output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s707986610
Accepted
p03624
Input is given from Standard Input in the following format: S
import sys class alphabet: # Trueなら大文字 def __init__(self, capitalize): self.num = dict() # アルファベットを数字に変換 self.abc = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] if capitalize: for i in range(26): self.abc[i] = self.abc[i].upper() for i, a in enumerate(self.abc): self.num[a] = True def solve(): S = input() AB = alphabet(False) for i in range(len(S)): AB.num[S[i]] = False for a in AB.abc: if AB.num[a]: print(a) break else: print("None") return 0 if __name__ == "__main__": solve()
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s934195431
Wrong Answer
p03624
Input is given from Standard Input in the following format: S
import math from collections import deque from collections import defaultdict import bisect # 自作関数群 def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() def factorization(n): res = [] if n % 2 == 0: res.append(2) for i in range(3, math.floor(n // 2) + 1, 2): if n % i == 0: c = 0 for j in res: if i % j == 0: c = 1 if c == 0: res.append(i) return res def fact2(n): p = factorization(n) res = [] for i in p: c = 0 z = n while 1: if z % i == 0: c += 1 z /= i else: break res.append([i, c]) return res def fact(n): # 階乗 ans = 1 m = n for _i in range(n - 1): ans *= m m -= 1 return ans def comb(n, r): # コンビネーション if n < r: return 0 l = min(r, n - r) m = n u = 1 for _i in range(l): u *= m m -= 1 return u // fact(l) def combmod(n, r, mod): return (fact(n) / fact(n - r) * pow(fact(r), mod - 2, mod)) % mod def printQueue(q): r = copyQueue(q) ans = [0] * r.qsize() for i in range(r.qsize() - 1, -1, -1): ans[i] = r.get() print(ans) class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): # root if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -1 * self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): # much time root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} # 1~n def bitArr(n): # ビット全探索 x = 1 zero = "0" * n ans = [] ans.append([0] * n) for i in range(2**n - 1): ans.append(list(map(lambda x: int(x), list((zero + bin(x)[2:])[-1 * n :])))) x += 1 return ans def arrsSum(a1, a2): for i in range(len(a1)): a1[i] += a2[i] return a1 def maxValue(a, b, v): v2 = v for i in range(v2, -1, -1): for j in range(v2 // a + 1): # j:aの個数 k = i - a * j if k % b == 0: return i return -1 def copyQueue(q): nq = queue.Queue() n = q.qsize() for i in range(n): x = q.get() q.put(x) nq.put(x) return nq def get_sieve_of_eratosthenes(n): # data = [2] data = [0, 0, 0] for i in range(3, n + 1, 2): data.append(i) data.append(0) for i in range(len(data)): interval = data[i] if interval != 0: for j in range(i + interval, n - 1, interval): data[j] = 0 # ans = [x for x in data if x!=0] ans = data[:] return ans def isInt(n): if isinstance(n, int): return True else: return n.is_integer() s = readChar() ex = set() for i in s: ex.add(i) al = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] for i in range(len(ex)): al.remove(ex.pop()) if len(al) == 0: print(-1) else: print(al[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s789444374
Accepted
p03624
Input is given from Standard Input in the following format: S
# -*- coding: utf-8 -*- import sys from collections import defaultdict, deque # def input(): return sys.stdin.readline()[:-1] # warning not \n # def input(): return sys.stdin.buffer.readline()[:-1] def solve(): s = set([x for x in input()]) for i in range(26): e = chr(ord("a") + i) if e not in s: print(e) return print("None") t = 1 # t = int(input()) for case in range(1, t + 1): ans = solve() """ 1 4 7 RRRR 1 1 0 1 ---- 4 1 4 47 RCRR 1 1 0 1 ---- -1 2 2 10 RR RR 1 7 4 1 ---- 4 2 2 10 RR RR 7 4 7 4 ---- -1 3 3 8 RCR RRC RRR 1 1 1 1 1 1 1 3 1 3 3 1 RCR RRC RRR 1 1 1 1 1 1 1 3 1 """
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s464156332
Runtime Error
p03624
Input is given from Standard Input in the following format: S
s=input() print(chr(i)) for i in range(ord("a"),ord("z")+1) if chr(i) not in s
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s922750109
Runtime Error
p03624
Input is given from Standard Input in the following format: S
S = list(input()) lst = [chr(i) for i in range(97, 97+26)] res = sorted(list(set(lst) - set(S))) if res = []: print("None") else: print(res[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s827409495
Runtime Error
p03624
Input is given from Standard Input in the following format: S
s_list = list(input()) small = None for s_uni in range(ord('a'), ord('z') + 1): if not chr(s_uni) in s_list: small = chr(s_uni) break if small: print(smal) else print('None')
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s718478939
Runtime Error
p03624
Input is given from Standard Input in the following format: S
S=input() x="None" num=[False for i in range(26)] for i in range(len(S)): num[ord(S[i])-ord("a")]=True for j in range(26): if !num[j]: x=chr(j+ord("a")) break print(x)
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s065727419
Accepted
p03624
Input is given from Standard Input in the following format: S
xs = set(range(ord("a"), ord("z") + 1)) - set(map(ord, input())) print(chr(min(xs)) if len(xs) else "None")
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s017417016
Accepted
p03624
Input is given from Standard Input in the following format: S
d = {chr(i) for i in range(ord("a"), ord("z") + 1)} - {c for c in input()} print("None" if len(d) == 0 else sorted(list(d))[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s616312994
Accepted
p03624
Input is given from Standard Input in the following format: S
print(min(set(map(chr, range(97, 123))) - set(input()) or ["None"]))
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s148396858
Accepted
p03624
Input is given from Standard Input in the following format: S
print(min(set(chr(97 + i) for i in range(26)) - set(input()) or ["None"]))
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s880728040
Wrong Answer
p03624
Input is given from Standard Input in the following format: S
print(min(set(map(chr, range(ord("a"), ord("z")))) - set(input()) or ["None"]))
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s755244808
Accepted
p03624
Input is given from Standard Input in the following format: S
hoge = input() flag = 0 if flag == 0 and hoge.count("a") == 0: print("a") flag = 1 if flag == 0 and hoge.count("b") == 0: print("b") flag = 1 if flag == 0 and hoge.count("c") == 0: print("c") flag = 1 if flag == 0 and hoge.count("d") == 0: print("d") flag = 1 if flag == 0 and hoge.count("e") == 0: print("e") flag = 1 if flag == 0 and hoge.count("f") == 0: print("f") flag = 1 if flag == 0 and hoge.count("g") == 0: print("g") flag = 1 if flag == 0 and hoge.count("h") == 0: print("h") flag = 1 if flag == 0 and hoge.count("i") == 0: print("i") flag = 1 if flag == 0 and hoge.count("j") == 0: print("j") flag = 1 if flag == 0 and hoge.count("k") == 0: print("k") flag = 1 if flag == 0 and hoge.count("l") == 0: print("l") flag = 1 if flag == 0 and hoge.count("m") == 0: print("m") flag = 1 if flag == 0 and hoge.count("n") == 0: print("n") flag = 1 if flag == 0 and hoge.count("o") == 0: print("o") flag = 1 if flag == 0 and hoge.count("p") == 0: print("p") flag = 1 if flag == 0 and hoge.count("q") == 0: print("q") flag = 1 if flag == 0 and hoge.count("r") == 0: print("r") flag = 1 if flag == 0 and hoge.count("s") == 0: print("s") flag = 1 if flag == 0 and hoge.count("t") == 0: print("t") flag = 1 if flag == 0 and hoge.count("u") == 0: print("u") flag = 1 if flag == 0 and hoge.count("v") == 0: print("v") flag = 1 if flag == 0 and hoge.count("w") == 0: print("w") flag = 1 if flag == 0 and hoge.count("x") == 0: print("x") flag = 1 if flag == 0 and hoge.count("y") == 0: print("y") flag = 1 if flag == 0 and hoge.count("z") == 0: print("z") flag = 1 if flag == 0: print("None")
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s174066031
Accepted
p03624
Input is given from Standard Input in the following format: S
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, "b") # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, "o") # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, "x") # rev => int(res, 16) MOD = 10**9 + 7 def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (MAX_NUM + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, MAX_NUM + 1, i): is_prime[j] = False return [i for i in range(MAX_NUM + 1) if is_prime[i]] ## libs ## from itertools import accumulate as acc from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): s = set(IS()) t = "abcdefghijklmnopqrstuvwxyz" for ti in t: if not ti in s: print(ti) return None print("None") if __name__ == "__main__": main()
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s831133838
Runtime Error
p03624
Input is given from Standard Input in the following format: S
S = set(list(input())) alpha = set([chr(ord("a") + i) for i in range(26)]) answer = alpha - S L = list(answer) L.sort() print(L[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s042628245
Runtime Error
p03624
Input is given from Standard Input in the following format: S
print(sorted(set([chr(i) for i in range(97, 97 + 26)]) - set(list(input())))[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s606721538
Accepted
p03624
Input is given from Standard Input in the following format: S
s = {i for i in input()} ss = [i for i in "abcdefghijklmnopqrstuvwxyz" if not i in s] ss.sort() print(None if not ss else ss[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s578500818
Accepted
p03624
Input is given from Standard Input in the following format: S
from __future__ import print_function import sys import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction from fractions import gcd # fractions.gcd() を用いること # math.log2()はatcoderでは対応していない.留意せよ. import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input = sys.stdin.readline def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) return def lcm(n, m): return int(n * m / gcd(n, m)) def coprimize(p, q): common = fractions.gcd(p, q) return (p // common, q // common) def combinations_count(n, r): r = min(r, n - r) numer = reduce(mul, range(n, n - r, -1), 1) denom = reduce(mul, range(1, r + 1), 1) return numer // denom def find_gcd(list_l): x = reduce(gcd, list_l) return x def main(): S = set(list("abcdefghijklmnopqrstuvwxyz")) - set(list(input().strip())) if len(list(S)) != 0: print(sorted(list(S))[0]) else: print("None") if __name__ == "__main__": main()
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s514174209
Accepted
p03624
Input is given from Standard Input in the following format: S
def counting_sort(array, max): bucket = [0] * (max + 1) for i in range(len(array)): if array[i] == "a": bucket[0] += 1 elif array[i] == "b": bucket[1] += 1 elif array[i] == "c": bucket[2] += 1 elif array[i] == "d": bucket[3] += 1 elif array[i] == "e": bucket[4] += 1 elif array[i] == "f": bucket[5] += 1 elif array[i] == "g": bucket[6] += 1 elif array[i] == "h": bucket[7] += 1 elif array[i] == "i": bucket[8] += 1 elif array[i] == "j": bucket[9] += 1 elif array[i] == "k": bucket[10] += 1 elif array[i] == "l": bucket[11] += 1 elif array[i] == "m": bucket[12] += 1 elif array[i] == "n": bucket[13] += 1 elif array[i] == "o": bucket[14] += 1 elif array[i] == "p": bucket[15] += 1 elif array[i] == "q": bucket[16] += 1 elif array[i] == "r": bucket[17] += 1 elif array[i] == "s": bucket[18] += 1 elif array[i] == "t": bucket[19] += 1 elif array[i] == "u": bucket[20] += 1 elif array[i] == "v": bucket[21] += 1 elif array[i] == "w": bucket[22] += 1 elif array[i] == "x": bucket[23] += 1 elif array[i] == "y": bucket[24] += 1 elif array[i] == "z": bucket[25] += 1 return bucket def main(): S = input() bucket_list = counting_sort(S, 25) for i in range(26): if bucket_list[i] == 0: if i == 0: print("a") return if i == 1: print("b") return if i == 2: print("c") return if i == 3: print("d") return if i == 4: print("e") return if i == 5: print("f") return if i == 6: print("g") return if i == 7: print("h") return if i == 8: print("i") return if i == 9: print("j") return if i == 10: print("k") return if i == 11: print("l") return if i == 12: print("m") return if i == 13: print("n") return if i == 14: print("o") return if i == 15: print("p") return if i == 16: print("q") return if i == 17: print("r") return if i == 18: print("s") return if i == 19: print("t") return if i == 20: print("u") return if i == 21: print("v") return if i == 22: print("w") return if i == 23: print("x") return if i == 24: print("y") return if i == 25: print("z") return print("None") main()
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s862867235
Accepted
p03624
Input is given from Standard Input in the following format: S
alp = "abcdefghijklmnopqrstuvwxyz" for c in list(input()): alp = alp.replace(c, "") print(alp[0] if len(alp) else "None")
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s156352038
Accepted
p03624
Input is given from Standard Input in the following format: S
l = "abcdefghijklmnopqrstuvwxyz" a = sorted(set(input()) ^ set(l)) print("None" if len(a) == 0 else a[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s076541627
Accepted
p03624
Input is given from Standard Input in the following format: S
a = set(input()) b = set([chr((ord("a") + i)) for i in range(26)]) print(sorted(list(b - a))[0] if b - a else "None")
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s049620535
Accepted
p03624
Input is given from Standard Input in the following format: S
x = sorted(set(chr(97 + i) for i in range(26)) - set(input())) print("None" if not x else x[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s136623900
Runtime Error
p03624
Input is given from Standard Input in the following format: S
import string x=input() a=string.acsii_lowercase for i in a if a not in x: print(x) exit()
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s780589442
Runtime Error
p03624
Input is given from Standard Input in the following format: S
a = sorted(set(input()) ^ set(map(chr(range(97, 123))))) print(a and a[0] or None)
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s016735268
Runtime Error
p03624
Input is given from Standard Input in the following format: S
S=input() s="abcdefghijklmnopqrstucwxyz" for si in s: if si in S S.remove(si) if S == "": print("None") else: S.sort() print(S[0])
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s194350676
Runtime Error
p03624
Input is given from Standard Input in the following format: S
s = list(input()) s.sort() start = ord('a') for c in s: if ord(c) == start: continue elif ord(c) - start == 1: start+=1 continue else: print(chr(start+1)) exit() print("None"
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s239814214
Runtime Error
p03624
Input is given from Standard Input in the following format: S
S = str(input) alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] S.sort() n = 0 m = 0 for i in range(len(S)): if S[n] not in alpha: print(S[n]) break n += 1 if n = len(S) - 1: m = 1 if m == 1: print('None')
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s735174518
Runtime Error
p03624
Input is given from Standard Input in the following format: S
#include <bits/stdc++.h> using namespace std; #define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i) #define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i) #define per(i,N) for(int i=(N)-1;i>=0;--i) #define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i) #define all(arr) (arr).begin(), (arr).end() #define SP << " " << #define SPF << " " #define SPEEDUP cin.tie(0);ios::sync_with_stdio(false); #define MAX_I INT_MAX //1e9 #define MIN_I INT_MIN //-1e9 #define MAX_UI UINT_MAX //1e9 #define MAX_LL LLONG_MAX //1e18 #define MIN_LL LLONG_MIN //-1e18 #define MAX_ULL ULLONG_MAX //1e19 typedef long long ll; typedef pair<int,int> PII; typedef pair<char,char> PCC; typedef pair<ll,ll> PLL; typedef pair<char,int> PCI; typedef pair<int,char> PIC; typedef pair<ll,int> PLI; typedef pair<int,ll> PIL; typedef pair<ll,char> PLC; typedef pair<char,ll> PCL; inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;} inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;} inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;} int main(void){ SPEEDUP cout << setprecision(15); string s;cin >> s; sort(all(s)); s.erase(unique(all(s)),s.end()); bool isNone = true; rep(i,26){ char out = 'a'+i; if(i==s.length()){ cout << out << endl; isNone = false; break; } if(s[i] != 'a'+i){ cout << out << endl; isNone = false; break; } } if(isNone) cout << "None" << endl; return 0; }
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the lexicographically smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead. * * *
s448424752
Wrong Answer
p03624
Input is given from Standard Input in the following format: S
word = input() print(word)
Statement You are given a string S consisting of lowercase English letters. Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S. If every lowercase English letter occurs in S, print `None` instead.
[{"input": "atcoderregularcontest", "output": "b\n \n\nThe string `atcoderregularcontest` contains `a`, but does not contain `b`.\n\n* * *"}, {"input": "abcdefghijklmnopqrstuvwxyz", "output": "None\n \n\nThis string contains every lowercase English letter.\n\n* * *"}, {"input": "fajsonlslfepbjtsaayxbymeskptcumtwrmkkinjxnnucagfrg", "output": "d"}]
Print the minimum time required to light K candles. * * *
s469975013
Wrong Answer
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
class Solver(object): def __init__(self): self.n, self.k = list(map(int, input().split(" "))) self.x_s = sorted(list(map(int, input().split(" ")))) def solve(self): # candles = self.filter() candles = self.x_s candidates = [] for i in range(len(candles) - self.k + 1): candidates.append((i, i + self.k)) # print(self.x_s[i:i+self.k]) best_candidate = candidates[0] best_distance = self.distance(best_candidate) for c in candidates[1:]: d = self.distance(c) if d < best_distance: best_candidate = c best_distance = d # print(best_candidate) print(best_distance) def distance(self, candidate): left = self.x_s[candidate[0]] right = self.x_s[candidate[1] - 1] # X X X 0 if right <= 0: return left # 0 X X X elif left >= 0: return right # X 0 X X elif abs(left) < abs(right): return abs(left) + abs(left) + abs(right) # X X 0 X else: return abs(right) + abs(right) + abs(left) def filter(self): # Only want -k .. k elements right = None counter = 0 for i, v in enumerate(self.x_s): if v >= 0: counter += 1 if counter == self.k: right = i + 1 break if right is None: right = len(self.x_s) left = None counter = 0 for i, v in reversed(list(enumerate(self.x_s))): if v <= 0: counter += 1 if counter == self.k: left = i break if left is None: left = 0 return self.x_s[left:right] if __name__ == "__main__": s = Solver() s.solve()
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s423299665
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
H, W = map(int, input().split()) a = [] for i in range(H): a.append(input()) row = [False] * H col = [False] * W for i in range(H): for j in range(W): if a[i][j] == "#": row[i] = True col[j] = True for i in range(H): if row[i]: for j in range(W): if col[j]: print(a[i][j], end="") print("", end="\n")
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s847759556
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
N, K = map(int,input().split()) x = list(map(int,input().split())) o = 0 if x[N-1] <= 0: print(x[N-K]) exit() if x[0] >= 0: print(x[K-1]) exit() MIN = float("inf") for i in range(N-K+1): l = i r = i + K cur1 = 2*abs(x[l]) + abs(x[r]-x[l]) cur2 = abs(x[l]) + 2*abs(x[r]-x[l]) # print([l,r,cur1,cur2]) if cur1 < MIN: MIN = cur1 if cur2 < MIN: MIN = cur2 print(MIN)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s992458401
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
# -*- coding: utf-8 -*- import numpy as np def solve(): N, K = map(int, input().split()) C = np.array(list(map(int,input().split()))) D = list() for i in range(N-K+1): c = C[i:i+K] l, r = max(c), min(c) d = -2*r + l if l > r else -r + 2*l D.append(d) return str(min(D) if __name__ == '__main__': print(solve())
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s476763609
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
def main(): N, K = map(int, input().split()) X = list(map(int, input().split())) D = [0]*(N - 1) for i in range(1, N): D[i-1] = X[i] - X[i - 1] ans = 0 t = 0 T = [0]*(N - K + 1) for i in range(1, N): t += D[i-1] if i < K: if i == K - 1: T[0] = t continue t -= D[i - K] T[i - K + 1] = t # print(D, T) ans = K * 10**8 for i in range(N - K + 1): a = T[i] + min(abs(X[i]), abs[X[i + K - 1])] ans = min(a, ans) print(ans) if __name__ == '__main__': main()
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s634571288
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
import itertools import collections n,k=map(int,input().split()) candle=list(map(int,input().split())) com=list(itertools.product([1,0], repeat=n)) ans=200000000 for i in range(2**n): count=collections.Counter(com[i]) if count[1]==k: begin=0 end=0 cnt=0 temp=0 print( for j in range(n): if com[i][j]==1: cnt+=1 if cnt==1: start=candle[j] elif cnt==k: end=candle[j] break; if start>=0: temp=abs(end) if temp<ans: ans=temp if end<=0: temp=abs(start) if temp<ans: ans=temp else: temp=min(abs(start), end)*2+max(abs(start), end) if temp<ans: ans=temp print(ans)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s507625162
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
n, k = map(int, input().split()) X = list(map(int, input().split())) count_0 = X.count(0) if k <= count_0: print(0) exit() k -= count_0 neg = [x for x in X if x < 0] pos = [x for x in X if x > 0] neg_count = len(neg) pos_count = len(pos) if not neg: print(pos[k-1]) exit() if not pos: print(neg[-k]) exit() res = [] for left in range(1, min(neg_count, k)): time1 = neg[-left] right = k - left - 1 if right >= pos_count: continue elif right < 0: res.append(abs(time1)) else: time2 = pos[right] res.append(time2-time1*2) for right in range(min(pos_count, k)): time1 = pos[right] left = k - right - 1 if left >= neg_count: continue elif left <= 0: res.append(abs(time1)) else: time2 = neg[-left] res.append(time1*2-time2) print(min(res))
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s589181280
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
W, H = map(int, input().split()) input_list = [] del_list1 = [] del_list2 = [] for i in range(0, H): input_list.append(list(input())) for i in range(len(input_list)): if input_list[i][0] == input_list[i][1]: count = 0 for j in range(len(input_list[0])): if input_list[i][0] == input_list[i][j]: count += 1 if count == len(input_list[i]): del_list1.append(i) for i in range(len(input_list[0])): if input_list[0][i] == input_list[1][i]: count = 0 for j in range(len(input_list)): if input_list[0][i] == input_list[j][i]: count += 1 if count == len(input_list): del_list2.append(i) for i in del_list1: input_list.pop(i) for i in reversed(del_list2): for tmp in input_list: tmp.pop(i) for i in input_list: for j in i: print(j, end="") print()
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s324802372
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
from bisect import * n, k = map(int, input().split()) candles = list(map(int, input().split())) i0 = bisect_right(candles, 0) MIN = float("inf") if i0 - k >= 0: MIN = -candles[i0 - k] i_start = max(0, i0 - k + 1) if 0 in candles: i0 -= 1 if i0 + k - 1 <= n - 1: MIN = min(MIN, candles[i0 + k - 1]) i_end = min(i0, n - k + 1) for i in range(i_start, i_end): L = -candles[i] R = candles[i + k - 1] temp = L + R + min(L, R) if temp < MIN: MIN = temp print(MIN)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s565702793
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
def main(): N, K = list(map(int, input().split(" "))) X = list(map(int, input().split(" "))) output = solve(N, K, X) print(output) return # ________________________________________ # Solve # ________________________________________ def solve(N, K, X): """ 解答のコード """ oab_min = X[-1] - X[0] a_list = [i for i in range(len(X)) if X[i] >= 0] # O(N) b_list = [i for i in range(len(X)) if X[i] < 0] # O(N) if not a_list: # if a_list is empty ob = -X[b_list[K - 1]] oab_min = min(ob, oab_min) if not b_list: oa = X[a_list[K - 1]] oab_min = min(ob, oab_min) left = max(0, K - len(b_list)) right = min(len(a_list), K) for i in range(left, right): # if a_list is empty, skip this process if (i == 0) and (a_list[0] != 0): ob = -X[b_list[K - 1]] oab_min = min(ob, oab_min) oa = X[a_list[i]] ob = abs(X[a_list[i] - K + 1]) oab = min(oa, ob) + oa + ob oab_min = min(oab, oab_min) return oab_min # ________________________________________ if __name__ == "__main__": main()
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s809392480
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
N, K = (int(T) for T in input().split()) X = [int(T) for T in input().split()] Cost = [0] * (N - K + 1) for T in range(0, N - K + 1): Left = X[T] Right = X[T + K - 1] Cost[T] = min(abs(Left) + abs(Left - Right), abs(Right) + abs(Right - Left)) print(min(Cost))
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s376431730
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
N, K = map(int, input().strip().split(" ")) x = list(map(int, input().strip().split(" "))) min_cost = float("inf") if N > 2 * K: for i, d in enumerate(x): if d >= 0: break x = x[i - K : i + K] for i in range(len(x) - K + 1): n_cost = -min(x[i], 0) p_cost = max(0, x[i + K - 1]) cost = n_cost + p_cost + min(n_cost, p_cost) if min_cost > cost: min_cost = cost print(min_cost)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s239593443
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
# 2019/05/10 # AtCoder Beginner Contest 107 - C # Input n, k = map(int, input().split()) x = list(map(int, input().split())) # Init acdist = list() # acdist.append(0) # Distance from x[0] for i in range(n): wx = x[i] - min(x[0], 0) acdist.append(wx) mindist = 10**10 eflg = False if x[0] >= 0: mindist = x[k - 1] eflg = True elif x[n - 1] <= 0: mindist = abs(x[n - k]) eflg = True for i in range(n - k + 1): if eflg == True: break sidx = i eidx = i + k - 1 if (x[eidx] < 0 and eidx < n - 1) or (x[sidx] > 0 and sidx > 0): continue else: # 折り返してゴールまで dist = acdist[eidx] - acdist[sidx] # 0からSidxまでの距離とEidxまでの距離の小さい方を足す dist += min(0 - x[sidx], x[eidx] - 0) if dist < mindist: mindist = dist # Output print(mindist)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s599923165
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
N, K = list(map(int, input().split(" "))) l = list(map(int, input().split(" "))) minuss = [0] + [-i for i in l if i < 0][::-1] pluss = [0] + [i for i in l if i >= 0] # minuss から k本、plussからK-k本取る(短い方を折り返すので2倍) ans = 1e16 # ? if pluss == [0]: # 4 2 [-4, -3 , -2, -1] pluss = minuss minuss = [0] for k in range(K): if k >= len(minuss) or K - k >= len(pluss): continue ans = min(ans, min(minuss[k] * 2 + pluss[K - k], minuss[k] + pluss[K - k] * 2)) print(ans)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s400718847
Wrong Answer
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
n, k = list(map(int, input().split())) d = list(map(int, input().split())) d_m = [] d_p = [i for i in d if i >= 0 or d_m.append(i)] ret = -1 for i in range(k): if len(d_p) >= i and len(d_m) >= k - i: dp_t = d_p[i - 1] if i > 0 else 0 dm_t = -1 * d_m[-(k - i)] if i != 0 else 0 if dp_t == 0: ret_t = dm_t elif dm_t == 0: ret_t = dp_t else: ret_t = dp_t + dm_t + min(dp_t, dm_t) # print(i, k-i, dp_t, dm_t, ret_t) if ret > ret_t or ret < 0: ret = ret_t print(ret)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s983463633
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
N, K = map(int, input().split(" ")) Xs = [int(a) for a in input().split()] min = 3 * (10**8) p = 0 z = 0 m = 0 Y = [] for x in Xs: if x > 0: p += 1 Y.append(x) elif x < 0: m += 1 else: z += 1 K -= z Z = [] for i in range(m - 1, -1, -1): Z.append(-Xs[i]) if K == 0: min = 0 if K - 1 < p and K - 1 >= 0: if Y[K - 1] < min: min = Y[K - 1] if K - 1 < m and K - 1 >= 0: if Z[K - 1] < min: min = Z[K - 1] for i in range(p): if i < K - 1: if K - i - 2 < m: if Y[i] * 2 + Z[K - i - 2] < min: min = Y[i] * 2 + Z[K - i - 2] for i in range(m): if i < K - 1: if K - i - 2 < p: if Z[i] * 2 + Y[K - i - 2] < min: min = Z[i] * 2 + Y[K - i - 2] print(min)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s055485370
Wrong Answer
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
n, k = map(int, input().split()) l = [int(i) for i in input().split()] right = [i for i in l if i > 0] left = [i for i in l if i <= 0] if not left: sm = 0 sm += l[0] for i in range(1, k): sm += l[i] - l[i - 1] print(sm) exit() if not right: sm = 0 l = [abs(i) for i in l] sm = l[0] for i in range(1, k): sm += l[i] - l[i - 1] print(sm) exit() le = len(left) ri = len(right) rl = [0] * le rr = [0] * ri left = [abs(i) for i in left] left = left[::-1] rl[0] = left[0] for i in range(1, le): rl[i] = rl[i - 1] + (left[i] - left[i - 1]) rr[0] = right[0] mini = 10**20 for i in range(1, ri): rr[i] = rr[i - 1] + (right[i] - right[i - 1]) if len(left) >= k: mini = min(mini, rl[k - 1]) if len(right) >= k: mini = min(mini, rr[k - 1]) if k == n: print(sum(rl) + sum(rr)) exit() for a in range(1, len(left)): b = k - a if b > len(rr): continue mini = min(mini, 2 * rl[a - 1] + rr[b - 1], rl[a - 1] + 2 * rr[b - 1]) print(mini)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s670835083
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
N, K = map(int, input().split()) L = list(map(int, input().split())) L.append(0) L.=sorted(L) dis = [] for i in range(N-K+1): if 0 in L[i:i+K+1]: l = L[i:i+K+1] d = abs(l[0]) + abs(l[-1])*2 dis.append(d) d = abs(l[0])*2 + abs(l[-1]) dis.append(d) print(min(dis))
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s307365620
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
import sys import math # noqa import bisect # noqa import queue # noqa def input(): return sys.stdin.readline().rstrip() def solve(X, K): N = len(X) cumsum = [0 for _ in range(N)] for i in range(1, N): cumsum[i] = abs(X[i] - X[i - 1]) + cumsum[i - 1] idx_zero = bisect.bisect_left(X, 0) ret = 1000000005 for i in range(0, N): if X[i] >= 0: break res = -X[i] k = idx_zero - i if (k < K) and (idx_zero + K - k - 1 < N): res += cumsum[idx_zero + K - k - 1] - cumsum[i] ret = min(ret, res) return ret if __name__ == "__main__": N, K = map(int, input().split()) X = list(map(int, input().split())) res = 1000000005 if min(X) >= 0: print(X[K - 1]) elif max(X) <= 0: X = X[::-1] print(-X[K - 1]) else: res = min(res, solve(X, K)) X = [-x for x in X] res = min(res, solve(X[::-1], K)) print(res)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s432807976
Accepted
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
n, k, *a = map(int, open(0).read().split()) print(min(r - l + min(abs(r), abs(l)) for l, r in zip(a, a[k - 1 :])))
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s654878021
Runtime Error
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
num = input().split(" ") zahyou = input().split(" ") num[1] = int(num[1]) plus = [] minus = [] rousoku = [] for i in range(int(num[0])): if int(zahyou[i]) < 0: minus.append(int(zahyou[i])) else: plus.append(int(zahyou[i])) # プラス方向で終了する場合 if num[1] > len(plus): plus_tmp = minus[(len(plus) - num[1]) :] + plus minus_tmp = minus[: (len(minus) + len(plus_tmp) - num[1] - 1)] rousoku = plus_tmp[0 : num[1]] minus_tmp_2 = [] for i in minus_tmp: minus_tmp_2.append(i) while True: if rousoku[-1] - rousoku[-2] >= (min(min(rousoku), 0) - minus_tmp_2[-1]) * 2: rousoku.pop(-1) rousoku.insert(0, minus_tmp_2.pop(-1)) else: break rousoku_move_plus = [] for i in rousoku: rousoku_move_plus.append(i - min(rousoku) * 2) # マイナス方向で終了する場合 if num[1] > len(minus): minus_tmp = minus + plus[: (num[1] - len(minus))] plus_tmp = plus[(num[1] - len(minus)) :] rousoku = minus_tmp[(-(num[1] + 1)) :] plus_tmp_2 = [] for i in plus_tmp: plus_tmp_2.append(i) while True: if rousoku[1] - rousoku[0] >= (plus_tmp_2[0] - max(max(rousoku), 0)) * 2: rousoku.pop(0) rousoku.append(plus_tmp_2.pop(0)) else: break rousoku_move_minus = [] for i in rousoku: rousoku_move_minus.append(max(rousoku) * 2 - i) print(min(max(rousoku_move_plus), max(rousoku_move_minus)))
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s284467722
Wrong Answer
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
import math S = input().split(" ") N = int(S[0]) K = int(S[1]) arr = [int(s) for s in input().split(" ")] def calculate(n, k, arr): minsArr = [] plusArr = [] for ar in arr: if ar < 0: minsArr.append(ar) else: plusArr.append(ar) # find start index startIndex = -10000 if len(minsArr) > k: startIndex = len(minsArr) - k else: startIndex = 0 minValues = [] while startIndex <= len(minsArr): tmpArr = arr[startIndex : startIndex + k] if len(tmpArr) < k: break minValue = 0 if tmpArr[0] * tmpArr[-1] < 0: minValue = math.fabs(tmpArr[-1] - tmpArr[0]) + min( math.fabs(tmpArr[-1]), math.fabs(tmpArr[0]) ) else: minValue = math.fabs(tmpArr[-1]) minValues.append(minValue) startIndex = startIndex + 1 return int(min(minValues)) result = calculate(N, K, arr) print(result)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s437551990
Wrong Answer
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
N, K = map(int, input().split()) x = list(map(int, input().split())) cnt = 0 seek = 0 # 左から原点をまたぐ場合 if x[0] <= 0 and 0 <= x[N - 1]: # 左に長い場合 if abs(x[0]) >= abs(x[N - 1]): for i in range(x[N - 1] + 1): if i in x: cnt += 1 if cnt == K: print(i) exit() seek = abs(i) seek = seek * 2 for i in range(0, x[0] - 1, -1): seek += 1 if i in x: cnt += 1 if cnt == K: print(seek) exit() # 右に長い場合 else: for i in range(0, x[0] - 1, -1): print(i) if i in x: cnt += 1 print(cnt) if cnt == K: print(i) exit() seek = abs(i) seek = seek * 2 for i in range(x[N - 1] + 1): seek += 1 if i in x: cnt += 1 if cnt == K: print(seek) exit() # 原点よりすべて正 elif x[0] >= 0 and 0 < x[N - 1]: for i in range(x[N - 1]): if i in x: cnt += 1 if cnt == K: print(i) exit() # 原点よりすべて負 elif x[0] < 0 and 0 >= x[N - 1]: for i in range(x[0]): if i in x: cnt += 1 if cnt == K: print(i) exit()
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Print the minimum time required to light K candles. * * *
s560894493
Wrong Answer
p03274
Input is given from Standard Input in the following format: N K x_1 x_2 ... x_N
def update(): cost = list(map(abs, candles)) min_cost_index = cost.index(min(cost)) print(min_cost_index) start_index = max(0, min_cost_index - K) end_index = min(N, min_cost_index + K) new_candles = candles[start_index:end_index] return new_candles def compute_cost(point_candles): if point_candles[0] * point_candles[-1] >= 0: return max(abs(point_candles[0]), abs(point_candles[-1])) else: return ( point_candles[-1] - point_candles[0] + min(abs(point_candles[0]), abs(point_candles[-1])) ) N, K = list(map(int, input().strip().split(" "))) candles = list(map(int, input().strip().split(" "))) candles = update() N = len(candles) min_cost = None patterns = N - K + 1 for start_index in range(patterns): cost = compute_cost(candles[start_index : start_index + K]) if min_cost == None or min_cost > cost: min_cost = cost print(min_cost)
Statement There are N candles placed on a number line. The i-th candle from the left is placed on coordinate x_i. Here, x_1 < x_2 < ... < x_N holds. Initially, no candles are burning. Snuke decides to light K of the N candles. Now, he is at coordinate 0. He can move left and right along the line with speed 1. He can also light a candle when he is at the same position as the candle, in negligible time. Find the minimum time required to light K candles.
[{"input": "5 3\n -30 -10 10 20 50", "output": "40\n \n\nHe should move and light candles as follows:\n\n * Move from coordinate 0 to -10.\n * Light the second candle from the left.\n * Move from coordinate -10 to 10.\n * Light the third candle from the left.\n * Move from coordinate 10 to 20.\n * Light the fourth candle from the left.\n\n* * *"}, {"input": "3 2\n 10 20 30", "output": "20\n \n\n* * *"}, {"input": "1 1\n 0", "output": "0\n \n\n * There may be a candle placed at coordinate 0.\n\n* * *"}, {"input": "8 5\n -9 -7 -4 -3 1 2 3 4", "output": "10"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s262684975
Wrong Answer
p02873
Input is given from Standard Input in the following format: S
##https://atcoder.jp/contests/agc040/tasks/agc040_a def find_next_lt_pos(start, s, n): for i in range(start, n): if s[i] == "<": return i return -1 def find_next_gt_pos(start, s, n): for i in range(start, n): if s[i] == ">": return i return -1 def sum_to_n(n): return n * (n + 1) // 2 def same_symbol_len(symb, st_pos, s): sp = st_pos while s[sp] == symb: sp += 1 return sp def find_sum(s): n = len(s) a = [0] * (n + 1) cur_pos = 0 change_pos = find_next_lt_pos(0, s, n) if change_pos == -1: for i in range(n + 1): a[i] = n - i else: for i in range(cur_pos, change_pos + 1): a[i] = change_pos - i cur_pos = change_pos + 1 while cur_pos <= n: change_pos = find_next_gt_pos(cur_pos, s, n) if change_pos == -1: for i in range(cur_pos, n + 1): a[i] = i - cur_pos + 1 cur_pos = n + 1 else: change_pos_2 = find_next_lt_pos(change_pos, s, n) if change_pos_2 == -1: change_pos_2 = n for i in range(cur_pos, change_pos + 1): a[i] = 1 + i - cur_pos cur_pos = change_pos for i in range(cur_pos, change_pos_2 + 1): if change_pos_2 - i > a[i]: a[i] = change_pos_2 - i cur_pos = change_pos_2 + 1 return sum(a) def solve(): print(find_sum(input())) if __name__ == "__main__": solve()
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s613891240
Accepted
p02873
Input is given from Standard Input in the following format: S
Slist = input() Slist = Slist.replace("><", ">,<").split(",") ans = 0 for S in Slist: a = S.count("<") b = S.count(">") n = max(a, b) m = len(S) - n ans = ans + n * (n + 1) // 2 + (m - 1) * m // 2 print(ans)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s478916519
Accepted
p02873
Input is given from Standard Input in the following format: S
S = input() count_more = 0 count_less = 0 ans = 0 pre_si = ">" for i, si in enumerate(S): if pre_si == ">" and si == "<": max_n = max(count_more, count_less) min_n = min(count_more, count_less) ans += (max_n + 1) * (max_n) // 2 # print(i, ans) ans += (min_n) * (min_n - 1) // 2 count_more = 0 count_less = 0 # print(i, ans) if si == "<": count_more += 1 elif si == ">": count_less += 1 pre_si = si max_n = max(count_more, count_less) min_n = min(count_more, count_less) ans += (max_n + 1) * (max_n) // 2 ans += (min_n) * (min_n - 1) // 2 print(ans)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s439072215
Wrong Answer
p02873
Input is given from Standard Input in the following format: S
S = input() if S[0] == "<": a = S.count(">") else: a = S.count("<") print(a * (a + 1) // 2)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s846701742
Wrong Answer
p02873
Input is given from Standard Input in the following format: S
print(8)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s417939696
Wrong Answer
p02873
Input is given from Standard Input in the following format: S
str = input() char_list = [] ans_list = [] ans_list.insert(0, 0) print(ans_list) char_list = list(str) n = len(char_list)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s454450836
Wrong Answer
p02873
Input is given from Standard Input in the following format: S
print(sum(range(input().count(">") + 1)))
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s907626913
Runtime Error
p02873
Input is given from Standard Input in the following format: S
S = input() result = 0 for sp in S.split("><"): num_l = sp.count("<") num_g = sp.count(">") M = max(num_l, num_g) m = min(num_l, num_g) if sp[0] == ">": if M > 0: d = (M + 2) * (M + 1) / 2 result += d if m > 0: d = m * (m + 1) / 2 result += d else: d = (M + 0) * (M + 1) / 2 result += d print(int(result))
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s122053490
Accepted
p02873
Input is given from Standard Input in the following format: S
s = ">" + input() + "<" l = len(s) - 1 arr = [-1] * l for i in range(l): if s[i] == ">" and s[i + 1] == "<": arr[i] = 0 for i in range(1, l): if s[i] == "<" and arr[i - 1] != -1: arr[i] = arr[i - 1] + 1 for i in range(l - 1, 0, -1): if s[i] == ">" and arr[i] != -1: arr[i - 1] = max(arr[i - 1], arr[i] + 1) print(sum(arr))
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s172005563
Runtime Error
p02873
Input is given from Standard Input in the following format: S
S = input() d = [] lt = 0 gt = 0 for i in range(len(S)): if i == 0: continue if S[i - 1] == S[i] and S[i] == "<": lt += 1 if S[i - 1] == S[i] and S[i] == ">": gt += 1 if S[i - 1] != S[i] and S[i - 1] == "<": d.append("<" * (lt + 1)) lt = 0 if S[i - 1] != S[i] and S[i - 1] == ">": d.append(">" * (gt + 1)) gt = 0 if i == len(S) - 1 and S[i] == "<": d.append("<" * (lt + 1)) if i == len(S) - 1 and S[i] == ">": d.append(">" * (gt + 1)) print(d) ans = 0 if d[0][0] == "<": i = 0 while i < len(d) - 1: if i != len(d) - 1: if len(d[i]) >= len(d[i + 1]): for i in range(1, len(d[i]) + 1): ans += i for i in range(1, len(d)): ans += i i += 2 elif len(d[i]) < len(d[i + 1]): for i in range(1, len(d[i]) + 1): ans += i for i in range(1, len(d)): ans += i i += 2 elif i == len(d) - 1: for i in range(1, len(d[i]) + 1): ans += i i += 1 if d[0][0] == ">": ans += (len(d[i]) + 1) * len(d[i]) / 2 i = 1 while i < len(d) - 1: if i != len(d) - 1: if len(d[i]) >= len(d[i + 1]): ans += (len(d[i]) + 1) * len(d[i]) / 2 + (len(d[i + 1])) * len( d[i + 1] ) / 2 i += 2 elif len(d[i]) < len(d[i + 1]): ans += (len(d[i])) * len(d[i]) / 2 + (len(d[i + 1]) + 1) * len( d[i + 1] ) / 2 i += 2 elif i == len(d) - 1: ans += (len(d[i]) + 1) * len(d[i]) / 2 print(ans) # min_d = 0 # for i in d: # min_d = min(min_d, d[i]) # d = list(map(lambda x: x + abs(min_d), d)) # if S[0] == "<": # d[0] = 0 # ans = 0 # for i in range(len(S)): # ans += d[i] # print(d) # print(ans)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s338574792
Accepted
p02873
Input is given from Standard Input in the following format: S
#!/usr/bin/env python3 S = input() s_list = list(S) w_list = [0] min_n = 0 s_l = len(s_list) totsu_list = [False] if s_list[0] == "<": ou_list = [True] else: ou_list = [False] t_list = [] if ou_list[0]: t_list = ["ou"] else: t_list = ["totsu"] for i, char in enumerate(s_list): # 凹であるかどうか is_ou = False is_totsu = False if i == s_l - 1: if char == ">": is_ou = True else: if s_list[i] == "<" and s_list[i + 1] == ">": is_totsu = True elif s_list[i] == ">" and s_list[i + 1] == "<": is_ou = True ou_list.append(is_ou) totsu_list.append(is_totsu) if is_ou: t = "ou" elif is_totsu: t = "totsu" elif char == "<": t = "up" else: t = "down" t_list.append(t) if char == "<": w_list.append(w_list[i] + 1) else: w_list.append(w_list[i] - 1) min_n = min(w_list[i] - 1, min_n) x_list = [] d = abs(min_n) w_len = len(w_list) for i, w in enumerate(w_list): t = t_list[i] if t == "ou": x = 0 elif t == "up" or i == w_len - 1: x = x_list[i - 1] + 1 else: x = w_list[i] + d x_list.append(x) x_len = len(x_list) y_list = x_list[:] total = 0 for i in range(x_len): idx = x_len - (i + 1) t = t_list[idx] if t == "down": y_list[idx] = y_list[idx + 1] + 1 elif t == "ou" or t == "down": pass elif t == "totsu": if idx == 0 or idx == x_len: pass else: a = y_list[idx - 1] b = y_list[idx + 1] y_list[idx] = max(a, b) + 1 total += y_list[idx] if len(y_list) >= 3: if t_list[0] == "totsu": total -= y_list[0] total += y_list[1] + 1 if t_list[-1] == "totsu": total -= y_list[-1] total += y_list[-2] + 1 # ans = sum(z_list) ans = total print(ans)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Find the minimum possible sum of the elements of a good sequence of N non- negative integers. * * *
s924375239
Runtime Error
p02873
Input is given from Standard Input in the following format: S
#!/usr/bin/env python3 # Atcoder necoak answer # https://atcoder.jp/contests/agc040/tasks/agc040_a MAX_INT = 100000 s_txt = input() MIN_V = 1000000 def func(my_suretu, my_s_txt, min_v): # print('func(', my_suretu, my_s_txt, min_v, ')') now_sum = sum(my_suretu) # print(now_sum) if now_sum >= min_v: return min_v if len(my_s_txt) == 0: if now_sum < min_v: min_v = now_sum return min_v else: next_my_s_txt = my_s_txt[1:] for v in range(0, MAX_INT): new_min_v = min_v if len(my_suretu) == 0: new_min_v = func(my_suretu + [v], next_my_s_txt, min_v) elif ((my_s_txt[0] == ">") and (my_suretu[-1] > v)) or ( (my_s_txt[0] == "<") and (my_suretu[-1] < v) ): # print(my_suretu[-1], my_s_txt[0], v) new_min_v = func(my_suretu + [v], next_my_s_txt, min_v) if new_min_v < min_v: min_v = new_min_v elif (new_min_v == min_v) and (new_min_v != MIN_V): break return min_v min_v = MIN_V for v in range(0, MAX_INT): new_min_v = func([v], s_txt, min_v) if new_min_v < min_v: min_v = new_min_v elif (new_min_v == min_v) and (new_min_v != MIN_V): break print(min_v)
Statement Given is a string S of length N-1. Each character in S is `<` or `>`. A sequence of N non-negative integers, a_1,a_2,\cdots,a_N, is said to be _good_ when the following condition is satisfied for all i (1 \leq i \leq N-1): * If S_i= `<`: a_i<a_{i+1} * If S_i= `>`: a_i>a_{i+1} Find the minimum possible sum of the elements of a good sequence of N non- negative integers.
[{"input": "<>>", "output": "3\n \n\na=(0,2,1,0) is a good sequence whose sum is 3. There is no good sequence whose\nsum is less than 3.\n\n* * *"}, {"input": "<>>><<><<<<<>>><", "output": "28"}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s725530489
Wrong Answer
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
print()
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s996927970
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools from collections import deque sys.setrecursionlimit(10**7) inf = 10**20 mod = 10**9 + 7 DR = [1, -1, 0, 0] DC = [0, 0, 1, -1] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): N = I() strings = [] prevdic = None for _ in range(N): ch = S() curdic = collections.Counter() for c in ch: curdic[c] += 1 if prevdic: for k, v in prevdic.items(): prevdic[k] = min(v, curdic[k]) else: prevdic = curdic diclist = [] for k, v in prevdic.items(): diclist.append((k, v)) diclist = sorted(diclist, key=lambda x: x[0]) ans = "" for item in diclist: k, v = item[0], item[1] ans += k * v print(ans) main()
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s687900033
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
import sys from io import StringIO import unittest def resolve(): n = int(input()) ss = [input() for _ in range(n)] alphabets = [chr(ord("a") + x) for x in range(26)] ans = [0 for _ in range(26)] for i, a in enumerate(alphabets): ans[i] = min([s.count(a) for s in ss]) ans_str = "" for a, cnt in zip(alphabets, ans): ans_str += a * cnt print(ans_str) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """3 cbaa daacc acacac""" output = """aac""" self.assertIO(input, output) def test_入力例_2(self): input = """3 a aa b""" output = """""" self.assertIO(input, output) if __name__ == "__main__": # unittest.main( resolve()
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s286656902
Runtime Error
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
n = int(input()) word = [sorted(input()) for _ in range(n)] result = [] word_result = [] for i in range(len(word) - 1): result.append(set(word[i]) & set(word[i + 1])) if min(result): for i in min(result): word_result.append(i * word[0].count(i)) print("".join(sorted(word_result)))
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s606625548
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
N = int(input()) s = list(input()) t = [list(input()) for i in range(N - 1)] u = [] for i in s: for k in range(N - 1): if i not in t[k]: break else: for j in range(N - 1): t[j].remove(i) u.append(i) print("".join(sorted(u)))
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s059548767
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
# 58c import collections n = int(input()) # 初回分だけ別処理 s = str(input()) s_counted = collections.Counter(s) alphabet_times_dict = dict(s_counted) # 初回分以降を読み込んで、重なっている文字と回数を絞っていく for i in range(n - 1): s = str(input()) s_counted = collections.Counter(s) for alphabet_times in alphabet_times_dict.items(): alphabet = alphabet_times[0] times = alphabet_times[1] if alphabet in s_counted: alphabet_times_dict[alphabet] = min( alphabet_times_dict[alphabet], s_counted[alphabet] ) else: alphabet_times_dict[alphabet] = 0 # 重なっていた文字*回数のリスト作成 string_list = [] for alphabet_times in alphabet_times_dict.items(): alphabet = alphabet_times[0] times = alphabet_times[1] if times != 0: string_list += [alphabet for i in range(times)] # 辞書順に並び替えて表示 string_list.sort(reverse=False) print("".join(map(str, string_list)))
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s710292992
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
n = int(input()) s = [] for i in range(n): a = input() s.append(a) p = [] for i in range(n): l = [0 for i in range(26)] for j in s[i]: if j == "a": l[0] += 1 if j == "b": l[1] += 1 if j == "c": l[2] += 1 if j == "d": l[3] += 1 if j == "e": l[4] += 1 if j == "f": l[5] += 1 if j == "g": l[6] += 1 if j == "h": l[7] += 1 if j == "i": l[8] += 1 if j == "j": l[9] += 1 if j == "k": l[10] += 1 if j == "l": l[11] += 1 if j == "m": l[12] += 1 if j == "n": l[13] += 1 if j == "o": l[14] += 1 if j == "p": l[15] += 1 if j == "q": l[16] += 1 if j == "r": l[17] += 1 if j == "s": l[18] += 1 if j == "t": l[19] += 1 if j == "u": l[20] += 1 if j == "v": l[21] += 1 if j == "w": l[22] += 1 if j == "x": l[23] += 1 if j == "y": l[24] += 1 if j == "z": l[25] += 1 p.append(l) l = [] for i in range(26): m = 1000000000 for j in range(n): m = min(m, p[j][i]) l.append(m) ans = "" for i in range(26): if i == 0 and l[i] > 0: ans += "a" * l[i] if i == 1 and l[i] > 0: ans += "b" * l[i] if i == 2 and l[i] > 0: ans += "c" * l[i] if i == 3 and l[i] > 0: ans += "d" * l[i] if i == 4 and l[i] > 0: ans += "e" * l[i] if i == 5 and l[i] > 0: ans += "f" * l[i] if i == 6 and l[i] > 0: ans += "g" * l[i] if i == 7 and l[i] > 0: ans += "h" * l[i] if i == 8 and l[i] > 0: ans += "i" * l[i] if i == 9 and l[i] > 0: ans += "j" * l[i] if i == 10 and l[i] > 0: ans += "k" * l[i] if i == 11 and l[i] > 0: ans += "l" * l[i] if i == 12 and l[i] > 0: ans += "m" * l[i] if i == 13 and l[i] > 0: ans += "n" * l[i] if i == 14 and l[i] > 0: ans += "o" * l[i] if i == 15 and l[i] > 0: ans += "p" * l[i] if i == 16 and l[i] > 0: ans += "q" * l[i] if i == 17 and l[i] > 0: ans += "r" * l[i] if i == 18 and l[i] > 0: ans += "s" * l[i] if i == 19 and l[i] > 0: ans += "t" * l[i] if i == 20 and l[i] > 0: ans += "u" * l[i] if i == 21 and l[i] > 0: ans += "v" * l[i] if i == 22 and l[i] > 0: ans += "w" * l[i] if i == 23 and l[i] > 0: ans += "x" * l[i] if i == 24 and l[i] > 0: ans += "y" * l[i] if i == 25 and l[i] > 0: ans += "z" * l[i] print(ans)
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s162907307
Wrong Answer
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
n = int(input()) List = [] List2 = [] for i in range(n): List.append(input()) S1 = sorted(List[0]) for j in range(1, n): for k in range(len(S1)): if List[j].count(S1[k]) == 0: List2.append(S1[k]) List2 = List2 List2 = set(List2) List2 = list(List2) for k in range(len(List2)): S1.remove(List2[k]) Answer = "".join(map(str, S1)) print(Answer)
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s747311792
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
n = int(input()) sAry = [] alphabet = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ] for i in range(n): alphAry = [0] * 26 s = list(input()) for alph in s: if alph == "a": alphAry[0] += 1 elif alph == "b": alphAry[1] += 1 elif alph == "c": alphAry[2] += 1 elif alph == "d": alphAry[3] += 1 elif alph == "e": alphAry[4] += 1 elif alph == "f": alphAry[5] += 1 elif alph == "g": alphAry[6] += 1 elif alph == "h": alphAry[7] += 1 elif alph == "i": alphAry[8] += 1 elif alph == "j": alphAry[9] += 1 elif alph == "k": alphAry[10] += 1 elif alph == "l": alphAry[11] += 1 elif alph == "m": alphAry[12] += 1 elif alph == "n": alphAry[13] += 1 elif alph == "o": alphAry[14] += 1 elif alph == "p": alphAry[15] += 1 elif alph == "q": alphAry[16] += 1 elif alph == "r": alphAry[17] += 1 elif alph == "s": alphAry[18] += 1 elif alph == "t": alphAry[19] += 1 elif alph == "u": alphAry[20] += 1 elif alph == "v": alphAry[21] += 1 elif alph == "w": alphAry[22] += 1 elif alph == "x": alphAry[23] += 1 elif alph == "y": alphAry[24] += 1 elif alph == "z": alphAry[25] += 1 sAry.append(alphAry) # print(sAry) resultAry = [51] * 26 for s in sAry: for i in range(26): if s[i] < resultAry[i]: resultAry[i] = s[i] # print(resultAry) answer = "" for i in range(26): for j in range(resultAry[i]): answer += alphabet[i] print(answer)
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s119966450
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
n = int(input()) l0 = [0] * n l = [l0[:] for _ in range(26)] for i in range(n): a = input() for x in a: if x == "a": l[0][i] += 1 elif x == "b": l[1][i] += 1 elif x == "c": l[2][i] += 1 elif x == "d": l[3][i] += 1 elif x == "e": l[4][i] += 1 elif x == "f": l[5][i] += 1 elif x == "g": l[6][i] += 1 elif x == "h": l[7][i] += 1 elif x == "i": l[8][i] += 1 elif x == "j": l[9][i] += 1 elif x == "k": l[10][i] += 1 elif x == "l": l[11][i] += 1 elif x == "m": l[12][i] += 1 elif x == "n": l[13][i] += 1 elif x == "o": l[14][i] += 1 elif x == "p": l[15][i] += 1 elif x == "q": l[16][i] += 1 elif x == "r": l[17][i] += 1 elif x == "s": l[18][i] += 1 elif x == "t": l[19][i] += 1 elif x == "u": l[20][i] += 1 elif x == "v": l[21][i] += 1 elif x == "w": l[22][i] += 1 elif x == "x": l[23][i] += 1 elif x == "y": l[24][i] += 1 elif x == "z": l[25][i] += 1 b = 0 s = "" for x in l: c = min(x) if b == 0: s += "a" * c elif b == 1: s += "b" * c elif b == 2: s += "c" * c elif b == 3: s += "d" * c elif b == 4: s += "e" * c elif b == 5: s += "f" * c elif b == 6: s += "g" * c elif b == 7: s += "h" * c elif b == 8: s += "i" * c elif b == 9: s += "j" * c elif b == 10: s += "k" * c elif b == 11: s += "l" * c elif b == 12: s += "m" * c elif b == 13: s += "n" * c elif b == 14: s += "o" * c elif b == 15: s += "p" * c elif b == 16: s += "q" * c elif b == 17: s += "r" * c elif b == 18: s += "s" * c elif b == 19: s += "t" * c elif b == 20: s += "u" * c elif b == 21: s += "v" * c elif b == 22: s += "w" * c elif b == 23: s += "x" * c elif b == 24: s += "y" * c elif b == 25: s += "z" * c b += 1 print(s)
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s235565810
Runtime Error
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
n = int(input()) s = [sorted(list(input())) for i in range(n)] rem = s[0] for i in range(1,n): tmp = rem[:] for j in s[i]: try: tmp.remove(j) except: pass for k in tmp: try: rem.remove(k) except: pass print(''.join(rem))
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s720369761
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
N = int(input()) S = [sorted(list(input())) for _ in range(N)] l = S[0] len_s = len(S) for i in range(len_s): l = list(set(l) & set(S[i])) ans = "" len_l = len(l) for i in range(len_l): cnt = 50 for j in range(len_s): if cnt > S[j].count(l[i]): cnt = S[j].count(l[i]) ans += l[i] * cnt print("".join(sorted(ans)))
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s320853850
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
### ### atcorder test program ### import sys ### math class class math: ### pi pi = 3.14159265358979323846264338 ### GCD def gcd(self, a, b): if b == 0: return a return self.gcd(b, a % b) ### LCM def lcm(self, a, b): return (a * b) // self.gcd(a, b) ### Prime number search def Pnum(self, a): if a == 1: return False for i in range(2, int(a**0.5) + 1): if a % i == 0: return False return True ### Circle area def caria(self, r): return r * r * self.pi math = math() ### output class class output: ### list def list(self, l): l = list(l) print(" ", end="") for i, num in enumerate(l): print(num, end="") if i != len(l) - 1: print(" ", end="") print() output = output() ### input sample # i = input() # A, B, C = [x for x in input().split()] # inlist = [int(w) for w in input().split()] # R = float(input()) # A = [int(x) for x in input().split()] # for line in sys.stdin.readlines(): # x, y = [int(temp) for temp in line.split()] ### output sample # print("{0} {1} {2:.5f}".format(A//B, A%B, A/B)) # print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi)) # print(" {}".format(i), end="") # A, B, C = [int(x) for x in input().split()] N = int(input()) S = [] AB = [chr(i) for i in range(ord("a"), ord("z") + 1)] for i in range(N): S.append(input()) for i in AB: countmin = 114514 for j in S: if countmin > j.count(i): countmin = j.count(i) # print(i,countmin,j.count(i)) for j in range(countmin): print(i, end="") print("")
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s099526901
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
n = int(input()) sl = [] for i in range(n): sss = list(str(input())) onedict = {} for j in range(len(sss)): if sss[j] in onedict: onedict[sss[j]] = onedict[sss[j]] + 1 else: onedict.update({sss[j]: 1}) sl.append(onedict) ansdict = {} for alphabet in sl[0].keys(): flag = 0 mins = [] for j in sl: if alphabet in j: mins.append(j[alphabet]) else: flag = 1 if flag == 1: None else: minutes = min(mins) ansdict.update({alphabet: minutes}) goalkeys = list(sorted(ansdict.keys())) moji = "" for i in goalkeys: for j in range(ansdict[i]): moji = moji + i print(moji)
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s553750255
Wrong Answer
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
print("")
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s685887400
Runtime Error
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
A, B, C = map(int, input().split()) X = int(1e9) + 7 print((A % X) * (B % X) * (C % X))
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s011169761
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
# input n = int(input()) S = [input() for _ in range(n)] INF = float("inf") alphabets = [INF] * 26 for i in range(n): alphabets[0] = min(S[i].count("a"), alphabets[0]) alphabets[1] = min(S[i].count("b"), alphabets[1]) alphabets[2] = min(S[i].count("c"), alphabets[2]) alphabets[3] = min(S[i].count("d"), alphabets[3]) alphabets[4] = min(S[i].count("e"), alphabets[4]) alphabets[5] = min(S[i].count("f"), alphabets[5]) alphabets[6] = min(S[i].count("g"), alphabets[6]) alphabets[7] = min(S[i].count("h"), alphabets[7]) alphabets[8] = min(S[i].count("i"), alphabets[8]) alphabets[9] = min(S[i].count("j"), alphabets[9]) alphabets[10] = min(S[i].count("k"), alphabets[10]) alphabets[11] = min(S[i].count("l"), alphabets[11]) alphabets[12] = min(S[i].count("m"), alphabets[12]) alphabets[13] = min(S[i].count("n"), alphabets[13]) alphabets[14] = min(S[i].count("o"), alphabets[14]) alphabets[15] = min(S[i].count("p"), alphabets[15]) alphabets[16] = min(S[i].count("q"), alphabets[16]) alphabets[17] = min(S[i].count("r"), alphabets[17]) alphabets[18] = min(S[i].count("s"), alphabets[18]) alphabets[19] = min(S[i].count("t"), alphabets[19]) alphabets[20] = min(S[i].count("u"), alphabets[20]) alphabets[21] = min(S[i].count("v"), alphabets[21]) alphabets[22] = min(S[i].count("w"), alphabets[22]) alphabets[23] = min(S[i].count("x"), alphabets[23]) alphabets[24] = min(S[i].count("y"), alphabets[24]) alphabets[25] = min(S[i].count("z"), alphabets[25]) ans = "" ans += "a" * alphabets[0] ans += "b" * alphabets[1] ans += "c" * alphabets[2] ans += "d" * alphabets[3] ans += "e" * alphabets[4] ans += "f" * alphabets[5] ans += "g" * alphabets[6] ans += "h" * alphabets[7] ans += "i" * alphabets[8] ans += "j" * alphabets[9] ans += "k" * alphabets[10] ans += "l" * alphabets[11] ans += "m" * alphabets[12] ans += "n" * alphabets[13] ans += "o" * alphabets[14] ans += "p" * alphabets[15] ans += "q" * alphabets[16] ans += "r" * alphabets[17] ans += "s" * alphabets[18] ans += "t" * alphabets[19] ans += "u" * alphabets[20] ans += "v" * alphabets[21] ans += "w" * alphabets[22] ans += "x" * alphabets[23] ans += "y" * alphabets[24] ans += "z" * alphabets[25] print(ans)
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line. * * *
s505627458
Accepted
p03761
Input is given from Standard Input in the following format: n S_1 ... S_n
num = int(input()) string = [input() for _ in range(num)] a = 1000 b = 1000 c = 1000 d = 1000 e = 1000 f = 1000 g = 1000 h = 1000 i1 = 1000 j = 1000 k = 1000 l = 1000 m = 1000 n = 1000 o = 1000 p = 1000 q = 1000 r = 1000 s = 1000 t = 1000 u = 1000 v = 1000 w = 1000 x = 1000 y = 1000 z = 1000 for i in range(num): a = min(string[i].count("a"), a) b = min(string[i].count("b"), b) c = min(string[i].count("c"), c) d = min(string[i].count("d"), d) e = min(string[i].count("e"), e) f = min(string[i].count("f"), f) g = min(string[i].count("g"), g) h = min(string[i].count("h"), h) i1 = min(string[i].count("i"), i1) j = min(string[i].count("j"), j) k = min(string[i].count("k"), k) l = min(string[i].count("l"), l) m = min(string[i].count("m"), m) n = min(string[i].count("n"), n) o = min(string[i].count("o"), o) p = min(string[i].count("p"), p) q = min(string[i].count("q"), q) r = min(string[i].count("r"), r) s = min(string[i].count("s"), s) t = min(string[i].count("t"), t) u = min(string[i].count("u"), u) v = min(string[i].count("v"), v) w = min(string[i].count("w"), w) x = min(string[i].count("x"), x) y = min(string[i].count("y"), y) z = min(string[i].count("z"), z) for _ in range(a): print("a", end="") for _ in range(b): print("b", end="") for _ in range(c): print("c", end="") for _ in range(d): print("d", end="") for _ in range(e): print("e", end="") for _ in range(f): print("f", end="") for _ in range(g): print("g", end="") for _ in range(h): print("h", end="") for _ in range(i1): print("i", end="") for _ in range(j): print("j", end="") for _ in range(k): print("k", end="") for _ in range(l): print("l", end="") for _ in range(m): print("m", end="") for _ in range(n): print("n", end="") for _ in range(o): print("o", end="") for _ in range(p): print("p", end="") for _ in range(q): print("q", end="") for _ in range(r): print("r", end="") for _ in range(s): print("s", end="") for _ in range(t): print("t", end="") for _ in range(u): print("u", end="") for _ in range(v): print("v", end="") for _ in range(w): print("w", end="") for _ in range(x): print("x", end="") for _ in range(y): print("y", end="") for _ in range(z): print("z", end="") print()
Statement Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string. He will receive a headline which contains one of the strings S_1,...,S_n tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains. Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
[{"input": "3\n cbaa\n daacc\n acacac", "output": "aac\n \n\nThe strings that can be created from each of `cbaa`, `daacc` and `acacac`, are\n`aa`, `aac`, `aca`, `caa` and so forth. Among them, `aac`, `aca` and `caa` are\nthe longest, and the lexicographically smallest of these three is `aac`.\n\n* * *"}, {"input": "3\n a\n aa\n b", "output": "The answer is an empty string."}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s302698364
Accepted
p03331
Input is given from Standard Input in the following format: N
# coding: utf-8 import re import math import itertools from copy import deepcopy import fractions import random from heapq import heappop, heappush import time import os import sys import datetime from functools import lru_cache readline = sys.stdin.readline sys.setrecursionlimit(2000) # import numpy as np alphabet = "abcdefghijklmnopqrstuvwxyz" mod = int(10**9 + 7) inf = int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find: def __init__(self, n): self.n = n self.P = [a for a in range(N)] self.rank = [0] * n def find(self, x): if x != self.P[x]: self.P[x] = self.find(self.P[x]) return self.P[x] def same(self, x, y): return self.find(x) == self.find(y) def link(self, x, y): if self.rank[x] < self.rank[y]: self.P[x] = y elif self.rank[y] < self.rank[x]: self.P[y] = x else: self.P[x] = y self.rank[y] += 1 def unite(self, x, y): self.link(self.find(x), self.find(y)) def size(self): S = set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_power(a, b): # aはbの累乗数か now = b while now < a: now *= b if now == a: return True else: return False def bin_(num, size): A = [0] * size for a in range(size): if (num >> (size - a - 1)) & 1 == 1: A[a] = 1 else: A[a] = 0 return A def fac_list(n, mod_=0): A = [1] * (n + 1) for a in range(2, len(A)): A[a] = A[a - 1] * a if mod > 0: A[a] %= mod_ return A def comb(n, r, mod, fac): if n - r < 0: return 0 return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod def next_comb(num, size): x = num & (-num) y = num + x z = num & (~y) z //= x z = z >> 1 num = y | z if num >= (1 << size): return False else: return num def get_primes(n, type="int"): A = [True] * (n + 1) A[0] = False A[1] = False for a in range(2, n + 1): if A[a]: for b in range(a * 2, n + 1, a): A[b] = False if type == "bool": return A B = [] for a in range(n + 1): if A[a]: B.append(a) return B def is_prime(num): if num <= 2: return False i = 2 while i * i <= num: if num % i == 0: return False i += 1 return True def join(A, c=" "): n = len(A) A = list(map(str, A)) s = "" for a in range(n): s += A[a] if a < n - 1: s += c return s ############################################# n = int(input()) if is_power(n, 10): print(10) else: n = str(n) n = list(n) n = list(map(int, n)) print(sum(n))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s371148599
Accepted
p03331
Input is given from Standard Input in the following format: N
import sys, re from collections import deque, defaultdict, Counter from math import ( ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, ) from itertools import ( accumulate, permutations, combinations, combinations_with_replacement, product, groupby, ) from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from fractions import gcd from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 # from decimal import * def ketawa(x): return sum(map(int, list(str(x)))) N = INT() ans = INF for a in range(1, N // 2 + 1): b = N - a ans = min(ans, ketawa(a) + ketawa(b)) print(ans)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s978392222
Wrong Answer
p03331
Input is given from Standard Input in the following format: N
print(sum(map(int, input().split())))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s549117753
Wrong Answer
p03331
Input is given from Standard Input in the following format: N
a = int() b = int() wa_list = [] n = int(input()) for a in range(n + 1): if b == n - a: wa_list.append(sum(map(int, list(str(a)))) + sum(map(int, list(str(b))))) print(min(wa_list))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s684140340
Accepted
p03331
Input is given from Standard Input in the following format: N
# main input_str = input() input_num = int(input_str) input_num_digits = len(input_str) - 1 if input_num == 10**input_num_digits: min_digit_sums = [10] else: former_num = 10**input_num_digits latter_num = input_num - former_num digit_sum = 0 for char in str(former_num): digit_sum += int(char) for char in str(latter_num): digit_sum += int(char) min_digit_sums = [digit_sum] for i in range(1, input_num // 2): former_num = i latter_num = input_num - i digit_sum = 0 for char in str(former_num): digit_sum += int(char) if digit_sum >= min(min_digit_sums): continue for char in str(latter_num): digit_sum += int(char) if digit_sum < min(min_digit_sums): min_digit_sums.append(digit_sum) print(str(min(min_digit_sums)))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s842459881
Accepted
p03331
Input is given from Standard Input in the following format: N
#!/usr/bin/env python3 from collections import defaultdict, deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list(map(lambda x: int(x) - 1, input().split())) def II(): return int(input()) def IF(): return float(input()) def LS(): return list(map(list, input().split())) def S(): return list(input().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = 1e10 # solve def solve(): n = input().rstrip() ans = sum(map(int, list(n))) if int(n) == 10 ** (len(n) - 1): ans = 10 print(ans) return # main if __name__ == "__main__": solve()
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s217375602
Runtime Error
p03331
Input is given from Standard Input in the following format: N
from fractions import gcd N, A, B, K = map(int, input().split()) mod = 998244353 Factorial = [1] * (N + 1) for i in range(1, N + 1): Factorial[i] = Factorial[i - 1] * (i) % mod def power(x, y): if y == 0: return 1 elif y == 1: return x % mod elif y % 2 == 0: return power(x, y // 2) ** 2 % mod else: return (power(x, y // 2) ** 2) * x % mod inverseFactorial = [1] * (N + 1) inverseFactorial[N] = power(Factorial[N], mod - 2) for i in range(0, N)[::-1]: inverseFactorial[i] = (inverseFactorial[i + 1] * (i + 1)) % mod def f(i, j): if i > j: i, j = j, i res = 0 if j <= N: for k in range(max(0, i + j - N), i + 1): res += ( Factorial[N] * inverseFactorial[i - k] * inverseFactorial[j - k] * inverseFactorial[k] * inverseFactorial[N - i - j + k] ) return res % mod ans = 0 g = gcd(A, B) if K % g == 0: A, B, K = A // g, B // g, K // g else: print(0) exit() for i in range(K // A + 1): if (K - A * i) % B == 0: x0 = i y0 = (K - A * i) // B break m = 0 while y0 - A * m >= 0: ans += f(x0 + B * m, y0 - A * m) ans %= mod m += 1 print(ans % mod - 1)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s483165617
Runtime Error
p03331
Input is given from Standard Input in the following format: N
N = int(input()) ls = [] for i in range(1, N - 1): b = N - i e = i % 10 f = i % 100 g = i % 1000 h = i % 10000 j = i % 100000 E = b % 10 F = b % 100 G = b % 1000 H = b % 10000 J = b % 100000 x = e + (f - e) / 10 + (g - f) / 100 + (h - g) / 1000 + (j - h) / 10000 X = E + (F - E) / 10 + (G - F) / 100 + (H - G) / 1000 + (J - H) / 10000 ls.append(x + X) print(int(min(ls)))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s106026854
Runtime Error
p03331
Input is given from Standard Input in the following format: N
n = int(input()) res = set([]) for i, j in zip(range(1, n), range(n - 1, n // 2, -1)): q_a = sum([int(x) for x in str(i)]) q_b = sum([int(x) for x in str(j)]) res.add(q_a + q_b) print(min(res))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s687858439
Accepted
p03331
Input is given from Standard Input in the following format: N
n = int(input()) wa_min = n for i in range(1, n + 1): n1 = n - i n2 = i wa1 = 0 wa2 = 0 while n1 > 0: mod = n1 % 10 wa1 += mod n1 = n1 // 10 while n2 > 0: mod2 = n2 % 10 wa2 += mod2 n2 = n2 // 10 if (wa1 + wa2) < wa_min: wa_min = wa1 + wa2 if i == n - i: break print(wa_min)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s183160796
Wrong Answer
p03331
Input is given from Standard Input in the following format: N
N = int(input()) ans = 1000000 for i in range(2, N): ans = min( (i % 10) + ((i // 10) % 10) + ((i // 100) % 10) + ((i // 1000) % 10) + ((i // 10000) % 10) + ((i // 100000) % 10) + ((i // 1000000) % 10) + ((N - i) % 10) + (((N - i) // 10) % 10) + (((N - i) // 100) % 10) + (((N - i) // 1000) % 10) + (((N - i) // 10000) % 10) + (((N - i) // 100000) % 10) + (((N - i) // 1000000) % 10), ans, ) print(ans)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s268441380
Wrong Answer
p03331
Input is given from Standard Input in the following format: N
n = int(input()) a, b, sA, sB, result = 1, 0, 0, 0, 0 soma = [] while a <= n: b = n - a for i in str(a): sA += int(i) for j in str(b): sB += int(j) soma.append(sA + sB) a = a + 1 for k in str(min(soma)): result += int(k) print(result)
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s172269220
Accepted
p03331
Input is given from Standard Input in the following format: N
N = int(input()) A = 1 B = 1 listA = [] listB = [] for i in range(N): # N = A + B A = i + 1 B = N - i - 1 listA.append(A) listB.append(B) ans = [] for i in range(N - 1): A = str(listA[i]) if len(str(A)) == 1: sumA = int(A) elif len(str(A)) == 2: sumA = int(A[0]) + int(A[1]) elif len(str(A)) == 3: sumA = int(A[0]) + int(A[1]) + int(A[2]) elif len(str(A)) == 4: sumA = int(A[0]) + int(A[1]) + int(A[2]) + int(A[3]) elif len(str(A)) == 5: sumA = int(A[0]) + int(A[1]) + int(A[2]) + int(A[3]) + int(A[4]) elif len(str(A)) == 6: sumA = int(A[0]) + int(A[1]) + int(A[2]) + int(A[3]) + int(A[4]) + int(A[5]) B = str(listB[i]) if len(str(B)) == 1: sumB = int(B) elif len(str(B)) == 2: sumB = int(B[0]) + int(B[1]) elif len(str(B)) == 3: sumB = int(B[0]) + int(B[1]) + int(B[2]) elif len(str(B)) == 4: sumB = int(B[0]) + int(B[1]) + int(B[2]) + int(B[3]) elif len(str(B)) == 5: sumB = int(B[0]) + int(B[1]) + int(B[2]) + int(B[3]) + int(B[4]) elif len(str(B)) == 6: sumB = int(B[0]) + int(B[1]) + int(B[2]) + int(B[3]) + int(B[4]) + int(B[5]) ans.append(sumA + sumB) print(min(ans))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s028989762
Accepted
p03331
Input is given from Standard Input in the following format: N
n = int(input()) if n % 10 == 0 and n != 10: print(10) else: a, b = 1, 0 sA, sB = 0, 0 soma = [] while a <= n: b = n - a for i in str(a): sA += int(i) for j in str(b): sB += int(j) soma.append(sA + sB) a = a + 1 print(min(soma))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s310163769
Runtime Error
p03331
Input is given from Standard Input in the following format: N
import numpy as np N = int(input()) ku = np.zeros((N, 2), dtype=int) for i in range(N): l = list(map(int, input().split())) ku[i][0] = l[0] ku[i][1] = l[1] K = 0 now = 0 for i in range(N): a = np.zeros(len(ku)) flag = np.zeros(len(ku)) for j in range(len(ku)): if now > ku[j][0] and now < ku[j][1]: a[j] = 0 flag[j] = 0 elif now < ku[j][0]: a[j] = abs(now - ku[j][0]) flag[j] = 1 else: a[j] = abs(now - ku[j][1]) flag[j] = 2 idx = a.argmax() K += a[idx] if flag[idx] == 1: now = ku[idx][0] elif flag[idx] == 2: now = ku[idx][1] ku = np.delete(ku, 0, 0) K += abs(now) print(int(K))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]
Print the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B". * * *
s577145026
Accepted
p03331
Input is given from Standard Input in the following format: N
n = int(input()) ans = 0 lis = [] for i in range(1, n): r = n - i ti = list(str(i)) tr = list(str(r)) for k in range(len(ti)): ti[k] = int(ti[k]) for k in range(len(tr)): tr[k] = int(tr[k]) lis.append(sum(ti) + sum(tr)) print(min(lis))
Statement Takahashi has two positive integers A and B. It is known that A plus B equals N. Find the minimum possible value of "the sum of the digits of A" plus "the sum of the digits of B" (in base 10).
[{"input": "15", "output": "6\n \n\nWhen A=2 and B=13, the sums of their digits are 2 and 4, which minimizes the\nvalue in question.\n\n* * *"}, {"input": "100000", "output": "10"}]