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 minimum number of tiles that need to be repainted to satisfy the condition. * * *
s413882097
Accepted
p03073
Input is given from Standard Input in the following format: S
a = 0 for i, s in enumerate(input()): a += i % 2 ^ int(s) print(min(a, i - a + 1))
Statement N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition?
[{"input": "000", "output": "1\n \n\nThe condition can be satisfied by repainting the middle tile white.\n\n* * *"}, {"input": "10010010", "output": "3\n \n\n* * *"}, {"input": "0", "output": "0"}]
Print the minimum number of tiles that need to be repainted to satisfy the condition. * * *
s573178380
Accepted
p03073
Input is given from Standard Input in the following format: S
S = [int(i) for i in input()] A = sum([int(i % 2 == 0) == v for i, v in enumerate(S)]) B = sum([int(i % 2 != 0) == v for i, v in enumerate(S)]) print(min(A, B))
Statement N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition?
[{"input": "000", "output": "1\n \n\nThe condition can be satisfied by repainting the middle tile white.\n\n* * *"}, {"input": "10010010", "output": "3\n \n\n* * *"}, {"input": "0", "output": "0"}]
Print the minimum number of tiles that need to be repainted to satisfy the condition. * * *
s113545345
Accepted
p03073
Input is given from Standard Input in the following format: S
n = str(input()) n_arr = list(str(n)) arr = list(map(int, n_arr)) zero = [] one = [] for i in range(len(arr)): if i % 2 == 0: zero.append(0) one.append(1) else: zero.append(1) one.append(0) zero_diff = 0 one_diff = 0 for i in range(len(arr)): if arr[i] != zero[i]: zero_diff += 1 for i in range(len(arr)): if arr[i] != one[i]: one_diff += 1 print(min([one_diff, zero_diff]))
Statement N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition?
[{"input": "000", "output": "1\n \n\nThe condition can be satisfied by repainting the middle tile white.\n\n* * *"}, {"input": "10010010", "output": "3\n \n\n* * *"}, {"input": "0", "output": "0"}]
Print the minimum number of tiles that need to be repainted to satisfy the condition. * * *
s634216361
Runtime Error
p03073
Input is given from Standard Input in the following format: S
import sys def judge(string): mem = "" for char in string: if mem == char: return False mem = char return True def main(): sinputl = sys.stdin.readline input = sinputl().strip() length = len(input) input = int(input, base=2) paint = [length] for i in range(2**length): status = input ^ i print(bin(status)[2:].zfill(length)) if judge(bin(status)[2:].zfill(length)): paint.append(bin(i).count("1")) print(min(paint)) if __name__ == "__main__": main()
Statement N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition?
[{"input": "000", "output": "1\n \n\nThe condition can be satisfied by repainting the middle tile white.\n\n* * *"}, {"input": "10010010", "output": "3\n \n\n* * *"}, {"input": "0", "output": "0"}]
Print the minimum number of tiles that need to be repainted to satisfy the condition. * * *
s515479902
Accepted
p03073
Input is given from Standard Input in the following format: S
S = str(input()) ans_one_start = "" for i in range(len(S)): if i % 2 == 0: ans_one_start += "0" else: ans_one_start += "1" ans_zero_start = "" for i in range(len(S)): if i % 2 == 0: ans_zero_start += "1" else: ans_zero_start += "0" diff_one = 0 diff_zero = 0 for i in range(len(S)): s_i = S[i] diff_i = ans_one_start[i] if s_i != diff_i: diff_one += 1 for i in range(len(S)): s_i = S[i] diff_i = ans_zero_start[i] if s_i != diff_i: diff_zero += 1 print(min(diff_one, diff_zero))
Statement N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition?
[{"input": "000", "output": "1\n \n\nThe condition can be satisfied by repainting the middle tile white.\n\n* * *"}, {"input": "10010010", "output": "3\n \n\n* * *"}, {"input": "0", "output": "0"}]
Print the minimum number of tiles that need to be repainted to satisfy the condition. * * *
s847425604
Accepted
p03073
Input is given from Standard Input in the following format: S
Tiles = input() N_len = len(Tiles) type1 = 0 # 1スタート for i in range(N_len): if Tiles[i] == str(i % 2): type1 += 1 # 0スタート type2 = 0 for i in range(N_len): if Tiles[i] != str(i % 2): type2 += 1 print(min(type1, type2))
Statement N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition?
[{"input": "000", "output": "1\n \n\nThe condition can be satisfied by repainting the middle tile white.\n\n* * *"}, {"input": "10010010", "output": "3\n \n\n* * *"}, {"input": "0", "output": "0"}]
Print the minimum number of tiles that need to be repainted to satisfy the condition. * * *
s167511359
Accepted
p03073
Input is given from Standard Input in the following format: S
S = list(input()) S = [int(s) for s in S] T = [] for s in range(len(S)): if s % 2 == 0: T.append(S[s] == 0) else: T.append(S[s] == 1) U = [] for s in range(len(S)): if s % 2 == 0: U.append(S[s] == 1) else: U.append(S[s] == 0) M = max(sum(T), sum(U)) print(len(S) - M)
Statement N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is `0`, and painted white if that character is `1`. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition?
[{"input": "000", "output": "1\n \n\nThe condition can be satisfied by repainting the middle tile white.\n\n* * *"}, {"input": "10010010", "output": "3\n \n\n* * *"}, {"input": "0", "output": "0"}]
Print the number of divisors in a line.
s991512622
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
import sys def main(lines=None): # ここは変えない if not lines: lines = sys.stdin.readlines() lines = [line.split() for line in lines] a, b, c = [int(e) for inner_list in lines for e in inner_list] # ここまで answer = 0 for i in range(a, b + 1): if c % i == 0: answer += 1 print(answer) # returnするときはstr型にする return str(answer) # 改行で複数項目をtest出力したい場合 # print("\n".join(answers)) # return "\n".join(answers) def test_main(): test_inputs = """ 1 1 1 """.strip() test_inputs = test_inputs.split("\n") answer = main(test_inputs) expect = """ 1 """.strip() assert answer == expect if __name__ == "__main__": main()
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s256486224
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
AA, BB, n = map(int, input().split()) CC = [] if n == 1: L = [1] l = sum(i >= AA for i in L) ll = sum(i > BB for i in L) print(l - ll) else: def sample_code(): fct = factorize(n) for div in divisorize(fct): C = num(div) CC.append(C) def divisorize(fct): b, e = fct.pop() # base, exponent pre_div = divisorize(fct) if fct else [[]] suf_div = [[(b, k)] for k in range(e + 1)] return [pre + suf for pre in pre_div for suf in suf_div] def factorize(n): fct = [] # prime factor b, e = 2, 0 # base, exponent while b * b <= n: while n % b == 0: n = n // b e = e + 1 if e > 0: fct.append((b, e)) b, e = b + 1, 0 if n > 1: fct.append((n, 1)) return fct def num(fct): a = 1 for base, exponent in fct: a = a * base**exponent return a if __name__ == "__main__": sample_code() CCC = sorted(CC) nnn = sum(i >= AA for i in CCC) NNN = sum(i > BB for i in CCC) print(nnn - NNN)
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s072832495
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
items = list(map(int, input().split())) print(len(list(filter(lambda x: items[2] % x == 0, range(items[0], items[1] + 1)))))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s726747587
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
a = list(map(int, input().split())) b = a[0] c = a[1] d = a[2] e = [] for i in range(b, c + 1): if d % i == 0: e.append(i) print(len(e))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s441773343
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
A, B, C = [int(_) for _ in input().split()] print(sum(C % i == 0 for i in range(A, B + 1)))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s349214524
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
j = [int(i) for i in input().split()] print(sum([1 for i in range(j[0], j[1] + 1) if not j[2] % i]))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s718331293
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
i = input().split() i = [int(x) for x in i] c = [1 for x in range(i[0], i[1] + 1) if i[2] % x == 0] print(sum(c))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s671690367
Runtime Error
p02398
Three integers a, b and c are given in a line separated by a single space.
a, b = map(int, input().split()) print(a // b, a % b, "{0:.8f}".format(a / b))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s513434868
Wrong Answer
p02398
Three integers a, b and c are given in a line separated by a single space.
list = input().split() li_uniq = [] for x in list: if x not in li_uniq: li_uniq.append(x) print(len(li_uniq))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s573468566
Accepted
p02398
Three integers a, b and c are given in a line separated by a single space.
a, b, c = list(map(int, input().split(" "))) div = [i if (c % i == 0) else 0 for i in range(a, b + 1)] div.append(0) print(len(set(div)) - 1)
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s199847765
Wrong Answer
p02398
Three integers a, b and c are given in a line separated by a single space.
a, b, c = [int(w) for w in input().split()] print(len([i for i in range(a, b + 1) if i % c == 0]))
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Print the number of divisors in a line.
s566063273
Wrong Answer
p02398
Three integers a, b and c are given in a line separated by a single space.
a, b, c = [int(n) for n in input().split()] print(b // c - a // c)
How Many Divisors? Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
[{"input": "5 14 80", "output": "3"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s995795741
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
S = input() K = "CODEFESTIVAL2016" sum = 0 for i in range(len(S)): if S[i] != K[i] sum += 1 print(sum)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s832318995
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print(sum((x != y for x, y in zip(input(), "CODEFESTIVAL2016"))))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s985477759
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import accumulate, permutations, combinations, 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 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 S = input() T = "CODEFESTIVAL2016" print(sum(x != y for x, y in zip(S, T)))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s062591317
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
str = "CODEFESTIVAL2016" s =input() cnt = 0 for i in range(16): if s[i]!=str[i]: cnt++ print(cnt)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s132594942
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print(sum(a != b for a, b in zip("CODEFESTIVAL2016", input())))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s238957164
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print(sum(map(lambda a, b: a != b, "CODEFESTIVAL2016", input())))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s263570945
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
N = int(input()) a = [0] * N for i in range(N): a[i] = int(input()) minimum = 1 count = 0 for i in a: if minimum < i: if i % minimum: count += i // minimum else: count += i // minimum - 1 else: minimum = max(minimum, i + 1) print(count)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s744535339
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
s=list(input()) v=list("CODEFESTIVAL2016") cnt=0 for i in range(16): if s[i]!=v[i]: cnt+=1 print(cnt)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s481944337
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print( len( list( filter( lambda x: x == 0, map( lambda x, y: True if x == y else False, list("CODEFESTIVAL2016"), list(input()), ), ) ) ) )
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s624077071
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
s = input() ans = 'CODEFESTIVAL2016' cnt = 0 for i in range(n): if s[i] = != ans[i]: cnt += 1 print(cnt)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s801003379
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print(sum((t != s for t, s in zip("CODEFESTIVAL2016", input()))))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s731343295
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print(sum(s != t for s, t in zip(input(), "CODEFESTIVAL2016")))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s538226005
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print(sum(c1 != c2 for c1, c2 in zip("CODEFESTIVAL2016", input())))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s388059903
Accepted
p03970
Inputs are provided from Standard Input in the following form. S
print(sum([1 if i != j else 0 for i, j in zip(input(), "CODEFESTIVAL2016")]))
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s211162287
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
s=input() t="CODEFESTIVAL2016" ret=0 for i range(s.len()): if s[i] != t[i]: ret+=1 print(ret)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s529161376
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
s= input() ss =‘CODEFESTIVAL2016’ t = 1 for i in range(s): if s[i]==ss[i]: t +=1 print(t)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s299405319
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
a=input() ans="CODEFESTIVAL2016" diff=0 for i in range(16): if a[i]!=ans[i]: diff++ print(diff)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Output an integer representing the minimum number of iterations needed for the rewrite operation. * * *
s344838884
Runtime Error
p03970
Inputs are provided from Standard Input in the following form. S
s=input() ans=0 if s[0]=='C': ans+=1 if s[1]='O': ans+=1 if s[2]='D': ans+=1 if s[3]='E': ans+=1 if s[4]='F': ans+=1 if s[5]='E': ans+=1 if s[6]='S': ans+=1 if s[7]='T': ans+=1 if s[8]='I': ans+=1 if s[9]='V': ans+=1 if s[10]='A': ans+=1 if s[11]='L': ans+=1 if s[12]='2': ans+=1 if s[13]='0': ans+=1 if s[14]='1': ans+=1 if s[15]='6': ans+=1 print(ans)
Statement CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. So Mr. Takahashi decided to perform an operation that replaces a certain character with another in the minimum number of iterations, changing the string to `CODEFESTIVAL2016`. Find the minimum number of iterations for the rewrite operation.
[{"input": "C0DEFESTIVAL2O16", "output": "2\n \n\nThe second character `0` must be changed to `O` and the 14th character `O`\nchanged to `0`.\n\n* * *"}, {"input": "FESTIVAL2016CODE", "output": "16"}]
Print the sum of f(T) modulo 998244353. * * *
s025340247
Wrong Answer
p02662
Input is given from Standard Input in the following format: N S A_1 A_2 ... A_N
a, b = map(float, input().split()) a = int(a) print(int(a * b))
Statement Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S. For a non-empty subset T of the set \\{1, 2, \ldots , N \\}, let us define f(T) as follows: * f(T) is the number of different non-empty subsets \\{x_1, x_2, \ldots , x_k \\} of T such that A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(T) over all 2^N-1 subsets T of \\{1, 2, \ldots , N \\}. Since the sum can be enormous, print it modulo 998244353.
[{"input": "3 4\n 2 2 4", "output": "6\n \n\nFor each T, the value of f(T) is shown below. The sum of these values is 6.\n\n * f(\\\\{1\\\\}) = 0\n * f(\\\\{2\\\\}) = 0\n * f(\\\\{3\\\\}) = 1 (One subset \\\\{3\\\\} satisfies the condition.)\n * f(\\\\{1, 2\\\\}) = 1 (\\\\{1, 2\\\\})\n * f(\\\\{2, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 2, 3\\\\}) = 2 (\\\\{1, 2\\\\}, \\\\{3\\\\})\n\n* * *"}, {"input": "5 8\n 9 9 9 9 9", "output": "0\n \n\n* * *"}, {"input": "10 10\n 3 1 4 1 5 9 2 6 5 3", "output": "3296"}]
Print the sum of f(T) modulo 998244353. * * *
s818001227
Wrong Answer
p02662
Input is given from Standard Input in the following format: N S A_1 A_2 ... A_N
print(3296)
Statement Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S. For a non-empty subset T of the set \\{1, 2, \ldots , N \\}, let us define f(T) as follows: * f(T) is the number of different non-empty subsets \\{x_1, x_2, \ldots , x_k \\} of T such that A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(T) over all 2^N-1 subsets T of \\{1, 2, \ldots , N \\}. Since the sum can be enormous, print it modulo 998244353.
[{"input": "3 4\n 2 2 4", "output": "6\n \n\nFor each T, the value of f(T) is shown below. The sum of these values is 6.\n\n * f(\\\\{1\\\\}) = 0\n * f(\\\\{2\\\\}) = 0\n * f(\\\\{3\\\\}) = 1 (One subset \\\\{3\\\\} satisfies the condition.)\n * f(\\\\{1, 2\\\\}) = 1 (\\\\{1, 2\\\\})\n * f(\\\\{2, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 2, 3\\\\}) = 2 (\\\\{1, 2\\\\}, \\\\{3\\\\})\n\n* * *"}, {"input": "5 8\n 9 9 9 9 9", "output": "0\n \n\n* * *"}, {"input": "10 10\n 3 1 4 1 5 9 2 6 5 3", "output": "3296"}]
Print the sum of f(T) modulo 998244353. * * *
s648144615
Wrong Answer
p02662
Input is given from Standard Input in the following format: N S A_1 A_2 ... A_N
def subsets(nums): output = [] for i in range(1, len(nums)): backtrack(0, nums, i, [], output) return output def backtrack(start, nums, size, curr, output): if len(curr) == size: output.append(curr[:]) for i in range(start, len(nums)): curr.append(nums[i]) backtrack(i + 1, nums, size, curr, output) curr.pop() def count_subsets(num, sum): n = len(num) dp = [0 for _ in range(sum + 1)] dp[0] = 1 # with only one number, we can form a subset only when the required sum is equal to the number for s in range(1, sum + 1): dp[s] = 1 if num[0] == s else 0 # process all subsets for all sums for i in range(1, n): for s in range(sum, -1, -1): if s >= num[i]: dp[s] += dp[s - num[i]] return dp[-1] N, S = map(int, input().split()) sub_sets = list(map(int, input().split())) result = count_subsets(sub_sets, S) print(result % 998244353)
Statement Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S. For a non-empty subset T of the set \\{1, 2, \ldots , N \\}, let us define f(T) as follows: * f(T) is the number of different non-empty subsets \\{x_1, x_2, \ldots , x_k \\} of T such that A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(T) over all 2^N-1 subsets T of \\{1, 2, \ldots , N \\}. Since the sum can be enormous, print it modulo 998244353.
[{"input": "3 4\n 2 2 4", "output": "6\n \n\nFor each T, the value of f(T) is shown below. The sum of these values is 6.\n\n * f(\\\\{1\\\\}) = 0\n * f(\\\\{2\\\\}) = 0\n * f(\\\\{3\\\\}) = 1 (One subset \\\\{3\\\\} satisfies the condition.)\n * f(\\\\{1, 2\\\\}) = 1 (\\\\{1, 2\\\\})\n * f(\\\\{2, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 2, 3\\\\}) = 2 (\\\\{1, 2\\\\}, \\\\{3\\\\})\n\n* * *"}, {"input": "5 8\n 9 9 9 9 9", "output": "0\n \n\n* * *"}, {"input": "10 10\n 3 1 4 1 5 9 2 6 5 3", "output": "3296"}]
Print the sum of f(T) modulo 998244353. * * *
s813016332
Runtime Error
p02662
Input is given from Standard Input in the following format: N S A_1 A_2 ... A_N
from collections import Counter MOD = 998244353 n, s = map(int, input().split()) la = [int(i) for i in input().split()] dks = [[None for s_ in range(s + 1)] for i in range(n)] def getks(i=0, s=s): # la[i:] if s < 0: return Counter({}) elif i == n: if s == 0: return Counter({0: 1}) else: return Counter({}) elif dks[i][s] is not None: return dks[i][s] else: ks0 = getks(i + 1, s) ks1 = Counter({k + 1: v for k, v in getks(i + 1, s - la[i]).items()}) ks = ks0 + ks1 dks[i][s] = ks return ks ks = getks() answer = 0 for k, v in ks.items(): answer += pow(2, n - k, MOD) * v answer %= MOD print(answer)
Statement Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S. For a non-empty subset T of the set \\{1, 2, \ldots , N \\}, let us define f(T) as follows: * f(T) is the number of different non-empty subsets \\{x_1, x_2, \ldots , x_k \\} of T such that A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(T) over all 2^N-1 subsets T of \\{1, 2, \ldots , N \\}. Since the sum can be enormous, print it modulo 998244353.
[{"input": "3 4\n 2 2 4", "output": "6\n \n\nFor each T, the value of f(T) is shown below. The sum of these values is 6.\n\n * f(\\\\{1\\\\}) = 0\n * f(\\\\{2\\\\}) = 0\n * f(\\\\{3\\\\}) = 1 (One subset \\\\{3\\\\} satisfies the condition.)\n * f(\\\\{1, 2\\\\}) = 1 (\\\\{1, 2\\\\})\n * f(\\\\{2, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 2, 3\\\\}) = 2 (\\\\{1, 2\\\\}, \\\\{3\\\\})\n\n* * *"}, {"input": "5 8\n 9 9 9 9 9", "output": "0\n \n\n* * *"}, {"input": "10 10\n 3 1 4 1 5 9 2 6 5 3", "output": "3296"}]
Print the sum of f(T) modulo 998244353. * * *
s490835274
Wrong Answer
p02662
Input is given from Standard Input in the following format: N S A_1 A_2 ... A_N
from functools import lru_cache @lru_cache(maxsize=1000) def pow_r(x, n, mod=10**9 + 7): """ O(log n) """ if n == 0: # exit case return 1 if n % 2 == 0: # standard case ① n is even return pow_r((x**2) % 1000000007, n // 2) % mod else: # standard case ② n is odd return (x * pow_r((x**2) % 1000000007, (n - 1) // 2) % mod) % mod def resolve(): N, S = map(int, input().split()) A = map(int, input().split()) dpt = [dict() for i in range(S + 1)] dpt[0][0] = 1 mx = 0 for i in A: for j in range(min(mx, S - i) + 1, -1, -1): if dpt[j]: mx = max(j + i, mx) if i + j > S: continue for k in dpt[j]: if not k + 1 in dpt[j + i]: dpt[j + i][k + 1] = 0 dpt[j + i][k + 1] += dpt[j][k] ans = 0 for i in dpt[-1]: ans += (pow_r(2, N - i, mod=998244353) * dpt[-1][i]) % 998244353 print(ans) resolve()
Statement Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S. For a non-empty subset T of the set \\{1, 2, \ldots , N \\}, let us define f(T) as follows: * f(T) is the number of different non-empty subsets \\{x_1, x_2, \ldots , x_k \\} of T such that A_{x_1}+A_{x_2}+\cdots +A_{x_k} = S. Find the sum of f(T) over all 2^N-1 subsets T of \\{1, 2, \ldots , N \\}. Since the sum can be enormous, print it modulo 998244353.
[{"input": "3 4\n 2 2 4", "output": "6\n \n\nFor each T, the value of f(T) is shown below. The sum of these values is 6.\n\n * f(\\\\{1\\\\}) = 0\n * f(\\\\{2\\\\}) = 0\n * f(\\\\{3\\\\}) = 1 (One subset \\\\{3\\\\} satisfies the condition.)\n * f(\\\\{1, 2\\\\}) = 1 (\\\\{1, 2\\\\})\n * f(\\\\{2, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 3\\\\}) = 1 (\\\\{3\\\\})\n * f(\\\\{1, 2, 3\\\\}) = 2 (\\\\{1, 2\\\\}, \\\\{3\\\\})\n\n* * *"}, {"input": "5 8\n 9 9 9 9 9", "output": "0\n \n\n* * *"}, {"input": "10 10\n 3 1 4 1 5 9 2 6 5 3", "output": "3296"}]
Print the answer. * * *
s367522360
Accepted
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
from copy import * from sys import * import math import queue from collections import defaultdict, Counter, deque from fractions import Fraction as frac setrecursionlimit(1000000) def main(): n = int(input()) a = list(map(int, input().split())) r = [a[0]] for i in range(1, n): r.append(r[i - 1] + a[i]) s = sum(a) m = [] for i in range(n - 1): m.append(abs(2 * r[i] - s)) print(min(m)) def zip(a): mae = a[0] ziparray = [mae] for i in range(1, len(a)): if mae != a[i]: ziparray.append(a[i]) mae = a[i] return ziparray def is_prime(n): if n < 2: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True def list_replace(n, f, t): return [t if i == f else i for i in n] def base_10_to_n(X, n): X_dumy = X out = "" while X_dumy > 0: out = str(X_dumy % n) + out X_dumy = int(X_dumy / n) if out == "": return "0" return out def gcd(m, n): x = max(m, n) y = min(m, n) while x % y != 0: z = x % y x = y y = z return y class Queue: def __init__(self): self.q = deque([]) def push(self, i): self.q.append(i) def pop(self): return self.q.popleft() def size(self): return len(self.q) def debug(self): return self.q class Stack: def __init__(self): self.q = [] def push(self, i): self.q.append(i) def pop(self): return self.q.pop() def size(self): return len(self.q) def debug(self): return self.q class graph: def __init__(self): self.graph = defaultdict(list) def addnode(self, l): f, t = l[0], l[1] self.graph[f].append(t) self.graph[t].append(f) def rmnode(self, l): f, t = l[0], l[1] self.graph[f].remove(t) self.graph[t].remove(f) def linked(self, f): return self.graph[f] class dgraph: def __init__(self): self.graph = defaultdict(set) def addnode(self, l): f, t = l[0], l[1] self.graph[f].append(t) def rmnode(self, l): f, t = l[0], l[1] self.graph[f].remove(t) def linked(self, f): return self.graph[f] main()
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s595517108
Wrong Answer
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
import math import string import collections from collections import Counter from collections import deque from decimal import Decimal def readints(): return list(map(int, input().split())) def nCr(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def has_duplicates2(seq): seen = [] for item in seq: if not (item in seen): seen.append(item) return len(seq) != len(seen) def divisor(n): divisor = [] for i in range(1, n + 1): if n % i == 0: divisor.append(i) return divisor # coordinates dx = [-1, -1, -1, 0, 0, 1, 1, 1] dy = [-1, 0, 1, -1, 1, -1, 0, 1] n = int(input()) a = readints() # print(a) sum_a = sum(a) ans = 10**5 s = [0] * (n + 1) for i in range(n - 1): s[i + 1] = s[i] + a[i] tmptmp = sum_a - s[i + 1] # print('tmp', tmp) # print('tmptmp', tmptmp) x = abs(s[i + 1] - tmptmp) ans = min(ans, x) print(ans)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s765675625
Wrong Answer
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
a = int(input()) A = input().split() B = [int(s) for s in A] lnB = len(B) XX = 0 YY = 0 for i in range(lnB): mi = max(B) if XX > YY: YY += mi else: XX += mi B.remove(mi) B = list(B) p = sum(B) ZZ = abs(XX - YY) print(ZZ)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s001288984
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
mport itertools N = int(input()) a = list(map(int,input().split())) ruiseki = list(itertools.accumulate(a)) ans = 10**100 for i in range(N-1): ans = min(ans,abs(sum(a[:i+1])-sum(a[i+1:]))) print(ans)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s900094269
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
from itertools import accumulate N = int(input()) lst = list(map(int, input().split())) cumsum = list(accumulate(lst)) mi = 2 * 10 ** 9 su = cumsum[-1] for i in cumsum: mi = min(mi, abs(i - (su-i)) print(mi)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s852346185
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
import sys sys.setrecursionlimit(100000) from collections import defaultdict edges = [] to = defaultdict(list) # 1から到達できるか ot = defaultdict(list) # Nから到達できるか N, M, P = map(int, input().split()) visited_toN = [False] * (N + 1) visited_fm1 = [False] * (N + 1) for i in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 edges.append((a, b, -c + P)) to[a].append(b) ot[b].append(a) def dfs(v): global visited_fm1 if visited_fm1[v]: return visited_fm1[v] = True for nxt in to[v]: dfs(nxt) def dfs_r(v): global visited_toN if visited_toN[v]: return visited_toN[v] = True for nxt in ot[v]: dfs_r(nxt) dfs(0) dfs_r(N - 1) is_ok = [] for s, t in zip(visited_fm1, visited_toN): is_ok.append(s and t) # BellmanFord INF = 10**18 def bellmanFord(n, edges, s, g): """ input n : 頂点の数 edges : (始点, 終点, コスト)のリスト s : 探索の始点 g : 探索の終点 output sから各点への最短距離 """ d = [INF] * n d[s] = 0 cnt = 0 while True: update = False for a, b, c in edges: if not is_ok[a]: continue if not is_ok[b]: continue if d[a] != INF and d[b] > d[a] + c: d[b] = d[a] + c update = True if not update: break cnt += 1 # 負閉路の存在をチェック if cnt > n: print(-1) exit() # print(d,cnt) return d[g] ans = bellmanFord(N, edges, 0, N - 1) print(max(0, -ans))
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s301006351
Accepted
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
import sys import math import collections import itertools import array import inspect # Set max recursion limit sys.setrecursionlimit(1000000) # Debug output def chkprint(*args): names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()} print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args)) # Binary converter def to_bin(x): return bin(x)[2:] def li_input(): return [int(_) for _ in input().split()] def gcd(n, m): if n % m == 0: return m else: return gcd(m, n % m) def gcd_list(L): v = L[0] for i in range(1, len(L)): v = gcd(v, L[i]) return v def lcm(n, m): return (n * m) // gcd(n, m) def lcm_list(L): v = L[0] for i in range(1, len(L)): v = lcm(v, L[i]) return v # Width First Search (+ Distance) def wfs_d(D, N, K): """ D: 隣接行列(距離付き) N: ノード数 K: 始点ノード """ dfk = [-1] * (N + 1) dfk[K] = 0 cps = [(K, 0)] r = [False] * (N + 1) r[K] = True while len(cps) != 0: n_cps = [] for cp, cd in cps: for i, dfcp in enumerate(D[cp]): if dfcp != -1 and not r[i]: dfk[i] = cd + dfcp n_cps.append((i, cd + dfcp)) r[i] = True cps = n_cps[:] return dfk # Depth First Search (+Distance) def dfs_d(v, pre, dist): """ v: 現在のノード pre: 1つ前のノード dist: 現在の距離 以下は別途用意する D: 隣接リスト(行列ではない) D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト """ global D global D_dfs_d D_dfs_d[v] = dist for next_v, d in D[v]: if next_v != pre: dfs_d(next_v, v, dist + d) return # -------------------------------------------- dp = None def main(): N = int(input()) A = li_input() C = [] tmpsum = 0 for a in A: tmpsum += a C.append(tmpsum) ans = 10**100 for i in range(len(C) - 1): ans = min(ans, abs((C[-1] - C[i]) - C[i])) print(ans) main()
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s258490699
Wrong Answer
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
N = int(input()) arr = sorted(list(map(int, input().split()))) ssunke = 0 sarai = 0 if N % 2 != 0: ssunke += arr[N - 1] arr.pop(-1) for i in range(len(arr) // 2): if ssunke <= sarai: ssunke += arr[2 * i + 1] sarai += arr[2 * i] else: ssunke += arr[2 * i] sarai += arr[2 * i + 1] print(abs(ssunke - sarai))
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s624263409
Wrong Answer
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
iN = int(input()) aA = [int(_) for _ in input().split()] iD = sum(aA) iF = 0 iB = iD minDiff = 10**9 for a in aA[:-1]: iF += a iB -= a thisDiff = abs(iF - iB) minDiff = min(minDiff, thisDiff) print(minDiff)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s307585400
Wrong Answer
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
N, x = int(input()), 0 s = list(map(int, input().split())) for j in s: x += j x = x - s[0] * 2 ans = x for k in range(1, N - 1): x = x - s[k] * 2 ans = min(ans, abs(x)) print(ans)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s803206366
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
n = int(input()) a = [int(i) for i in input().split()] result = abs(sum(a[0:1]) - sum(a[1:])) for i in range(1:n-1): d = abs(sum(a[0:i+1]) - sum(a[i+1:])) if d<result: result = d print(result)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s516333962
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
~ "arc078_a.py" 13L, 193C 1,1 全て N = int(input()) a = [int(n) for n in input().split()] x = 0 y = sum(a) res = 1000000000000000 for i in range(N-1): x += a[i] y -= a[i] if res > abs(x-y): res = abs(x-y) print(res)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s230746641
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
C - Splitting Pile N = int(input()) a = list(map(int, input().split())) sum_s = a[0] tmp = sum(a)//2 for i in range(1,N): if sum_s < tmp: sum_s += a[i] else: break sum_a = sum(a) - sum_s ans = abs(sum_s - sum_a) print(ans)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s467482132
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
n = int(input()) a = list(map(int,input().split())) sss = 0 for i in range(n): sss=sss + a[i] ppp = 0 qqq = abs(sss - 2 * a[0]) for i in range(n): ppp=ppp + a[i] qo = abs(sss-2ppp) if qqq > qo: qqq=qo print(qqq)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s753640265
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
N = int(input()) L = list(map(int,input().split())) S = sum(L) A = [] for i in range(1,N): p = abs(2*sum(L[0:i])-S) A.append(p) print(min(A))
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s554410993
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
N=int(input()) lst=[int(i) for i in input().split()] import numpy res=numpy.cumsum(lst) ans=10e10 for i in range(N): ans=min(ans,abs(res[i]-(res[-1]-res[i])) print(ans)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s042568386
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
n = int(input()) v = list(map(int, input().split())) t = [0] s = 2000000000 for i in range(0, n): t.append(t[i]+v[i]) for i in range(0, n-1): s = min(s, abs(t[n]-t[i+1]) print(s)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s789515603
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
n = int(input()) v = list(map(int, input().split())) t = [0] s = 2000000000 for i in range(0, n): t.append(t[i]+v[i]) for i in range(0, n-1): s = min(s, abs(s-t[i+1]) print(s)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s152775147
Runtime Error
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
n = int(input()) a = list(map(int, input().split())) s = [0] if (n == 2): print(abs(a[0] - a[1])) else: for i in range(n): s.append(a[i] + s[i]) b = 1e+9 j = 1 while j != n: if (abs(s[j] - (s[n] - s[j])) < b): b = abs(s[j] - (s[n] - s[j])) j++ print(b)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s802836114
Accepted
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
# coding: utf-8 import re import math from collections import defaultdict from collections import deque import collections from fractions import Fraction import itertools from copy import deepcopy import random import time import os import queue import sys import datetime from functools import lru_cache # @lru_cache(maxsize=None) readline = sys.stdin.readline sys.setrecursionlimit(2000000) # 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 ispow(a, b): # aはbの累乗数か now = b while now < a: now *= b if now == a: return True else: return False def getbin(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 getfacs(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 nextcomb(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 getprimes(n, type="int"): if n == 0: if type == "int": return [] else: return [False] 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 isprime(num): if num <= 1: return False i = 2 while i * i <= num: if num % i == 0: return False i += 1 return True def ifelse(a, b, c): if a: return b else: return c 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 def factorize(n, type_="dict"): b = 2 list_ = [] while b * b <= n: while n % b == 0: n //= b list_.append(b) b += 1 if n > 1: list_.append(n) if type_ == "dict": dic = {} for a in list_: if a in dic: dic[a] += 1 else: dic[a] = 1 return dic elif type_ == "list": return list_ else: return None def pm(x): return x // abs(x) def inputintlist(): return list(map(int, input().split())) ###################################################################################################### n = int(input()) A = inputintlist() ssum = sum(A) ans = inf now = 0 for a in A[:-1]: now += a x = now y = ssum - now ans = min(ans, abs(x - y)) print(ans)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s271057922
Wrong Answer
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
n = int(input()) v = list(map(int, input().split())) v.sort() a = 1000000007 s = 0 for i in range(0, len(v)): s += v[i] a = min(a, abs(v[i])) print(2 * a - s % 2)
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the answer. * * *
s052737135
Accepted
p03659
Input is given from Standard Input in the following format: N a_1 a_2 ... a_{N}
n = int(input()) a_list = list(map(int, input().split())) a1_list = a_list res_list = [] a_score = 0 s_score = 0 for i in range(n): a_score += a_list[i] for i in a1_list: a_score -= i s_score += i res = abs(s_score - a_score) res_list.append(res) del res_list[n - 1] print(min(res_list))
Statement Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
[{"input": "6\n 1 2 3 4 5 6", "output": "1\n \n\nIf Snuke takes four cards from the top, and Raccoon takes the remaining two\ncards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.\n\n* * *"}, {"input": "2\n 10 -10", "output": "20\n \n\nSnuke can only take one card from the top, and Raccoon can only take the\nremaining one card. In this case, x=10, y=-10, and thus |x-y|=20."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s891037290
Accepted
p03209
Input is given from Standard Input in the following format: N X
def solve(): n, x = map(int, input().split()) l = [1] nu = [1] for i in range(n): l.append(l[-1] * 2 + 3) nu.append(nu[-1] * 2 + 1) def chris(a, b): if a == 0: return b elif b <= a: return 0 hl = l[a] if b >= hl - a: return nu[a] elif hl // 2 + 1 <= b: return nu[a - 1] + 1 + chris(a - 1, b - (hl // 2 + 1)) return chris(a - 1, b - 1) print(chris(n, x)) solve()
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s141751566
Accepted
p03209
Input is given from Standard Input in the following format: N X
def delete_head_zeros(n): n = str(n) l = len(n) if "." in n: l = n.find(".") head_zeros = 0 for i in range(l - 1): if n[i] == "0": head_zeros += 1 else: break return n[head_zeros:] # compare a, b # a, b: int or string def bigint_compare(a, b): a = delete_head_zeros(a) b = delete_head_zeros(b) if len(a) > len(b): return 1 elif len(a) < len(b): return -1 else: if a > b: return 1 elif a < b: return -1 else: return 0 # calculate a + b # a, b: int or string def bigint_plus(a, b): a = str(a) b = str(b) d = max([len(a), len(b)]) a = "0" * (d - len(a)) + a b = "0" * (d - len(b)) + b ans = "" carry = 0 for i in range(d): s = int(a[-i - 1]) + int(b[-i - 1]) + carry carry = s // 10 ans = str(s % 10) + ans else: if carry: ans = str(carry) + ans return ans # calculate a - b # a, b: int or string def bigint_minus(a, b): a = str(a) b = str(b) M = [] m = [] sign = "" if len(a) > len(b) or (len(a) == len(b) and a >= b): [M, m] = [a, b] else: [M, m] = [b, a] sign = "-" m = "0" * (len(M) - len(m)) + m ans = "" borrow = 0 for i in range(len(M)): s = int(M[-i - 1]) - int(m[-i - 1]) - borrow if s < 0: borrow = 1 s += 10 else: borrow = 0 ans = str(s) + ans return sign + delete_head_zeros(ans) # calculate a * b # a, b: int or string def bigint_multiply(a, b): a = str(a) b = str(b) md = [] for j in range(len(b)): carry = 0 mj = "" for i in range(len(a)): m = int(a[-i - 1]) * int(b[-j - 1]) + carry carry = m // 10 mj = str(m % 10) + mj else: if carry: mj = str(carry) + mj md.append(mj) ans = 0 for k in range(len(md)): ans = bigint_plus(md[k] + "0" * k, ans) return ans # calculate a / b to d digits after decimal point # a, b, d: int or string def bigint_divide(a, b, d=0): a = str(a) b = str(b) d = int(d) if d < 0: d = 0 ans = "" r = "" for i in range(len(a) + d): q = 0 if i < len(a): r += a[i] elif i == len(a): ans += "." r += "0" else: r += "0" if bigint_compare(r, b) == -1: ans += str(q) else: while bigint_compare(r, b) >= 0: r = bigint_minus(r, b) q += 1 ans += str(q) return delete_head_zeros(ans) def main(): N, X = input().split(" ") layer = [1] patties = [1] for i in range(int(N)): layer.append(bigint_plus(bigint_multiply(layer[-1], 2), 3)) patties.append(bigint_plus(bigint_multiply(patties[-1], 2), 1)) def count_patty(L, Y, P): # Y, P : bigint if L == 0: return bigint_plus(P, 1) center = bigint_divide(bigint_plus(layer[L], 1), 2) if Y == "1": return P elif Y == layer[L]: return bigint_plus(P, patties[L]) elif bigint_compare(Y, center) == 0: return bigint_plus(bigint_plus(P, 1), patties[L - 1]) elif bigint_compare(Y, center) == 1: return count_patty( L - 1, bigint_minus(Y, center), bigint_plus(bigint_plus(P, patties[L - 1]), 1), ) elif bigint_compare(Y, center) == -1: return count_patty(L - 1, bigint_minus(Y, 1), P) print(count_patty(int(N), X, "0")) main()
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s000856243
Wrong Answer
p03209
Input is given from Standard Input in the following format: N X
def examA(): N = DI() / dec(7) ans = N print(N) return def examB(): ans = 0 print(ans) return def examC(): ans = 0 print(ans) return def examD(): N, X = LI() S = [0] * (N + 1) P = [0] * (N + 1) S[0] = 1 P[0] = 1 for i in range(N): S[i + 1] = S[i] * 2 + 3 P[i + 1] = P[i] * 2 + 1 def dfs(n, x): if n == 0: return 0 < x if x >= S[n - 1] + 2: return 1 + P[n - 1] + dfs(n - 1, x - 2 - S[n - 1]) return dfs(n - 1, x - 1) ans = dfs(N, X) print(ans) return from decimal import getcontext, Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(input()) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(input()) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord("a") + i) for i in range(26)] alphabet_convert = {chr(ord("a") + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == "__main__": examD() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s660937603
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n, x = map(int, input().split()) a,p = [1],[1] for i in range(N): a.append(a[i] * 2 + 3) p.append(p[i] * 2 + 1) deff(N, X): return 0 if X <= 0 else 1 elif X <= 1 + a[N - 1]: return f(N - 1, X - 1) else: return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1]) print(f(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s280157729
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n = int(input()) x = int(input()) list = ["P"] i = 1 while i < n + 1: list.append("P") list = list + list list.pop() list.append("B") list.insert(0, "B") i += 1 sosu = len(list) ku = sosu - x i = 1 while i < ku + 1: list.pop() i += 1 print(list.count("P"))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s660819750
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n, x = (int(x) for x in input().split()) f = [0] * (n + 1) g = [0] * (n + 1) f[0] = 1 g[0] = 1 for i in range(1, n + 1): f[i] = f[i - 1] * 2 + 3 g[i] = g[i - 1] * 2 + 1 total = 0 remain = x def eat(n): global total global f global remain if remain == 0: return if f[n] <= remain: total += g[n] remain -= f[n] return if f[n] > remain: remain -= 1 if f[n - 1] > remain: eat(n - 1) else: total += g[n - 1] remain -= f[n - 1] total += 1 remain -= 1 eat(n - 1) eat(n) print(total)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s149817459
Accepted
p03209
Input is given from Standard Input in the following format: N X
def rec(L, X): S = [0 for i in range(51)] S[0] = 1 for i in range(1, 51): S[i] = 3 + 2 * S[i - 1] dic = {} def f(L, X): if L == 0: return 1 if X < 2: return 0 if (L, X) in dic: return dic[(L, X)] if X < S[L - 1] + 1: dic[(L, X)] = f(L - 1, X - 1) elif X == S[L - 1] + 1: dic[(L, X)] = f(L - 1, S[L - 1]) elif X == S[L - 1] + 2: dic[(L, X)] = f(L - 1, S[L - 1]) + 1 else: dic[(L, X)] = f(L - 1, S[L - 1]) + 1 + f(L - 1, X - 2 - S[L - 1]) return dic[(L, X)] return f(L, X) L, X = map(int, input().split()) print(rec(L, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s456225124
Accepted
p03209
Input is given from Standard Input in the following format: N X
memo = [[0, 1]] def f(n, b, p, k): if b + p == k: return [b, p] if n == 0: return [b, p + 1] newlst1 = [b + 1, p] if newlst1[0] + newlst1[1] == k: return newlst1 newlst2 = [newlst1[0] + memo[n - 1][0], newlst1[1] + memo[n - 1][1]] if newlst2[0] + newlst2[1] == k: return newlst2 if newlst2[0] + newlst2[1] > k: return f(n - 1, newlst1[0], newlst1[1], k) newlst3 = [newlst2[0], newlst2[1] + 1] if newlst3[0] + newlst3[1] == k: return newlst3 newlst4 = [newlst3[0] + memo[n - 1][0], newlst3[1] + memo[n - 1][1]] if newlst4[0] + newlst4[1] == k: return newlst4 if newlst4[0] + newlst4[1] > k: return f(n - 1, newlst3[0], newlst3[1], k) return [newlst4[0] + 1, newlst4[1]] N, K = map(int, input().split()) for i in range(1, N): memo.append([2 * memo[i - 1][0] + 2, 2 * memo[i - 1][1] + 1]) print(f(N, 0, 0, K)[1])
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s551360348
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = map(int, input().split()) layers = [1] patties = [1] for i in range(1, N+1): layer_i = 2 * layers[i-1] + 3 patty_i = 2 * patties[i-1] + 1 layers.append(layer_i) patties.append(patty_i) def f(n, x): if x == 1: return 0 elif 1 < x <= 1 + layers[n-1]: return f(n-1, x-1) elif x == 2 + layers[n-1]: return patties[n-1] + 1 elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]: return patties[n-1] + 1 + f(n-1, x-2-layers[n-1]) elif x == 3 + 2 * layers[n-1]: return 2 * patties[n-1] + 1 print(f(N, X))N, X = map(int, input().split()) layers = [1] patties = [1] for i in range(1, N+1): layer_i = 2 * layers[i-1] + 3 patty_i = 2 * patties[i-1] + 1 layers.append(layer_i) patties.append(patty_i) def f(n, x): if x == 1: return 0 elif 1 < x <= 1 + layers[n-1]: return f(n-1, x-1) elif x == 2 + layers[n-1]: return patties[n-1] + 1 elif 2 + layers[n-1] < x <= 2 + 2 * layers[n-1]: return patties[n-1] + 1 + f(n-1, x-2-layers[n-1]) elif x == 3 + 2 * layers[n-1]: return 2 * patties[n-1] + 1 print(f(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s788433346
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
len_burger_cache = {} def len_burger(n: int): if n == 0: return 1 elif n in len_burger_cache: return len_burger_cache[n] else: tmp = (len_burger(n - 1) * 2) + 3 len_burger_cache[n] = tmp return tmp def gen_burger(n: int): if n == 0: return "P" return "B" + gen_burger(n - 1) + "P" + gen_burger(n - 1) + "B" def culc_eat(n: int, x: int): if n == 0: return 1 if n < len_burger(x): # 次の次元まで計算すればOK return gen_burger(n)[:x].count("P") else: # 次の次元の計算を行う return culc_eat(n - 1, x - 1) # input n, x = input().split() n = int(n) x = int(x) # gen burger print(culc_eat(n, x))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s028555981
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n, x = map(int, input().split()) pate, slice = [1], [1] for _ in range(n + 1): pate.append(2 * pate[-1] + 1) slice.append(2 * slice[-1] + 3) ans = 0 while n > 0: if x >= slice[n - 1] + 2: ans += pate[n - 1] + 1 x -= slice[n - 1] + 2 elif x < slice[n - 1] + 2: x -= 1 n -= 1 print(ans + (x > 0))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s101631934
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
a,b= map(int,input().split()) l = 1 c = [1] d = [1] for i in range(50): c.append(2*c[-1]+3) d.append(2*d[-1]+1) k = 0 while True: if b == 1 && a == 0: k += 1 break elif b==1: break elif c[a] // 2 == b: k += d[a-1] break elif c[a] // 2 > b: a -= 1 b -= 1 elif c[a] // 2 + 1 == b: a -= 1 k += 1 + d[a] break elif c[a] == b: k = d[a] break elif a == 0: k += 1 break else: a -= 1 k += d[a]+1 b -= c[a] + 2 print(k)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s636219996
Accepted
p03209
Input is given from Standard Input in the following format: N X
n, k = map(int, input().split()) pk = [1] pz = [1] for i in range(n): pk.append(pk[-1] * 2 + 1) pz.append(pz[-1] * 2 + 3) ans = 0 for i in range(n, -1, -1): z = pz.pop() ka = pk.pop() if k >= z // 2: ans += ka // 2 k -= z // 2 if k: ans += 1 if k: k -= 1 print(ans)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s267622214
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n, k = map(int, input().split()) pre = "P" for i in range(1, n): cur = "B" + pre + "P" + pre + "B" pre = cur print(cur[:k].count("P"))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s812626367
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = [int(nx) for nx in input().split()] L = "P" for n in range(1, N + 1): L = "B" + L + "P" + L + "B" print(L[0:X].count("P"))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s882387482
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
def getItemCount(L): if L == 0: return 1 return 2 * getItemCount(L - 1) + 3 def getPatsCount(L, eaten): if eaten * 2 - 1 == getItemCount(L): return 2 ** (1 + layer) + 1 return 2 ** (1 + layer) def getAns(layer, eaten): items = getItemCount(layer) patsInLayer = getPatsCount(layer, eaten) if layer == 0 and eaten == 1: return 1 if eaten == items: return patsInLayer elif eaten < items: return getAns(layer - 1, eaten - 1) else: return patsInLayer + getAns(layer - 1, eaten - 1) layer, eaten = [int(x) for x in input().split()] print(getAns(layer, eaten)) """ tPats = 0 if layer != 0: while 1: items = getItemCount(layer) patsInLayer = getPatsCount(layer) if eaten == items: if layer != 0: tPats += patsInLayer eaten -= items break elif eaten < items: eaten -= 1 elif eaten > items: tPats += patsInLayer + 1 eaten -= items layer -= 1 if layer < 0: break else: if eaten == 1: print(1) else: print(0) print(tPats) """
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s700593274
Wrong Answer
p03209
Input is given from Standard Input in the following format: N X
n, x = map(int, input().split()) len_b = 2 ** (n + 2) - 3 p = [2 ** (i + 1) - 1 for i in range(n + 1)] start = 1 end = len_b center = (end + 1) // 2 count1 = 0 count2 = n - 1 while True: if x == start: break elif x == center: count1 += p[count2] + 1 break elif x == end: count1 += p[count2] * 2 + 1 break elif x < center: start = start + 1 end = center - 1 center = (start + end + 1) // 2 count2 -= 1 else: start = center + 1 end = end - 1 center = (start + end + 1) // 2 count1 += p[count2] count2 -= 1 print(count1)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s335694714
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n, x = map(int, input().split()) l = [0]*(n+1) l[0] = 1 for i in range(1,n+1): l[i] = l[i-1]*2+3 p = [0]*(n+1) p[0] = 1 for i in range(1,n+1): p[i] = p[i-1]*2+1 ans = 0 def bts(a,b): global ans if b = 1: ans += 0 elif 1 < b < l[a-1]+1: bts(a-1,b-1) elif b == l[a-1]+1: ans += p[a-1] elif b == l[a-1]+2: ans += p[a-1]+1 elif l[a-1]+2 < b < l[a-1]*2+2: ans += p[a-1]+1 bts(a-1,b-2-l[a-1]) else: ans += p[a-1]+2 bts(n,x) print(ans)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s517309472
Wrong Answer
p03209
Input is given from Standard Input in the following format: N X
def bread_cnt(lev): return 2 ** (lev + 1) - 2 def patty_cnt(lev): return 2 ** (lev + 1) - 1 def burger_cnt(lev): return 2 ** (lev + 2) - 3 def solve(n, x): return _solve(n, x, 0) def _solve(n, x, p): total_s = burger_cnt(n) if x == 1: return p elif 1 < x and x <= (total_s + 1) // 2: reach_mid = 1 if x == (total_s + 1) // 2 else 0 return _solve(n - 1, x - 1 - reach_mid, p + reach_mid) elif (total_s + 1) // 2 < x and x < total_s: return _solve(n - 1, x - 2 - burger_cnt(n - 1), p + 1 + patty_cnt(n - 1)) elif x == total_s: return p + patty_cnt(n) n, x = map(int, input().split(" ")) print(solve(n, x))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s707143337
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N,X = map(int,input().split()) if N == 0: print(1) exit() # a:バンの数 b:パティの数 a,b = [1],[1] for i in range(N): a.append(2*a[i] + 3) b.append(2*b[i] + 1) def f(N,X): if X == 1: return 0 elif 1 < X <= a[N-1] + 1: return f(N-1,X-1) elif X == a[N-1] + 2: return b[N-1] + 1 elif a[N-1] + 2 < X <= 2*a[N-1] + 2: return b[N-1] + 1 + f(N-1,X-(a[N-1]+2)) elif X = 2*a[N-1] + 3: return 2*b[N-1] + 1 ans = f(N,X) print(ans)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s819150939
Accepted
p03209
Input is given from Standard Input in the following format: N X
n, x = (list)(map(int, input().split())) patty = [] patty.append(1) lay = [] lay.append(1) for i in range(n): patty.append(patty[i] * 2 + 1) lay.append(lay[i] * 2 + 3) # print(patty) # print(lay) c = 0 for i in reversed(range(n + 1)): # print("i,x,c=", i, x, c) if x == lay[i]: # print("i") c += patty[i] break elif x == lay[i - 1] + 2: # ちょうど半分の時 # print("elif1") c += patty[i - 1] + 1 break elif x < lay[i - 1] + 2: # 半分より小さい時 # print("elif2") x = x - 1 else: # 半分より大きい時 # print("el") x = x - 2 - lay[i - 1] c += patty[i - 1] + 1 print(c)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s466572620
Accepted
p03209
Input is given from Standard Input in the following format: N X
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline N, X = map(int, input().split()) numP_N = [0] * N numPB_N = [0] * N numP_N[0] = 3 numPB_N[0] = 5 for i in range(1, N): numP_N[i] = numP_N[i - 1] * 2 + 1 numPB_N[i] = numPB_N[i - 1] * 2 + 3 def rec(n, x): if n == 1: ans_1 = [0, 0, 1, 2, 3, 3] return ans_1[x] if x == numPB_N[n - 1]: return numP_N[n - 1] elif x > numPB_N[n - 2] + 2: return numP_N[n - 2] + 1 + rec(n - 1, x - numPB_N[n - 2] - 2) elif x == numPB_N[n - 2] + 2: return numP_N[n - 2] + 1 elif x == numPB_N[n - 2] + 1: return numP_N[n - 2] elif x < numPB_N[n - 2] + 1: return rec(n - 1, x - 1) print(rec(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s540328678
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
def getItems(layerCount): if layerCount == 0: return 1 return 2*getItems(layerCount-1) + 3 def getPats(layerCount): return 2**(layerCount + 1) - 1 def patEaten(layer, toEat): pattyCount = 0 if layer == 1: burger = "BPPPB" for x in range(toEat): if burger[x] == "P": pattyCount += 1 return pattyCount elif layer == 0: if toEat == 1: return 1 else: return 0 else: items = getItems(layer) if toEat == items: pattyCount += patEaten(layer, toEat) toEat = 0 return pattyCount elif toEat < 2+getItems(layer-1): if items + 1 == 2* toEat: toEat-=2 return 1 + patEaten(layer - 1, toEat) toEat -= 1 return patEaten(layer - 1, toEat) else: toEat -= (1+1+getItems(layer-1)) pattyCount += 1 + getPats(layer-1) return pattyCount + patEaten(layer-1, toEat) #i, j = [int(x) for x in input().split()] print(patEaten(2,13)) #print(getItems(2))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s401389547
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
using System; using System; using System.Collections.Generic; using System.Linq; class Solver5 { /* * * https://atcoder.jp/contests/abc115/tasks/abc115_d * */ public void Solve5() { var nx = u.readLongArrayBySplit(); var n = nx[0]; var x = nx[1]; long ans = 0; while (true) { var thk = new long[5]{ 1, (long)Math.Pow(2,n + 1) - 3, 1, (long)Math.Pow(2, n + 1) - 3, 1 }; var pc = new long[5] { 0, (long)Math.Pow(2, n ) - 1 , 1, (long)Math.Pow(2, n )- 1, 0 }; for (int i = 0; i < 5; i++) { if (x > thk[i]) { x -= thk[i]; ans += pc[i]; } else if (x < thk[i]) { n--; break; } else { ans += pc[i]; Console.WriteLine(ans.ToString()); return; } } } } static void Main() { var solver = new Solver5(); solver.Solve5(); } } static class u { public static long[] readLongArrayBySplit() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); } }
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s074675707
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = map(int, input().split()) a,p=[1],[1] for i in range(N): a.append(a[i] * 2 + 3) p.append(p[i] * 2 + 1) deff(N,X): #X<=0やX>a_Nを許容し解説本文から簡略化 if N == 0: return 0 if X <= 0 else 1 elif X <= 1 + a[N-1]: return f(N-1, X-1) else: return p[N-1] + 1 + f(N-1, X-2-a[N-1]) print(f(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s176338332
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = map(int, input().split()) a,p=[1],[1] for i in range(N): a.append(a[i] * 2 + 3) p.append(p[i] * 2 + 1) deff(N,X): #X<=0やX>a_Nを許容し解説本文から簡略化 if N == 0: return 0 if X <= 0 else 1 elif X <= 1 + a[N-1]: return f(N-1, X-1) else: return p[N-1] + 1 + f(N-1, X-2-a[N-1]) print(f(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s811002823
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = map(int, input().split()) a, p = [1], [1] for i in range(N): a.append(a[i] * 2 + 3) p.append(p[i] * 2 + 1) def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化 if N == 0: return 0 if X <= 0 else 1 elif X <= 1 + a[N-1]: return f(N-1, X-1) elif X == 2 + a[N-1]: return p[N-1] + 1 elif X == 3 + 2 * a[N-1]: return 2 * p[N-1] + 1 else: return p[N-1] + 1 + f(N-1, X-2-a[N-1]) print(f(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s426245636
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = map(int, input().split()) a, p = [1], [1] for i in range(N): a.append(a[i] * 2 + 3) p.append(p[i] * 2 + 1) def f(N, X): # X <= 0 や X > a_N を許容し解説本文から簡略化 if N == 0: return 0 if X <= 0 else 1 elif X <= 1 + a[N-1]: return f(N-1, X-1) else: return p[N-1] + 1 + f(N-1, X-2-a[N-1]) print(f(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s378823504
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = map(int, input().split()) a, p = [1], [1] for i in range(N): a.append(a[i] * 2 + 3) p.append(p[i] * 2 + 1) def f(N, X): if N == 0: return 0 if X <= 0 else 1 elif X <= 1 + a[N-1]: return f(N-1, X-1) else: return p[N-1] + 1 + f(N-1, X-2-a[N-1]) print(f(N, X))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s994341033
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
ef dfs (i,depth): if i >= depth-1: return 'bpppb' else: s = dfs(i+1,depth) return 'b' + s + 'p' + s + 'b' n,x = map(int,input().split()) p = 2**(n+1)-1 b = 2**(n+1)-2 a = p + b #print(p,a,b) pos = a / x #print(pos) #print(p / pos) r = dfs(0,n) print(r.count('p',0,x))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s273708992
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n,x=map(int,input().split()) a=[1] p=[1] for i in range(n-1): a.append(a[i]*2+3) p.append(p[i]*2+1) def f(n,x): if n==0 and x==1: return 1 elif n==0: return 0 elif x<=1: return 0 elif x<=1+a[n-]: return f(n-1,x-1) else: return p[n-1]+1+f(n-1,x-2-a[n-1]) print(f(n,x))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s058309087
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n,x = [int(x) for x in input().split()] def b(z): if z != 0: return b(z-1)*2+1 else: return 1 def f(x): while x<=3: def c(y): a = 0 y -= 2 while y<=5: y -= 2 y -= 3 a += 3 return a a = b(n) print(c(x))
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s399803839
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
n,x=map(int,input().split()) l=[0] for i in range(n+1): l.append(2**(i+1)-1) m=[0] for i in range(n+1): m.append(2**(i+2)-3) c=0 for i in range(n,-1,-1): if x<2**(i+1)-1: x-=1 elif x==2**(i+1)-1: c+=l[i]+1 x=0 elif x>2**(i+1)-1: c+=l[i]+1 elif x==m[i+1]: x-=1 x=x-(2**(i+1)-1) print(c)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s398807778
Wrong Answer
p03209
Input is given from Standard Input in the following format: N X
n, k = map(int, input().split()) cnt = [0, 1] tmp = [[0, 1]] for i in range(n): tmp.append([cnt[0] * 2 + 2, cnt[1] * 2 + 1]) cnt[0] = cnt[0] * 2 + 2 cnt[1] = cnt[1] * 2 + 1 """ 半分に区切ってジャスト半分なら前の分+1を出力 大きければ前の分+1を足して次 小さければ数える数を1小さくしてレベルを下げる """ num = 0 for i in range(n, 0, -1): if (sum(tmp[i]) + 1) / 2 == k: num += tmp[i - 1][1] + 1 break elif (sum(tmp[i]) - 1) / 2 == k: num += tmp[i - 1][1] break elif sum(tmp[i]) == k or sum(tmp[i]) == k: num += tmp[i][1] break elif (sum(tmp[i]) - 1) / 2 < k: num += tmp[i - 1][1] + 1 k = k - sum(tmp[i - 1]) - 2 elif (sum(tmp[i]) - 1) / 2 > k: k = k - 1 print(num)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger. * * *
s231095857
Runtime Error
p03209
Input is given from Standard Input in the following format: N X
N, X = map(int, input().split()) # (i)XがLバーガーの半分より上かどうか?を計算 # (ii-i)上の場合: sumに下半分のパティの数を加算。下半分を切り捨てて、L-1バーガに対して、 # 再度X = (X-(Lバーガーの半分の枚数))で(i)から計算 # (ii-ii)下の場合: 上半分を切り捨てて、L-1バーガに対して再度X = (X-(Lバーガーの半分の枚数))で(i)から計算 patty_num_map = {} size_map = {} patty_num_map[0] = 1 size_map[0] = 1 for i in range(1, 51): patty_num_map[i] = 1 + patty_num_map[i - 1] * 2 size_map[i] = 3 + size_map[i - 1] * 2 L = N patty_sum = 0 L1_map = {} L1_map[0] = 0 L1_map[1] = 0 L1_map[2] = 1 L1_map[3] = 2 L1_map[4] = 3 L1_map[5] = 3 while True: half = size_map[L] // 2 + 1 if L < 2: patty_sum += L1_map[X] break if X > half: patty_sum += patty_num_map[L - 1] + 1 # 真ん中のpattyの分 # X -= half+1 # 一番上のバティの分 X -= half L -= 1 elif X < half: X -= 1 # 一番下のバンの分 L -= 1 else: # ちょうど半分 patty_sum += patty_num_map[L - 1] + 1 break print(patty_sum)
Statement In some other world, today is Christmas. Mr. Takaha decides to make a multi-dimensional burger in his party. A _level- L burger_ (L is an integer greater than or equal to 0) is the following thing: * A level-0 burger is a patty. * A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom. For example, a level-1 burger and a level-2 burger look like `BPPPB` and `BBPPPBPBPPPBB` (rotated 90 degrees), where `B` and `P` stands for a bun and a patty. The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?
[{"input": "2 7", "output": "4\n \n\nThere are 4 patties in the bottom-most 7 layers of a level-2 burger\n(`BBPPPBPBPPPBB`).\n\n* * *"}, {"input": "1 1", "output": "0\n \n\nThe bottom-most layer of a level-1 burger is a bun.\n\n* * *"}, {"input": "50 4321098765432109", "output": "2160549382716056\n \n\nA level-50 burger is rather thick, to the extent that the number of its layers\ndoes not fit into a 32-bit integer."}]
If $p$ is in $s$, print Yes in a line, otherwise No.
s328879131
Accepted
p02418
In the first line, the text $s$ is given. In the second line, the pattern $p$ is given.
s = input().rstrip() p = input().rstrip() line = s + s print("Yes") if p in line else print("No")
Ring Write a program which finds a pattern $p$ in a ring shaped text $s$. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_ITP1_8_D)
[{"input": "vanceknowledgetoad\n advance", "output": "Yes"}, {"input": "vanceknowledgetoad\n advanced", "output": "No"}]