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 K-th lexicographically smallest substring of K. * * *
s694697737
Accepted
p03353
Input is given from Standard Input in the following format: s K
s = input() k = int(input()) n = len(s) if n == 1: print(s) elif n == 2: l2 = sorted(list(set([s[i : i + 2] for i in range(n - 1)]))) print(l2[0]) elif n == 3: l1 = list(set(s)) l2 = list(set([s[i : i + 2] for i in range(n - 1)])) l3 = list(set([s[i : i + 3] for i in range(n - 2)])) out = sorted(l1 + l2 + l3) print(out[k - 1]) elif n == 4: l1 = list(set(s)) l2 = list(set([s[i : i + 2] for i in range(n - 1)])) l3 = list(set([s[i : i + 3] for i in range(n - 2)])) l4 = list(set([s[i : i + 4] for i in range(n - 3)])) out = sorted(l1 + l2 + l3 + l4) print(out[k - 1]) else: l1 = list(set(s)) l2 = list(set([s[i : i + 2] for i in range(n - 1)])) l3 = list(set([s[i : i + 3] for i in range(n - 2)])) l4 = list(set([s[i : i + 4] for i in range(n - 3)])) l5 = list(set([s[i : i + 5] for i in range(n - 4)])) out = sorted(l1 + l2 + l3 + l4 + l5) print(out[k - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s986002822
Runtime Error
p03353
Input is given from Standard Input in the following format: s K
s = input() K = int(input()) str_list = list(s) str_list2 = list(s) str_list2 = list(set(str_list2)) str_list2.sort() a = str_list2[0] n = str_list.count(a) if K == 1: print(a) else: K -= 1 indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 1] if len(indexes) > 0: sub_list = [s[i : i + 2] for i in indexes] indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 2] if len(indexes) > 0: sub_list += [s[i : i + 3] for i in indexes] indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 3] if len(indexes) > 0: sub_list += [s[i : i + 4] for i in indexes] indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 4] if len(indexes) > 0: sub_list += [s[i : i + 5] for i in indexes] sub_list = list(set(sub_list)) sub_list.sort() if len(sub_list) >= K: print(sub_list[K - 1]) else: K -= len(sub_list) a = str_list[1] if K == 1: print(a) else: K -= 1 indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 1] if len(indexes) > 0: sub_list = [s[i : i + 2] for i in indexes] indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 2] if len(indexes) > 0: sub_list += [s[i : i + 3] for i in indexes] indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 3] if len(indexes) > 0: sub_list += [s[i : i + 4] for i in indexes] indexes = [i for i, x in enumerate(str_list) if x == a and i < len(s) - 4] sub_list = list(set(sub_list)) sub_list.sort() if len(sub_list) >= K: print(sub_list[K - 1]) else: K -= len(sub_list) a = str_list[2] if K == 1: print(a) else: K -= 1 indexes = [ i for i, x in enumerate(str_list) if x == a and i < len(s) - 1 ] if len(indexes) > 0: sub_list = [s[i : i + 2] for i in indexes] indexes = [ i for i, x in enumerate(str_list) if x == a and i < len(s) - 2 ] if len(indexes) > 0: sub_list += [s[i : i + 3] for i in indexes] indexes = [ i for i, x in enumerate(str_list) if x == a and i < len(s) - 3 ] if len(indexes) > 0: sub_list += [s[i : i + 4] for i in indexes] indexes = [ i for i, x in enumerate(str_list) if x == a and i < len(s) - 4 ] sub_list = list(set(sub_list)) sub_list.sort() print(sub_list[K - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s312770494
Accepted
p03353
Input is given from Standard Input in the following format: s K
s = str(input()) K = int(input()) S = set() anslength = K while 0 < anslength: for i in range(0, len(s) - anslength + 1): S.add(s[i : i + anslength]) anslength -= 1 LS = list(S) LS.sort() print(LS[K - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s069549927
Runtime Error
p03353
Input is given from Standard Input in the following format: s K
a = input() p = int(input()) k = [] for i in range(len(a)): for j in range(i + 1, min(i + 6, len(a) - 1)): k.append(a[i:j]) k = set(k) k = list(k) k.sort() # print(k) print(k[p - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s943639365
Wrong Answer
p03353
Input is given from Standard Input in the following format: s K
S = input() K = int(input()) L = [""] for s in range(len(S)): for e in range(s, len(S)): # print(S[s:e+1]) if len(L) > K: if S[s : e + 1] > L[K]: break if S[s : e + 1] not in L: if len(L) <= K: L.append(S[s : e + 1]) else: L.append(S[s : e + 1]) L.sort() L = L[: K + 1] # print(L) print(L[-1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s921757263
Accepted
p03353
Input is given from Standard Input in the following format: s K
from collections import deque s = list(input()) K = int(input()) # max(K)=5でaaaaaはa,aa,aaa,aaaa,aaaaaの順 # よって5文字まで取れば良い d = deque() for i in range(len(s)): d.append(s[i]) comp = [] # print(d) for i in range(len(s)): buf = deque() for j in range(len(d)): v = d.popleft() buf.append(v) if j < 5: comp.append("".join(buf)) d = deque() for j in range(len(buf)): d.append(buf[j]) d.popleft() comp = list(set(comp)) comp.sort() print(comp[K - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s590419607
Accepted
p03353
Input is given from Standard Input in the following format: s K
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# S = S() K = I() N = len(S) bag = set() for i in range(N): for j in range(i + 1, N + 1): if S[i:j] not in bag: bag.add(S[i:j]) sortbag = sorted(list(bag)) if len(sortbag) == 6: if S[i:j] not in sortbag[:-1]: bag = set(sortbag[:-1]) break bag = set(sortbag[:-1]) print(sorted(bag)[K - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s250058511
Accepted
p03353
Input is given from Standard Input in the following format: s K
import sys sys.setrecursionlimit(2147483647) INF = float("inf") MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() class SuffixArray(object): def __init__(self, s): self.__s = s self.__n = len(s) self.__suffix_array() self.__lcp_array() self.__sparse_table() def __suffix_array(self): s = self.__s n = self.__n sa = list(range(n)) rank = [ord(s[i]) for i in range(n)] tmp = [0] * n k = 1 cmp_key = lambda i: (rank[i], rank[i + k] if i + k < n else -1) while k <= n: sa.sort(key=cmp_key) tmp[sa[0]] = 0 for i in range(1, n): tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_key(sa[i - 1]) < cmp_key(sa[i])) rank = tmp[:] k <<= 1 self.__sa = sa self.__rank = rank def __lcp_array(self): s = self.__s n = self.__n sa = self.__sa rank = self.__rank lcp = [0] * n h = 0 for i in range(n): j = sa[rank[i] - 1] if h > 0: h -= 1 if rank[i] == 0: continue while j + h < n and i + h < n and s[j + h] == s[i + h]: h += 1 lcp[rank[i]] = h self.__lcp = lcp def __sparse_table(self): n = self.__n logn = max(1, (n - 1).bit_length()) table = [[0] * n for _ in range(logn)] table[0] = self.__lcp[:] from itertools import product for i, k in product(range(1, logn), range(n)): if k + (1 << (i - 1)) >= n: table[i][k] = table[i - 1][k] else: table[i][k] = min(table[i - 1][k], table[i - 1][k + (1 << (i - 1))]) self.__table = table @property def suffix(self): return self.__sa def lcp(self, a, b): if a == b: return self.__n - a l, r = self.__rank[a], self.__rank[b] l, r = min(l, r) + 1, max(l, r) + 1 i = max(0, (r - l - 1).bit_length() - 1) table = self.__table return min(table[i][l], table[i][r - (1 << i)]) def resolve(): S = input() n = len(S) k = int(input()) sa = SuffixArray(S) D = set() for i in sa.suffix: for j in range(i + 1, n + 1): D.add(S[i:j]) if len(D) == k: print(sorted(D)[-1]) return resolve()
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s217058778
Accepted
p03353
Input is given from Standard Input in the following format: s K
s, n = input(), int(input()) ss = [s[i : i + j + 1] for i in range(len(s)) for j in range(5)] print(sorted(set(ss), key=sorted(ss).index)[n - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s655655496
Wrong Answer
p03353
Input is given from Standard Input in the following format: s K
s = input() K = int(input()) answers = [] S = [a for a in s] N = len(S) for a in range(N): number = 0 while a + number <= N and number <= K: z = S[a : a + number] moji = "" for y in z: moji += y answers.append(moji) number += 1 kotae = [] for a in answers: if a in kotae: pass else: kotae.append(a) kotae = sorted(kotae) print(kotae) print(kotae[K - 1])
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
Print the K-th lexicographically smallest substring of K. * * *
s218711369
Accepted
p03353
Input is given from Standard Input in the following format: s K
s = input() k = int(input()) t = len(s) u = [] u2 = [] """for i in range(t): u.append([])""" for i in range(5): u.append([]) for j in range(5): for i in range(t): u[j].append([]) for i in range(t): u2.append([]) for j in range(5): for i in range(t): if j == 0: if s[i] not in u2[j]: u[j][i].append(s[i]) u2[j].append(s[i]) u[j][i].append(i) elif j == 1: if i + 1 < t: if s[i] + s[i + 1] not in u2[j] and s[i] + s[i + 1] not in u2[j - 1]: for r in range(j + 1): if u[r][i] == []: u[r][i].append(s[i] + s[i + 1]) u2[j].append(s[i] + s[i + 1]) u[r][i].append(i) break elif j == 2: if i + 2 < t: if ( s[i] + s[i + 1] + s[i + 2] not in u2[j] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 1] and s[i] + s[i + 1] + s[i + 2] not in u2[j - 2] ): for r in range(j + 1): if u[r][i] == []: u[r][i].append(s[i] + s[i + 1] + s[i + 2]) u2[j].append(s[i] + s[i + 1] + s[i + 2]) u[r][i].append(i) break elif j == 3: if i + 3 < t: if ( s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 1] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 2] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] not in u2[j - 3] ): for r in range(j + 1): if u[r][i] == []: u[r][i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3]) u2[j].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3]) u[r][i].append(i) break elif j == 4: if i + 4 < t: if ( s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 1] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 2] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 3] and s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] not in u2[j - 4] ): for r in range(j + 1): if u[r][i] == []: u[r][i].append( s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] ) u2[j].append( s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] ) u[r][i].append(i) break """for i in range(t): for j in range(k): if j == 0: u[i].append(s[i]) elif j == 1: u[i].append(s[i] + s[i + 1]) elif j == 2: u[i].append(s[i] + s[i + 1] + s[i + 2]) elif j == 3: u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3]) elif j == 4: u[i].append(s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4])""" p = [0] * t n = "z" * 10000 m = -1 l = -1 for i in range(5): for j in range(t + 5): if j < len(u[0]): if u[0][j] != []: if u[0][j][0] <= n: n = u[0][j][0] m = u[0][j][1] l = j # sorted(u[0]) if i + 1 == k: print(n) # print(u[0][0].pop(0)) exit() else: u[0].append(u[1 + p[m]][m]) p[m] += 1 u[0][l].pop(0) u[0][l].pop(0) n = "z" * 10000 m = -1 l = -1
Statement You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
[{"input": "aba\n 4", "output": "b\n \n\ns has five substrings: `a`, `b`, `ab`, `ba` and `aba`. Among them, we should\nprint the fourth smallest one, `b`. Note that we do not count `a` twice.\n\n* * *"}, {"input": "atcoderandatcodeer\n 5", "output": "andat\n \n\n* * *"}, {"input": "z\n 1", "output": "z"}]
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`. Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice. * * *
s036610071
Wrong Answer
p02692
Input is given from Standard Input in the following format: N A B C s_1 s_2 : s_N
l = list(map(int, input().split())) if l.count(0) >= 2: print("No") else: print("Yes")
Statement There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
[{"input": "2 1 3 0\n AB\n AC", "output": "Yes\n A\n C\n \n\nYou can successfully make two choices, as follows:\n\n * In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.\n * In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.\n\n* * *"}, {"input": "3 1 0 0\n AB\n BC\n AB", "output": "No\n \n\n* * *"}, {"input": "1 0 9 0\n AC", "output": "No\n \n\n* * *"}, {"input": "8 6 9 1\n AC\n BC\n AB\n BC\n AC\n BC\n AB\n AB", "output": "Yes\n C\n B\n B\n C\n C\n B\n A\n A"}]
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`. Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice. * * *
s435200937
Wrong Answer
p02692
Input is given from Standard Input in the following format: N A B C s_1 s_2 : s_N
N, A, B, C = map(int, input().split()) s = [] for i in range(N): s.append(input()) print("No")
Statement There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
[{"input": "2 1 3 0\n AB\n AC", "output": "Yes\n A\n C\n \n\nYou can successfully make two choices, as follows:\n\n * In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.\n * In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.\n\n* * *"}, {"input": "3 1 0 0\n AB\n BC\n AB", "output": "No\n \n\n* * *"}, {"input": "1 0 9 0\n AC", "output": "No\n \n\n* * *"}, {"input": "8 6 9 1\n AC\n BC\n AB\n BC\n AC\n BC\n AB\n AB", "output": "Yes\n C\n B\n B\n C\n C\n B\n A\n A"}]
If it is possible to make N choices under the condition, print `Yes`; otherwise, print `No`. Also, in the former case, show one such way to make the choices in the subsequent N lines. The (i+1)-th line should contain the name of the variable (`A`, `B`, or `C`) to which you add 1 in the i-th choice. * * *
s446955502
Runtime Error
p02692
Input is given from Standard Input in the following format: N A B C s_1 s_2 : s_N
n, a, b, c = map(int, input().split()) ref = [a, b, c, []] for i in range(n): nxt = [] roun = [] s = input() for l in ref: if s == "AB": if l[1] > 0 and ([l[0] + 1, l[1] - 1, l[2], l[3].append("A")] not in roun): nxt.append([l[0] + 1, l[1] - 1, l[2], l[3].append("A")]) roun.append([l[0] + 1, l[1] - 1, l[2], l[3].append("A")]) if l[0] > 0 and ([l[0] - 1, l[1] + 1, l[2], l[3].append("B")] not in roun): nxt.append([l[0] - 1, l[1] + 1, l[2], l[3].append("B")]) roun.append([l[0] - 1, l[1] + 1, l[2], l[3].append("B")]) elif s == "AC": if l[2] > 0 and ([l[0] + 1, l[1], l[2] - 1, l[3].append("A")] not in roun): nxt.append([l[0] + 1, l[1], l[2] - 1, l[3].append("A")]) roun.append([l[0] + 1, l[1], l[2] - 1, l[3].append("A")]) if l[0] > 0 and ([l[0] - 1, l[1], l[2] + 1, l[3].append("C")] not in roun): nxt.append([l[0] - 1, l[1], l[2] + 1, l[3].append("C")]) roun.append([l[0] - 1, l[1], l[2] + 1, l[3].append("C")]) elif s == "BC": if l[2] > 0 and ([l[0], l[1] + 1, l[2] - 1, l[3].append("B")] not in roun): nxt.append([l[0], l[1] + 1, l[2] - 1, l[3].append("B")]) roun.append([l[0], l[1] + 1, l[2] - 1, l[3].append("B")]) if l[1] > 0 and ([l[0], l[1] - 1, l[2] + 1, l[3].append("C")] not in roun): nxt.append([l[0], l[1] - 1, l[2] + 1, l[3].append("C")]) roun.append([l[0], l[1] - 1, l[2] + 1, l[3].append("C")]) else: pass ref = nxt if ref != []: for i in ref[0][3]: print(i)
Statement There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or C then subtract 1 from the other; if s_i is `BC`, you must add 1 to B or C then subtract 1 from the other. After each choice, none of A, B, and C should be negative. Determine whether it is possible to make N choices under this condition. If it is possible, also give one such way to make the choices.
[{"input": "2 1 3 0\n AB\n AC", "output": "Yes\n A\n C\n \n\nYou can successfully make two choices, as follows:\n\n * In the first choice, add 1 to A and subtract 1 from B. A becomes 2, and B becomes 2.\n * In the second choice, add 1 to C and subtract 1 from A. C becomes 1, and A becomes 1.\n\n* * *"}, {"input": "3 1 0 0\n AB\n BC\n AB", "output": "No\n \n\n* * *"}, {"input": "1 0 9 0\n AC", "output": "No\n \n\n* * *"}, {"input": "8 6 9 1\n AC\n BC\n AB\n BC\n AC\n BC\n AB\n AB", "output": "Yes\n C\n B\n B\n C\n C\n B\n A\n A"}]
Output "1" if the new reservation temporally overlaps with any of the existing ones, or "0" otherwise.
s696857188
Accepted
p00355
The input is given in the following format. a b N s_1 f_1 s_2 f_2 : s_N f_N The first line provides new reservation information, i.e., the start time a and end time b (0 ≤ a < b ≤ 1000) in integers. The second line specifies the number of existing reservations N (0 ≤ N ≤ 100). Subsequent N lines provide temporal information for the i-th reservation: start time s_i and end time f_i (0 ≤ s_i < f_i ≤ 1000) in integers. No two existing reservations overlap.
# N = int(sys.stdin.readline()) # INF = float("inf") import sys # N,M = map(int,sys.stdin.readline().split()) # abx = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(M)) # multi line with multi param # imos=[[0]*(N) for _ in range(N)] # for a,b,x in abx: # imos[a-1][b-1] += 1 # if a+x-1+1 < N and b+x-1+1 < N: # imos[a+x-1+1][b+x-1+1] -= 1 # imos[a+x-1+1][b-1+1] -= 1 # print(imos) # for r in range(N): # for c in range(N): # imos[r][c] += imos[r-1][c-1]#+imos[r][c-1] # print(imos) a, b = map(int, sys.stdin.readline().split()) N = int(sys.stdin.readline()) sf = tuple( tuple(map(int, sys.stdin.readline().rstrip().split())) for _ in range(N) ) # multi line with multi param M = 1000 imos = [0] * (M + 1) imos[a] += 1 imos[b] -= 1 for s, f in sf: imos[s] += 1 imos[f] -= 1 for i in range(M): imos[i + 1] += imos[i] for i in range(a, b + 1): if imos[i] > 1: print("1") exit() print("0")
Reservation System The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap each other. Write a program to report if a new reservation overlaps with any of the existing reservations. Note that the coincidence of start and end times is not considered to constitute an overlap. All the temporal data is given as the elapsed time from the moment at which the L system starts operation.
[{"input": "5 7\n 3\n 1 4\n 4 5\n 7 10", "output": "0"}, {"input": "3 7\n 3\n 7 10\n 1 4\n 4 5", "output": "1"}]
For each query, pinrt "1" if the given nodes belong to the same strongly connected component, "0" otherwise.
s190711460
Accepted
p02368
A directed graph G(V, E) and a sequence of queries where each query contains a pair of nodes u and v. |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 Q u0 v0 u1 v1 : uQ-1 vQ-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target nodes of i-th edge (directed). ui and vi represent a pair of nodes given as the i-th query.
# 蟻本参照 import sys sys.setrecursionlimit(200000) input = sys.stdin.readline ##redline,recursionlimit変更 v, e = map(int, input().split()) E = [[] for _ in range(v)] revE = [[] for _ in range(v)] used = [0] * v kaeri = [] topo = [-1 for _ in range(v)] for _ in range(e): s, t = map(int, input().split()) E[s].append(t) revE[t].append(s) q = int(input()) ############ def dfs(v): used[v] = 1 for u in E[v]: if not used[u]: dfs(u) kaeri.append(v) def re_dfs(v, k): used[v] = 1 topo[v] = k for u in revE[v]: if not used[u]: re_dfs(u, k) ### for u in range(v): if not used[u]: dfs(u) kaeri.reverse() used = [0] * v k = 0 for u in kaeri: if not used[u]: k += 1 re_dfs(u, k) # print(topo) for _ in range(q): u, v = map(int, input().split()) if topo[u] == topo[v]: print(1) else: print(0)
Strongly Connected Components A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable.
[{"input": "5 6\n 0 1\n 1 0\n 1 2\n 2 4\n 4 3\n 3 2\n 4\n 0 1\n 0 3\n 2 3\n 3 4", "output": "1\n 0\n 1\n 1"}]
For each query, pinrt "1" if the given nodes belong to the same strongly connected component, "0" otherwise.
s761884415
Accepted
p02368
A directed graph G(V, E) and a sequence of queries where each query contains a pair of nodes u and v. |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 Q u0 v0 u1 v1 : uQ-1 vQ-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target nodes of i-th edge (directed). ui and vi represent a pair of nodes given as the i-th query.
def strongly_connected_components(E): N = len(E) postorder = [] visited = set([]) def reverse_edge(E): result = [[] for _ in range(len(E))] for v, neighbor in enumerate(E): for n in neighbor: result[n].append(v) return result def dfs(E, s): postorder = [] # a dfs postordering of each vertex nonlocal visited stack = [(s, -1, 0)] # (vertex, parent, status) while stack: v, p, st = stack.pop() if st == 0 and v not in visited: # visited v for the first time visited |= {v} n_children = 0 for u in E[v]: if u in visited: continue if n_children == 0: stack += [(v, p, 2), (u, v, 0)] n_children += 1 else: stack += [(v, p, 1), (u, v, 0)] n_children += 1 if n_children == 0: # v is a leaf postorder.append(v) elif st == 0 and v in visited: # the edge (v, p) is a back edge continue elif st == 1: # now searching continue else: # search finished postorder.append(v) return postorder for v in range(N): if v not in visited: order = dfs(E, v) postorder += order reverse_E = reverse_edge(E) scc = [N] * N visited = set([]) k = 0 while postorder: v = postorder.pop() if scc[v] == N: order = dfs(reverse_E, v) for u in order: scc[u] = k k += 1 return scc N, M = map(int, input().split()) E = [[] for _ in range(N)] for _ in range(M): s, t = map(int, input().split()) E[s].append(t) scc = strongly_connected_components(E) Q = int(input()) for _ in range(Q): u, v = map(int, input().split()) print(1 if scc[u] == scc[v] else 0)
Strongly Connected Components A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable.
[{"input": "5 6\n 0 1\n 1 0\n 1 2\n 2 4\n 4 3\n 3 2\n 4\n 0 1\n 0 3\n 2 3\n 3 4", "output": "1\n 0\n 1\n 1"}]
For each query, pinrt "1" if the given nodes belong to the same strongly connected component, "0" otherwise.
s418836257
Accepted
p02368
A directed graph G(V, E) and a sequence of queries where each query contains a pair of nodes u and v. |V| |E| s0 t0 s1 t1 : s|E|-1 t|E|-1 Q u0 v0 u1 v1 : uQ-1 vQ-1 |V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target nodes of i-th edge (directed). ui and vi represent a pair of nodes given as the i-th query.
import sys sys.setrecursionlimit(int(1e6)) n, m = map(int, input().split()) graph = {} graph_rev = {} for i in range(m): s, t = map(int, input().split()) if s not in graph: graph[s] = set() graph[s].add(t) if t not in graph_rev: graph_rev[t] = set() graph_rev[t].add(s) order = [] visited = set() def dfs1(i): visited.add(i) if i in graph: for t in graph[i]: if t not in visited: dfs1(t) order.append(i) for i in range(n): if i not in visited: dfs1(i) group = [-1] * n visited.clear() def dfs2(i, g): visited.add(i) group[i] = g if i in graph_rev: for t in graph_rev[i]: if t not in visited: dfs2(t, g) group_id = 0 while len(order) > 0: v = order.pop() if v in visited: continue dfs2(v, group_id) group_id += 1 q = int(input()) ans = [] for i in range(q): u, v = map(int, input().split()) ans.append(1) if group[u] == group[v] else ans.append(0) for a in ans: print(a)
Strongly Connected Components A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable.
[{"input": "5 6\n 0 1\n 1 0\n 1 2\n 2 4\n 4 3\n 3 2\n 4\n 0 1\n 0 3\n 2 3\n 3 4", "output": "1\n 0\n 1\n 1"}]
Print the number of permutations modulo M. * * *
s857395864
Accepted
p02738
Input is given from Standard Input in the following format: N M
from functools import lru_cache N, M = map(int, input().split()) @lru_cache(maxsize=None) def mod_inv(x): x1, y1, z1 = 1, 0, x x2, y2, z2 = 0, 1, M while z1 != 1: d, m = divmod(z2, z1) x1, x2 = x2 - d * x1, x1 y1, y2 = y2 - d * y1, y1 z1, z2 = m, z1 return x1 % M def gen_Y(i): # sC2/1, (s-2)C2/2, (s-4)C2/3 ... s = 3 * (N - i) r = s * (s - 1) >> 1 d_r = (s << 1) - 3 for j in range(1, N - i + 1): yield r * mod_inv(j) r -= d_r d_r -= 4 def gen_X(): # sC3*2/1, (s-3)C3*2/2, (s-6)C3*2/3 ... a = N b = 3 * N - 1 for i in range(1, N + 1): yield a * b * (b - 1) * mod_inv(i) a -= 1 b -= 3 def acc_mulmod(it, init=1): x = init yield x for y in it: x = x * y % M yield x ans = sum(sum(acc_mulmod(gen_Y(i), A)) for i, A in enumerate(acc_mulmod(gen_X()))) % M print(ans)
Statement Given is a positive integer N. Find the number of permutations (P_1,P_2,\cdots,P_{3N}) of (1,2,\cdots,3N) that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number M. * Make N sequences A_1,A_2,\cdots,A_N of length 3 each, using each of the integers 1 through 3N exactly once. * Let P be an empty sequence, and do the following operation 3N times. * Among the elements that are at the beginning of one of the sequences A_i that is non-empty, let the smallest be x. * Remove x from the sequence, and add x at the end of P.
[{"input": "1 998244353", "output": "6\n \n\nAll permutations of length 3 count.\n\n* * *"}, {"input": "2 998244353", "output": "261\n \n\n* * *"}, {"input": "314 1000000007", "output": "182908545"}]
Print the number of permutations modulo M. * * *
s849232749
Accepted
p02738
Input is given from Standard Input in the following format: N M
n, m = map(int, input().split()) N = 3 * n d = [[0] * (N + 1) for i in range(N + 4)] d[0][0] = 1 for i in range(N): a, b, c, e = d[i : i + 4] for j in range(N): J = j + 1 b[j] = (b[j] + a[j]) % m c[J] = (c[J] + a[j] * (i + 1)) % m e[J] = (e[J] + a[j] * (i + 1) * (i + 2)) % m print(sum(d[N][: n + 1]) % m)
Statement Given is a positive integer N. Find the number of permutations (P_1,P_2,\cdots,P_{3N}) of (1,2,\cdots,3N) that can be generated through the procedure below. This number can be enormous, so print it modulo a prime number M. * Make N sequences A_1,A_2,\cdots,A_N of length 3 each, using each of the integers 1 through 3N exactly once. * Let P be an empty sequence, and do the following operation 3N times. * Among the elements that are at the beginning of one of the sequences A_i that is non-empty, let the smallest be x. * Remove x from the sequence, and add x at the end of P.
[{"input": "1 998244353", "output": "6\n \n\nAll permutations of length 3 count.\n\n* * *"}, {"input": "2 998244353", "output": "261\n \n\n* * *"}, {"input": "314 1000000007", "output": "182908545"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s631227888
Runtime Error
p03083
Input is given from Standard Input in the following format: B W
B, W = map(int, input().split()) def gcd(a, b): """ 自然数a, b の最大公約数を求める """ if b == 0: return a else: return gcd(b, a % b) def ExtendedEuclidianAlgorithms(a, b): """ 返り値: 自然数a, bの最小公倍数d, ax+by=gcd(a, b)を満たす(x, y)が、 (d, x, y)のtuple d = 1ならxはaの逆元(inverse element) """ d, c1 = a, b x0, x1 = 1, 0 y0, y1 = 0, 1 while c1 != 0: m = d % c1 q = d // c1 d, c1 = c1, m x0, x1 = x1, (x0 - q * x1) y0, y1 = y1, (y0 - q * y1) return d, x0, y0 def makeTableMod(N, mod=10**9 + 7): fac = [1 for i in range(N)] finv = [1 for i in range(N)] inv = [1 for i in range(N)] for i in range(2, N): fac[i] = fac[i - 1] * i % mod inv[i] = mod - inv[mod % i] * (mod // i) % mod finv[i] = finv[i - 1] * inv[i] % mod return fac, finv def binomialCoefficient(N, r, mod=10**9 + 7): if N < r: return 0 else: return fac[N] * (finv[r] * finv[N - r] % mod) % mod fac, finv = makeTableMod(B + W) mod = 10**9 + 7 def unknown(x, y, mod=10**9 + 7): g, a, b = ExtendedEuclidianAlgorithms(x, mod) if g != 1: raise Exception("modular inverse does not exist") else: return a * y % mod def plusFraction(frac1, frac2): """ frac: tuple (numerator, denominator) """ b, a = frac1 d, c = frac2 g = gcd(a, c) nume = b * (c // g) + d * (a // g) deno = (a * c) // g g = gcd(nume, deno) nume //= g deno //= g return (nume, deno) P = [(0, 1)] Q = [(0, 1)] for i in range(B + W): if i == 0: print(500000004) continue p = plusFraction(P[-1], (binomialCoefficient(i - 1, B - 1, mod), 2**i)) q = plusFraction(Q[-1], (binomialCoefficient(i - 1, W - 1, mod), 2**i)) P.append(p) Q.append(q) b, a = p[1] - p[0], p[1] d, c = q g = gcd(a, c) nume = b * (c // g) + d * (a // g) deno = ((a * c) // g) * 2 g = gcd(nume, deno) nume //= g deno //= g ans = unknown(deno, nume) print(ans)
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s146154234
Accepted
p03083
Input is given from Standard Input in the following format: B W
import sys write = sys.stdout.write B, W = map(int, sys.stdin.readline().split()) MOD = 10**9 + 7 L = B + W fact = [1] * (L + 1) rfact = [1] * (L + 1) for i in range(L): fact[i + 1] = r = fact[i] * (i + 1) % MOD rfact[L] = pow(fact[L], MOD - 2, MOD) for i in range(L, 0, -1): rfact[i - 1] = rfact[i] * i % MOD rev2 = pow(2, MOD - 2, MOD) p = q = 0 L = min(B, W) r2 = "%d\n" % rev2 for i in range(L): write(r2) base = pow(rev2, L - 1, MOD) rB = rfact[B - 1] rW = rfact[W - 1] for i in range(L, B + W): base = rev2 * base % MOD if i >= B: p = (p + (fact[i - 1] * rfact[i - B] % MOD) * (rB * base % MOD) % MOD) % MOD if i >= W: q = (q + (fact[i - 1] * rfact[i - W] % MOD) * (rW * base % MOD) % MOD) % MOD write("%d\n" % ((1 - p + q) * rev2 % MOD))
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s642414855
Accepted
p03083
Input is given from Standard Input in the following format: B W
# a,b,c = [int(i) for i in input().split()] import sys input = sys.stdin.readline SIZE = 200002 MOD = 10**9 + 7 bai = 500000000 + 4 inv = [0] * (SIZE + 1) # inv[j] = j^{-1} mod MOD fac = [0] * (SIZE + 1) # fac[j] = j! mod MOD finv = [0] * (SIZE + 1) # finv[j] = (j!)^{-1} mod MOD inv[1] = 1 fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2, SIZE + 1): inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD fac[i] = fac[i - 1] * i % MOD finv[i] = finv[i - 1] * inv[i] % MOD def choose(n, r): # nCk mod MOD の計算 if 0 <= r <= n: return (fac[n] * finv[r] % MOD) * finv[n - r] % MOD else: return 0 b, w = [int(i) for i in input().split()] c = min(b, w) for i in [0] * c: print(bai) ans = bai p = pow(bai, c + 1, MOD) for i in range(c, b + w): # print(p,i-1,i-w,b-1) ans += p * (choose(i - 1, i - w) - choose(i - 1, b - 1)) p = p * bai p %= MOD ans = ans % MOD print(ans)
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s699061284
Accepted
p03083
Input is given from Standard Input in the following format: B W
import sys readline = sys.stdin.readline sys.setrecursionlimit(10**7) import numpy as np MOD = 10**9 + 7 B, W = map(int, readline().split()) def cumprod(arr): L = len(arr) Lsq = int(L**0.5 + 1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n - 1] arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n - 1, -1] arr[n] %= MOD return arr.ravel()[:L] U = 2 * 10**5 + 100 x = np.arange(U, dtype=np.int64) x[0] = 1 fact = cumprod(x) x = np.arange(U, 0, -1, dtype=np.int64) x[0] = pow(int(fact[-1]), MOD - 2, MOD) fact_inv = cumprod(x)[::-1] x = np.full(U, pow(2, MOD - 2, MOD), dtype=np.int64) x[0] = 1 pow2_inv = cumprod(x) # 各時点で、単色になっている確率 black_only = np.zeros(B + W, np.int64) x = fact[W - 1 : B + W - 1] % MOD * fact_inv[0:B] % MOD * fact_inv[W - 1] % MOD black_only[W : B + W] = pow2_inv[W : B + W] * x % MOD np.cumsum(black_only, out=black_only) black_only %= MOD white_only = np.zeros(W + B, np.int64) x = fact[B - 1 : W + B - 1] % MOD * fact_inv[0:W] % MOD * fact_inv[B - 1] % MOD white_only[B : W + B] = pow2_inv[B : W + B] * x % MOD np.cumsum(white_only, out=white_only) white_only %= MOD answer = (1 + black_only - white_only) * pow(2, MOD - 2, MOD) % MOD print("\n".join(answer.astype(str)))
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s188852787
Accepted
p03083
Input is given from Standard Input in the following format: B W
mod = 10**9 + 7 b, w = map(int, input().split()) def comb(n, r): if n < r: return 0 if n < 0 or r < 0: return 0 return fa[n] * fi[r] % mod * fi[n - r] % mod n = b + w + 10 inv = [1] * (n + 1) fa = [1] * (n + 1) fi = [1] * (n + 1) for i in range(1, n): inv[i] = ((inv[i - 1] % 2) * mod + inv[i - 1]) // 2 fa[i] = fa[i - 1] * i % mod fi[i] = pow(fa[i], mod - 2, mod) p, q = 0, 0 for i in range(b + w): if i >= b: p *= 2 p += comb(i - 1, b - 1) p %= mod if i >= w: q *= 2 q += comb(i - 1, w - 1) q %= mod print(((q - p) * inv[i + 1] + inv[1]) % mod)
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s555087154
Accepted
p03083
Input is given from Standard Input in the following format: B W
b, w = map(int, input().split()) MOD = 10**9 + 7 list_size = 200001 f_list = [1] * list_size f_r_list = [1] * list_size for i in range(list_size - 1): f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD) f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD) for i in range(2, list_size + 1): f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD) def comb(n, r): if n < r: return 0 elif n == 0 or r == 0 or n == r: return 1 else: return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD two_pow = [1] for i in range(b + w + 1): two_pow.append((two_pow[-1] * 500000004) % MOD) ans = 500000004 print(ans) for i in range(1, b + w): if i - 1 >= b - 1: ans -= comb(i - 1, b - 1) * two_pow[i + 1] if i - w >= 0: ans += comb(i - 1, i - w) * two_pow[i + 1] ans %= MOD print(ans)
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s161661718
Accepted
p03083
Input is given from Standard Input in the following format: B W
def main(): U = 2 * 10**5 MOD = 10**9 + 7 fact = [1] * (U + 1) fact_inv = [1] * (U + 1) two = [1] * (U + 1) two_inv = [1] * (U + 1) for i in range(1, U + 1): fact[i] = (fact[i - 1] * i) % MOD two[i] = (two[i - 1] * 2) % MOD fact_inv[U] = pow(fact[U], MOD - 2, MOD) two_inv[U] = pow(two[U], MOD - 2, MOD) for i in range(U, 0, -1): fact_inv[i - 1] = (fact_inv[i] * i) % MOD two_inv[i - 1] = (two_inv[i] * 2) % MOD def comb(n, k): if k < 0 or k > n: return 0 z = fact[n] z *= fact_inv[k] z %= MOD z *= fact_inv[n - k] z %= MOD return z B, W = map(int, input().split()) p = 0 q = 0 for i in range(1, B + W + 1): ans = 1 - p + q ans %= MOD ans *= two_inv[1] ans %= MOD print(ans) p += comb(i - 1, B - 1) * two_inv[i] % MOD p %= MOD q += comb(i - 1, W - 1) * two_inv[i] % MOD q %= MOD if __name__ == "__main__": main()
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s870671441
Accepted
p03083
Input is given from Standard Input in the following format: B W
def cmb(n, r, mod): # コンビネーションの高速計算 if r < 0 or r > n: return 0 r = min(r, n - r) return g1[n] * g2[r] * g2[n - r] % mod mod = 10**9 + 7 # 出力の制限 N = 2 * 10**5 g1 = [1, 1] # 元テーブル g2 = [1, 1] # 逆元テーブル inverse = [0, 1] # 逆元テーブル計算用テーブル for i in range(2, N + 1): g1.append((g1[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod // i)) % mod) g2.append((g2[-1] * inverse[-1]) % mod) import sys write = sys.stdout.write B, W = map(int, input().split()) p = [1] for i in range(1, B + W + 1): p.append((p[-1] * inverse[2]) % mod) BD = [0] for i in range(1, B + W + 1): t = (BD[-1] + cmb(i - 1, B - 1, mod) * p[i]) % mod BD.append(t) WD = [0] for i in range(1, B + W + 1): t = (WD[-1] + cmb(i - 1, W - 1, mod) * p[i]) % mod WD.append(t) for i in range(1, B + W + 1): ans = (1 - BD[i - 1] - WD[i - 1]) * p[1] + WD[i - 1] ans %= mod write(str(ans) + "\n")
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7. * * *
s929229435
Runtime Error
p03083
Input is given from Standard Input in the following format: B W
def main(): b, w = map(int, input().split()) mod = 10**9 + 7 fact = [1, 1] for i in range(2, 10**5): fact.append(fact[-1] * i % mod) half = pow(2, mod - 2, mod) def nCr(n, r, mod=10**9 + 7): return pow(fact[n - r] * fact[r] % mod, mod - 2, mod) * fact[n] % mod h = 1 A, B, C = 0, 1, 0 for i in range(1, b + w + 1): h = h * half % mod ans = B A = A * 2 % mod B = B * 2 % mod C = C * 2 % mod if i - 1 >= b: p = nCr(i - 1, b) ans = (ans - p) % mod C = (C + p) % mod B = (B - p) % mod if i - w - 1 >= 0: p = nCr(i - 1, i - w - 1) A = (A + p) % mod B = (B - p) % mod ans = (ans + A) % mod print(ans * h % mod) main()
Statement Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack. He will repeat the following procedure until there is no piece left: * Choose black or white with equal probability, and eat a piece of that color if it exists. For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black. It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.
[{"input": "2 1", "output": "500000004\n 750000006\n 750000006\n \n\n * There are three possible orders in which Snuke eats the pieces:\n * white, black, black\n * black, white, black\n * black, black, white\n * with probabilities \\frac{1}{2}, \\frac{1}{4}, \\frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \\frac{1}{2},\\frac{3}{4} and \\frac{3}{4}, respectively.\n\n* * *"}, {"input": "3 2", "output": "500000004\n 500000004\n 625000005\n 187500002\n 187500002\n \n\n * They are \\frac{1}{2},\\frac{1}{2},\\frac{5}{8},\\frac{11}{16} and \\frac{11}{16}, respectively.\n\n* * *"}, {"input": "6 9", "output": "500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 500000004\n 929687507\n 218750002\n 224609377\n 303710940\n 633300786\n 694091802\n 172485353\n 411682132\n 411682132"}]
Find the maximum possible number of edges that can be added. * * *
s297008908
Runtime Error
p03579
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M
v N,M = map(int, input().split()) es = [[] for i in range(N)] for i in range(M): a,b = map(int, input().split()) a,b = a-1,b-1 es[a].append(b) es[b].append(a) colors = [0 for i in range(N)] def is_bipartite(): stack = [(0,1)] while stack: v,color = stack.pop() colors[v] = color for to in es[v]: if colors[to] == color: return False if colors[to] == 0: stack.append((to, -color)) return True if is_bipartite(): b = (sum(colors) + N) // 2 w = N-b print(b*w - M) else: all = N*(N-1) // 2 print(all - M)
Statement Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
[{"input": "6 5\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "4\n \n\nIf we add edges as shown below, four edges can be added, and no more.\n\n![](https://img.atcoder.jp/code-\nfestival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png)\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 1\n 5 4\n 5 1", "output": "5\n \n\nFive edges can be added, for example, as follows:\n\n * Add an edge connecting Vertex 5 and Vertex 3.\n * Add an edge connecting Vertex 5 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 1.\n * Add an edge connecting Vertex 4 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 3."}]
Find the maximum possible number of edges that can be added. * * *
s090491589
Runtime Error
p03579
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M
import networkx as nx print("a")
Statement Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
[{"input": "6 5\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "4\n \n\nIf we add edges as shown below, four edges can be added, and no more.\n\n![](https://img.atcoder.jp/code-\nfestival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png)\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 1\n 5 4\n 5 1", "output": "5\n \n\nFive edges can be added, for example, as follows:\n\n * Add an edge connecting Vertex 5 and Vertex 3.\n * Add an edge connecting Vertex 5 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 1.\n * Add an edge connecting Vertex 4 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 3."}]
Find the maximum possible number of edges that can be added. * * *
s788841592
Accepted
p03579
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M
import sys from collections import deque readline = sys.stdin.buffer.readline ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) def solve(): mod = 10**9 + 7 n, m = nm() G = [list() for _ in range(n)] for _ in range(m): u, v = nm() u -= 1 v -= 1 G[u].append(v) G[v].append(u) col = [-1] * n q = deque([0]) col[0] = 1 while q: v = q.popleft() for x in G[v]: if col[x] < 0: col[x] = col[v] ^ 1 q.append(x) elif col[x] == col[v]: print(n * (n - 1) // 2 - m) return bl = sum(col) wh = n - bl print(bl * wh - m) return solve() # T = ni() # for _ in range(T): # solve()
Statement Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
[{"input": "6 5\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "4\n \n\nIf we add edges as shown below, four edges can be added, and no more.\n\n![](https://img.atcoder.jp/code-\nfestival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png)\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 1\n 5 4\n 5 1", "output": "5\n \n\nFive edges can be added, for example, as follows:\n\n * Add an edge connecting Vertex 5 and Vertex 3.\n * Add an edge connecting Vertex 5 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 1.\n * Add an edge connecting Vertex 4 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 3."}]
Find the maximum possible number of edges that can be added. * * *
s672993936
Runtime Error
p03579
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M
import sys sys.setrecursionlimit(10**7) N, M = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(M)] graph = [[] for _ in range(N)] for a, b in AB: graph[a−1].append(b - 1) graph[b - 1].append(a - 1) # 二部グラフかどうかの判定 color = [None] * N color[0] = 0 q = [0] while q: x = q.pop() for y in graph[x]: if color[y] is None: color[y] = 1 - color[x] q.append(y) # 二部グラフかどうか bg = all(color[a] != color[b] for a, b in AB) if bg: # 完全二部グラフにする x = sum(color) y = N - x answer = x * y - M else: # 完全グラフにする(奇数長のパスがある場合は必ず2ずつ減らしていけば長さが3になる) answer = N * (N - 1) // 2 - M print(answer)
Statement Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
[{"input": "6 5\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "4\n \n\nIf we add edges as shown below, four edges can be added, and no more.\n\n![](https://img.atcoder.jp/code-\nfestival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png)\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 1\n 5 4\n 5 1", "output": "5\n \n\nFive edges can be added, for example, as follows:\n\n * Add an edge connecting Vertex 5 and Vertex 3.\n * Add an edge connecting Vertex 5 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 1.\n * Add an edge connecting Vertex 4 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 3."}]
Find the maximum possible number of edges that can be added. * * *
s368005650
Accepted
p03579
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M
# 設定 import sys input = sys.stdin.buffer.readline # ライブラリインポート from collections import defaultdict import queue # 入力受け取り def getlist(): return list(map(int, input().split())) INF = float("inf") class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b): self.graph[a].append(b) def get_nodes(self): return self.graph.keys() class BFS(object): def __init__(self, graph, s, N): self.g = graph.graph self.Q = queue.Queue() self.Q.put(0) self.W = [INF] * N # sからの距離 self.visit = ["No"] * N # 見たか判定 self.visit[s] = "Yes" self.W[s] = 0 self.judge = "Yes" while not self.Q.empty(): v = self.Q.get() for i in self.g[v]: if self.visit[i] == "No": self.W[i] = self.W[v] + 1 self.Q.put(i) self.visit[i] = "Yes" # 二部グラフ判定 else: if (self.W[i] - self.W[v] - 1) % 2 == 1: self.judge = "No" break # 処理内容 def main(): N, M = getlist() G = Graph() for i in range(M): a, b = getlist() G.add_edge(a - 1, b - 1) G.add_edge(b - 1, a - 1) BF = BFS(G, 0, N) if BF.judge == "No": print(int(N * (N - 1) // 2) - M) else: even = 0 odd = 0 for i in BF.W: if i % 2 == 0: even += 1 else: odd += 1 print(even * odd - M) if __name__ == "__main__": main()
Statement Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
[{"input": "6 5\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "4\n \n\nIf we add edges as shown below, four edges can be added, and no more.\n\n![](https://img.atcoder.jp/code-\nfestival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png)\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 1\n 5 4\n 5 1", "output": "5\n \n\nFive edges can be added, for example, as follows:\n\n * Add an edge connecting Vertex 5 and Vertex 3.\n * Add an edge connecting Vertex 5 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 1.\n * Add an edge connecting Vertex 4 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 3."}]
Find the maximum possible number of edges that can be added. * * *
s279813005
Runtime Error
p03579
Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 : A_M B_M
vn, en = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(en)] e = [[] for _ in range(vn)] for f, t in ab: e[f - 1].append(t - 1) e[t - 1].append(f - 1) def dfs(v, root: list): if v in root: return else: root.append(v) if len(root) == 4: if not (root[-1] in e[root[0]]): s.add(tuple(root)) s.add(tuple(root[::-1])) e[root[0]].append(root[-1]) e[root[-1]].append(root[0]) else: for vt in e[root[-1]]: if not vt in root: dfs(vt, root) s = set() for vi in range(vn): for vt in e[vi]: dfs(vt, [vi]) print(len(s) // 2)
Statement Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \neq v) such that Vertex v can be reached by traversing exactly three edges from Vertex u, and add an edge connecting Vertices u and v. It is not allowed to add an edge if there is already an edge connecting Vertices u and v. Find the maximum possible number of edges that can be added.
[{"input": "6 5\n 1 2\n 2 3\n 3 4\n 4 5\n 5 6", "output": "4\n \n\nIf we add edges as shown below, four edges can be added, and no more.\n\n![](https://img.atcoder.jp/code-\nfestival-2017-qualb/6e99dccc06ac8b14d9ca2e297524bc0c.png)\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 1\n 5 4\n 5 1", "output": "5\n \n\nFive edges can be added, for example, as follows:\n\n * Add an edge connecting Vertex 5 and Vertex 3.\n * Add an edge connecting Vertex 5 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 1.\n * Add an edge connecting Vertex 4 and Vertex 2.\n * Add an edge connecting Vertex 4 and Vertex 3."}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s499420089
Accepted
p03129
Input is given from Standard Input in the following format: N K
# coding: utf-8 import re import math import itertools from copy import deepcopy import fractions import random from heapq import heappop, heappush import time import os import queue import sys import datetime from functools import lru_cache readline = sys.stdin.readline sys.setrecursionlimit(2000) # import numpy as np alphabet = "abcdefghijklmnopqrstuvwxyz" mod = int(10**9 + 7) inf = int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find: def __init__(self, n): self.n = n self.P = [a for a in range(N)] self.rank = [0] * n def find(self, x): if x != self.P[x]: self.P[x] = self.find(self.P[x]) return self.P[x] def same(self, x, y): return self.find(x) == self.find(y) def link(self, x, y): if self.rank[x] < self.rank[y]: self.P[x] = y elif self.rank[y] < self.rank[x]: self.P[y] = x else: self.P[x] = y self.rank[y] += 1 def unite(self, x, y): self.link(self.find(x), self.find(y)) def size(self): S = set() for a in range(self.n): S.add(self.find(a)) return len(S) def is_power(a, b): # aはbの累乗数か now = b while now < a: now *= b if now == a: return True else: return False def bin_(num, size): A = [0] * size for a in range(size): if (num >> (size - a - 1)) & 1 == 1: A[a] = 1 else: A[a] = 0 return A def fac_list(n, mod_=0): A = [1] * (n + 1) for a in range(2, len(A)): A[a] = A[a - 1] * a if mod > 0: A[a] %= mod_ return A def comb(n, r, mod, fac): if n - r < 0: return 0 return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod def next_comb(num, size): x = num & (-num) y = num + x z = num & (~y) z //= x z = z >> 1 num = y | z if num >= (1 << size): return False else: return num def get_primes(n, type="int"): A = [True] * (n + 1) A[0] = False A[1] = False for a in range(2, n + 1): if A[a]: for b in range(a * 2, n + 1, a): A[b] = False if type == "bool": return A B = [] for a in range(n + 1): if A[a]: B.append(a) return B def is_prime(num): if num <= 2: return False i = 2 while i * i <= num: if num % i == 0: return False i += 1 return True def 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 ############################################ N, K = map(int, input().split()) YN((N + 1) // 2 >= K)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s506772124
Wrong Answer
p03129
Input is given from Standard Input in the following format: N K
import sys input_methods = ["clipboard", "file", "key"] using_method = 0 input_method = input_methods[using_method] tin = lambda: map(int, input().split()) lin = lambda: list(tin()) mod = 1000000007 # +++++ def main(): # a = int(input()) # b , c = tin() # s = input() b, c = tin() return "Yes" if b >= (c * 2) - 1 else "No" # +++++ isTest = False def pa(v): if isTest: print(v) def input_clipboard(): import clipboard input_text = clipboard.get() input_l = input_text.splitlines() for l in input_l: yield l if __name__ == "__main__": if sys.platform == "ios": if input_method == input_methods[0]: ic = input_clipboard() input = lambda: ic.__next__() elif input_method == input_methods[1]: sys.stdin = open("inputFile.txt") else: pass isTest = True else: pass # input = sys.stdin.readline ret = main() if ret is not None: print(ret)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s554342182
Wrong Answer
p03129
Input is given from Standard Input in the following format: N K
n, k = [int(v) for v in input().split()] print("Yes" if k <= (n + 1) // 2 else "No")
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s589455655
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k=map(int,input().split()) if (n+1)/2>=k: print('YES') else: print('')NO
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s538680124
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int, input().split()) ans = 2*k+1 if ans > n: print(“No”) else: print(“Yes”)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s787701247
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int, input().split()) ans = 2*k+1 if ans > n:print(“NO”) else:print(“YES”)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s453279953
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
N, K = map(int,input().split()) if N + 1 >= 2 * K: print('YES') ele: print('NO')
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s783270647
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int, input().split()) ans = 2*k+1 if ans > n: print(“NO”) else: print(“YES”)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s374151196
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int(), input().split()) ans = 2*k+1 if ans > n: print(“No”) else: print(“Yes”)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s268805475
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int,input().split()) num = int(n/2) + 1 if n!=2andnum>=k: print('YES') else: print('NO')
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s072749688
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int, input().split()) ans = 2*k+1 if ans > n: print(‘NO’) else: print(‘YES’)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s281719006
Accepted
p03129
Input is given from Standard Input in the following format: N K
# import bisect # import heapq # import math # import random # from fractions import gcd # from collections import Counter, defaultdict, deque # from decimal import Decimal # from functools import lru_cache, reduce # from itertools import combinations, combinations_with_replacement, product, permutations # from operator import add, mul, sub, itemgetter # import numpy as np import sys sys.setrecursionlimit(10000) def read_int(read=None): if read == None: read = sys.stdin.readline().strip() return int(read) def read_int_n(read=None): if read == None: read = sys.stdin.readline().strip() return [int(x) for x in read.split()] def read_float(read=None): if read == None: read = sys.stdin.readline().strip() return float(read) def read_float_n(read=None): if read == None: read = sys.stdin.readline().strip() return [float(x) for x in read.split()] def read_str(read=None): if read == None: read = sys.stdin.readline().strip() return str(read) def read_str_n(read=None): if read == None: read = sys.stdin.readline().strip() return [str(x) for x in read.split()] def error_print(*args): print(*args, file=sys.stderr) def mt(f): import time def wrap(*args, **kwargs): s = time.time() ret = f(*args, **kwargs) e = time.time() error_print(e - s, "sec") return ret return wrap @mt def slv(N, K): if N + 1 >= 2 * K: ans = "YES" else: ans = "NO" return ans def main(): t = """ """.splitlines() N, K = read_int_n() print(slv(N, K)) if __name__ == "__main__": main()
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s619444281
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
A,B=map(int, input() .split()) if int(A / 2) + 1 =< B: print(YES) else: print(NO)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s186692059
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
i = list(map(int, input().split())) n = i[0] k = i[1] if n >= 1 and n <= 100 and k >= 1 and k <= 100: if n > 2: if n > k - 2: if n % 2 == 1: if n / k >= 1: print("YES") elif n % k == 1: print("YES") else: print("NO") elif: if n / k >= 2: print("YES") elif n % k == 0: print("YES") else: print("NO") else: print("NO") else: print("NO") else: print("NO") else: print("NO")
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s076410904
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
import numpy as np n, k = (int(x) for x in input().split()) if n%2==0: if k <= n/2.0 print("YES") else: print("NO") if n%2!=0: if k <= np.ceil(n/2.0) print("YES") else: print("NO")
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s490766708
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
i = list(map(int, input().split())) n = i[0] k = i[1] if n >= 1 and n <= 100 and k >= 1 and k <= 100: if n > 2: if n % 2 == 1: if n / k >= 1: print("YES") elif n % k == 1: print("YES") else: print("NO") else: if n / k >= 2: print("YES") elif n % k == 0: print("YES") else: print("NO") else: print("NO") else:
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s417005859
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int,input().split()) ans = 2*k+1 if ans > n: print(‘NO’) else: print(‘YES’)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s335883893
Wrong Answer
p03129
Input is given from Standard Input in the following format: N K
a, b = list(map(int, input().split())) print("YES" if (a + b - 1) / 2 >= b else "NO")
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s922036815
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
N,K = map(int,input().split()) IF (int(N/2)+1>K): print("YES") ELSE: print("NO")
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s898649225
Accepted
p03129
Input is given from Standard Input in the following format: N K
# coding: utf-8 import sys # import bisect # import math # import numpy as np """Template""" class IP: """ 入力を取得するクラス """ def __init__(self): self.input = sys.stdin.readline def I(self): """ 1文字の取得に使います :return: int """ return int(self.input()) def S(self): """ 1文字の取得(str :return: str """ return self.input() def IL(self): """ 1行を空白で区切りリストにします(int :return: リスト """ return list(map(int, self.input().split())) def SL(self): """ 1行の文字列を空白区切りでリストにします :return: リスト """ return list(map(str, self.input().split())) def ILS(self, n): """ 1列丸々取得します(int :param n: 行数 :return: リスト """ return [int(self.input()) for _ in range(n)] def SLS(self, n): """ 1列丸々取得します(str :param n: 行数 :return: リスト """ return [self.input() for _ in range(n)] def SILS(self, n): """ Some Int LineS 横に複数、縦にも複数 :param n: 行数 :return: list """ return [self.IL() for _ in range(n)] def SSLS(self, n): """ Some String LineS :param n: 行数 :return: list """ return [self.SL() for _ in range(n)] class Idea: def __init__(self): pass def HF(self, p): """ Half enumeration 半分全列挙です pの要素の和の組み合わせを作ります。 ソート、重複削除行います :param p: list : 元となるリスト :return: list : 組み合わせられた和のリスト """ return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p)))) def Bfs2(self, a): """ bit_full_search2 bit全探索の改良版 全探索させたら2進数のリストと10進数のリストを返す :return: list2つ : 1個目 2進数(16桁) 2個目 10進数 """ # 参考 # https://blog.rossywhite.com/2018/08/06/bit-search/ # https://atcoder.jp/contests/abc105/submissions/4088632 value = [] for i in range(1 << len(a)): output = [] for j in range(len(a)): if self.bit_o(i, j): """右からj+1番目のiが1かどうか判定""" # output.append(a[j]) output.append(a[j]) value.append([format(i, "b").zfill(16), sum(output)]) value.sort(key=lambda x: x[1]) bin = [value[k][0] for k in range(len(value))] val = [value[k][1] for k in range(len(value))] return bin, val def S(self, s, r=0, m=-1): """ ソート関係行います。色々な設定あります。 :param s: 元となるリスト :param r: reversするかどうか 0=False 1=True :param m: (2次元配列)何番目のインデックスのソートなのか :return: None """ r = bool(r) if m == -1: s.sort(reverse=r) else: s.sort(reverse=r, key=lambda x: x[m]) def bit_n(self, a, b): """ bit探索で使います。0以上のときにTrue出します 自然数だからn :param a: int :param b: int :return: bool """ return bool((a >> b & 1) > 0) def bit_o(self, a, b): """ bit探索で使います。1のときにTrue出すよ oneで1 :param a: int :param b: int :return: bool """ return bool(((a >> b) & 1) == 1) def ceil(self, x, y): """ Round up 小数点切り上げ割り算 :param x: int :param y: int :return: int """ return -(-x // y) def ave(self, a): """ 平均を求めます :param a: list :return: int """ return sum(a) / len(a) """ここからメインコード""" def main(): # 1文字に省略 r, e = range, enumerate ip = IP() id = Idea() """この下から書いてね""" n, k = ip.IL() a = k * 2 if a - 2 < n: print("YES") else: print("NO") main()
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s809962426
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
def solution(edges): num_of_neighbor = {} for e in edges: if e[0] in num_of_neighbor: num_of_neighbor[e[0]] += 1 else: num_of_neighbor[e[0]] = 1 if e[1] in num_of_neighbor: num_of_neighbor[e[1]] += 1 else: num_of_neighbor[e[1]] = 1 n_2 = 0 n_1 = 0 for n in num_of_neighbor: if num_of_neighbor[n] == 2: n_2 += 1 elif num_of_neighbor[n] == 1: n_1 += 1 if n_2 == 2 and n_1 == 2: return "YES" else: return "NO" e1 = [int(s) for s in input().split(" ")] e2 = [int(s) for s in input().split(" ")] e3 = [int(s) for s in input().split(" ")] edges = [e1, e2, e3] print(solution(edges))
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s237057984
Accepted
p03129
Input is given from Standard Input in the following format: N K
print("YNEOS"[(lambda n, k: n < k * 2 - 1)(*map(int, input().split())) :: 2])
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s727372206
Wrong Answer
p03129
Input is given from Standard Input in the following format: N K
def Main(n, k): if n - k > 0: return "YES" else: return "NO"
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s654568379
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n, k = int(map(int, input().split())) print("YES" if (n + 1) >= k + k else "NO")
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s261200700
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
A,B=map(int, input() .split()) if int(A / 2) + 1 =< B: print(YES) else:print
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s936591072
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
print("YES" if sum(divmod(int(input()), 2)) >= int(inpu()) else "NO")
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
If we can choose K integers as above, print `YES`; otherwise, print `NO`. * * *
s423672912
Runtime Error
p03129
Input is given from Standard Input in the following format: N K
n,k = map(int, input().split()) ans = 2*k+1 if ans > n: print(‘NO’) else: print(‘YES’)
Statement Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
[{"input": "3 2", "output": "YES\n \n\nWe can choose 1 and 3.\n\n* * *"}, {"input": "5 5", "output": "NO\n \n\n* * *"}, {"input": "31 10", "output": "YES\n \n\n* * *"}, {"input": "10 90", "output": "NO"}]
For each dataset, print the grade (A, B, C, D or F) in a line.
s633064491
Accepted
p02411
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line. The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols. The number of datasets (the number of students) does not exceed 50.
while True: m,f,r = map(int,input().split()) if m == -1 and f == -1 and r == -1: break if m == -1 or f ==-1: print('F') if m != -1 and f!=-1: if m+f >= 80: print('A') elif 65<=m+f<80: print('B') elif 50 <= m+f < 65 or r>=50: print('C') elif 30 <= m+f <50: print('D') elif m+f<30: print('F')
Grading Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
[{"input": "42 -1\n 20 30 -1\n 0 2 -1\n -1 -1 -1", "output": "A\n C\n F"}]
For each dataset, print the grade (A, B, C, D or F) in a line.
s577106477
Accepted
p02411
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line. The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols. The number of datasets (the number of students) does not exceed 50.
while True: m, f, r = list(map(int, input().split())) if m == f == r ==-1: break if m == -1 or f == -1: print("F") elif m + f >= 80: print("A") elif 65 <= m + f < 80: print("B") elif 50 <= m + f < 65: print("C") elif 30 <= m + f < 50: if r >= 50: print("C") else: print("D") else: print("F")
Grading Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
[{"input": "42 -1\n 20 30 -1\n 0 2 -1\n -1 -1 -1", "output": "A\n C\n F"}]
For each dataset, print the grade (A, B, C, D or F) in a line.
s711037815
Accepted
p02411
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line. The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols. The number of datasets (the number of students) does not exceed 50.
while True: [m,f,r] = map(int,input().split()) if m==-1 and f==-1 and r==-1: break if m==-1 or f==-1: gr='F' elif m + f >=80: gr='A' elif m + f >=65: gr='B' elif m + f >=50: gr='C' elif m + f >=30 and r>=50: gr='C' elif m + f >=30: gr='D' else: gr='F' print(gr)
Grading Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
[{"input": "42 -1\n 20 30 -1\n 0 2 -1\n -1 -1 -1", "output": "A\n C\n F"}]
For each dataset, print the grade (A, B, C, D or F) in a line.
s600664586
Accepted
p02411
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line. The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols. The number of datasets (the number of students) does not exceed 50.
while True: data=list(map(int,input().split())) if data[0]==data[1]==data[2]==-1: break if data[0]!=-1 and data[1]!=-1: sum=data[0]+data[1] if data[2]!=-1 and sum<data[2]: if data[2]>=50: sum=50 if data[0]==-1 or data[1]==-1: print('F') elif sum<30 : print('F') elif 30<=sum<50: print('D') elif 50<=sum<65: print('C') elif 65<=sum<=79: print('B') elif 80<=sum: print('A')
Grading Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
[{"input": "42 -1\n 20 30 -1\n 0 2 -1\n -1 -1 -1", "output": "A\n C\n F"}]
For each dataset, print the grade (A, B, C, D or F) in a line.
s598138980
Accepted
p02411
The input consists of multiple datasets. For each dataset, three integers m, f and r are given in a line. The input ends with three -1 for m, f and r respectively. Your program should not process for the terminal symbols. The number of datasets (the number of students) does not exceed 50.
while True: m,f,r=map(int, input().split()) if m==-1 and f==-1 and r==-1: break elif m==-1 or f==-1: print('F') elif m+f>=80: print('A') elif m+f>=65: print('B') elif m+f>=50: print('C') elif m+f>=30: if r>=50: print('C') else: print('D') else: print('F')
Grading Write a program which reads a list of student test scores and evaluates the performance for each student. The test scores for a student include scores of the midterm examination m (out of 50), the final examination f (out of 50) and the makeup examination r (out of 100). If the student does not take the examination, the score is indicated by -1. The final performance of a student is evaluated by the following procedure: * If the student does not take the midterm or final examination, the student's grade shall be F. * If the total score of the midterm and final examination is greater than or equal to 80, the student's grade shall be A. * If the total score of the midterm and final examination is greater than or equal to 65 and less than 80, the student's grade shall be B. * If the total score of the midterm and final examination is greater than or equal to 50 and less than 65, the student's grade shall be C. * If the total score of the midterm and final examination is greater than or equal to 30 and less than 50, the student's grade shall be D. However, if the score of the makeup examination is greater than or equal to 50, the grade shall be C. * If the total score of the midterm and final examination is less than 30, the student's grade shall be F.
[{"input": "42 -1\n 20 30 -1\n 0 2 -1\n -1 -1 -1", "output": "A\n C\n F"}]
For each pair of input integers A and B, you must output the sum of A and B in one line.
s047902736
Runtime Error
p00586
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
print(sum(list(map(int, input().split))))
A + B Problem Compute A + B.
[{"input": "2\n 10 5\n 100 20", "output": "15\n 120"}]
Print the maximum possible number of times the operation can be performed. * * *
s442130937
Runtime Error
p03200
Input is given from Standard Input in the following format: S
import collections s = list(input()) Ans = 0 c = collections.Counter(s) d = c['B'] for i in range(len(s)): if s[i] == 'B': for j in range(len(s)-i-1): if s[i+j+1]=='W': Ans += j+1 s[i] = 'W' s[i+1] = 'B' s[i+j+1] = 'B' break if i = d: break print(Ans)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s692252772
Runtime Error
p03200
Input is given from Standard Input in the following format: S
import sys ## io ## def IS(): return sys.stdin.readline().rstrip() def II(): return int(IS()) def MII(): return list(map(int, IS().split())) def MIIZ(): return list(map(lambda x: x - 1, MII())) ## dp ## def DD2(d1, d2, init=0): return [[init] * d2 for _ in range(d1)] def DD3(d1, d2, d3, init=0): return [DD2(d2, d3, init) for _ in range(d1)] ## math ## def to_bin(x: int) -> str: return format(x, "b") # rev => int(res, 2) def to_oct(x: int) -> str: return format(x, "o") # rev => int(res, 8) def to_hex(x: int) -> str: return format(x, "x") # rev => int(res, 16) MOD = 10**9 + 7 def divc(x, y) -> int: return -(-x // y) def divf(x, y) -> int: return x // y def gcd(x, y): while y: x, y = y, x % y return x def lcm(x, y): return x * y // gcd(x, y) def enumerate_divs(n): """Return a tuple list of divisor of n""" return [(i, n // i) for i in range(1, int(n**0.5) + 1) if n % i == 0] def get_primes(MAX_NUM=10**3): """Return a list of prime numbers n or less""" is_prime = [True] * (MAX_NUM + 1) is_prime[0] = is_prime[1] = False for i in range(2, int(MAX_NUM**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, MAX_NUM + 1, i): is_prime[j] = False return [i for i in range(MAX_NUM + 1) if is_prime[i]] ## libs ## from itertools import ( accumulate as acc, combinations as combi, product, combinations_with_replacement as combi_dup, ) from collections import deque, Counter from heapq import heapify, heappop, heappush from bisect import bisect_left # ======================================================# def main(): s = IS() c = s.split("B") if s.index("W") != 0: c = c[1:] c = c[::-1] cnt_w = [len(ci) for ci in c] acc_w = acc(cnt_w) print(sum(acc_w)) if __name__ == "__main__": main()
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s075713009
Runtime Error
p03200
Input is given from Standard Input in the following format: S
S = input() W = [] for i, s enumerate(S): if s == 'W': W.append(i) idx = 0 ans = 0 for w in W: ans += w-idx idx += 1 print(ans)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s033202710
Wrong Answer
p03200
Input is given from Standard Input in the following format: S
S = input()[::-1] n = len(S) l = list(i for i in range(n) if S[-i] == "B") k = len(l) * (len(l) - 1) // 2 print(sum(l) - k)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s148496773
Runtime Error
p03200
Input is given from Standard Input in the following format: S
a = str(input()) aList = list(a) isW = False count = 0 for i in reversed(aList): if i == B: if isW == True: count = count + 1 else: isW = False if i == W: isW = True
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s588291493
Runtime Error
p03200
Input is given from Standard Input in the following format: S
N = int(input()) X = [[] for i in range(N)] P = [-1] * N for i in range(N - 1): x, y = map(int, input().split()) X[x - 1].append(y - 1) X[y - 1].append(x - 1) def set_parent(i): # print(i) for a in X[i]: if a != P[i]: P[a] = i # print(a) X[a].remove(i) set_parent(a) set_parent(0) B = [-1] * N def set_block(i): for a in X[i]: B[a] = max(i, B[i]) set_block(a) B_id = [-1] * N B_id_cnt = [0] * N def BID(i): for a in X[i]: if a > B[i]: B_id[a] = a else: B_id[a] = B_id[i] # print(a, B_id) B_id_cnt[B_id[a]] += 1 BID(a) Ans = [1] * N def flow(i): for a in X[i]: if B_id[a] == B_id[i]: Ans[a] = Ans[i] else: Ans[a] = Ans[i] + B_id_cnt[a] flow(a) set_block(0) # print("X=", X) # 子リスト # print("P=", P) # 親 # print("B=", B) # Block # print(B_id) # BlockのID # print(B_id_cnt) # BlockのID # print(Ans) print(" ".join(map(str, Ans[1:])))
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s162666387
Runtime Error
p03200
Input is given from Standard Input in the following format: S
# _*_ coding:utf-8 _*_ # Atcoder_Grand_Contest029-B # https://agc029.contest.atcoder.jp/tasks/agc029_b from collections import Counter def maxCountPair(n_ballCount, a_ballDatas): a_ballDatas.sort(reverse=True) ballDictBox = Counter(a_ballDatas) ballCountRange = range(0, n_ballCount) pairCount = 0 for i in ballCountRange: getBallNumber = a_ballDatas[i] getBallNumberBin = getBallNumber.bit_length() nextTwoPower = 2**getBallNumberBin diffNumber = nextTwoPower - getBallNumber if 1 <= ballDictBox[diffNumber]: if getBallNumber != diffNumber: pairCount = pairCount + 1 ballDictBox[getBallNumber] = ballDictBox[getBallNumber] - 1 ballDictBox[diffNumber] = ballDictBox[diffNumber] - 1 else: if 2 <= ballDictBox[diffNumber]: pairCount = pairCount + 1 ballDictBox[diffNumber] = ballDictBox[diffNumber] - 2 answer = pairCount return answer if __name__ == "__main__": n_ballCount = int(input()) a_ballDatas = list((map(int, input().split(" ")))) solution = maxCountPair(n_ballCount, a_ballDatas) print(solution)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s921526563
Runtime Error
p03200
Input is given from Standard Input in the following format: S
ball_num = int(input()) num_data = list(map(int, input().split())) ans = 0 def check_beki(num1, num2): data = num1 + num2 while 1: data1 = data % 2 data = int(data / 2) if data1 == 1: return 0 elif num1 + num2 >= 1 and data == 1: return 1 def check_ans(ans_list, tasu_flg): global ans ans_kari = 0 for i in range(len(ans_list)): if check_beki(ans_list[i], 0) and tasu_flg[i] == 1: ans_kari += 1 if ans_kari > ans: ans = ans_kari def check(index, ans_list_ori, tasu_flg_ori): global ball_num, num_data ans_list = ans_list_ori.copy() tasu_flg = tasu_flg_ori.copy() # if len(ans_list) >= tree_num: # return # print(check_beki(3, 5)) if index < ball_num: for j in range(len(ans_list)): # print(ans_list[j], num_data[index]) if check_beki(ans_list[j], num_data[index]) and tasu_flg[j] == 0: # print('yyy') ans_list[j] += num_data[index] tasu_flg[j] = 1 check(index + 1, ans_list, tasu_flg) tasu_flg[j] = 0 ans_list[j] -= num_data[index] # 新しく木を使う場合 ans_list.append(num_data[index]) tasu_flg.append(0) check(index + 1, ans_list, tasu_flg) tasu_flg.pop(-1) ans_list.pop(-1) else: # 以前よりも最少の気で作れたら最小値の更新 check_ans(ans_list, tasu_flg) def main(): global num_data check(1, [num_data[0]], [0]) print(ans) if __name__ == "__main__": main()
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s046012427
Wrong Answer
p03200
Input is given from Standard Input in the following format: S
a = input() print(min(a.count("B"), a.count("W")) * 2)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s509267474
Runtime Error
p03200
Input is given from Standard Input in the following format: S
s = input() ans = 0 def reverse(s,i): if s[i] == 'B' and s[i+1] == 'W': s[i] = 'W' s[i+1] = 'B' ans += 1 while True: s = ans for i in range(len(s) - 1): reverse(s,i) if s == ans: print(ans) break
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s243739167
Runtime Error
p03200
Input is given from Standard Input in the following format: S
osero = input(); len = len(osero); con_b = 0; con = 0; for(i =0; i<len, i++) { if(osero[i]='B') { con_b++; } if(osero[i] ='W') { con = con + con_b; } } print(con)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s402365982
Runtime Error
p03200
Input is given from Standard Input in the following format: S
import collections S = list(input()) c = collections.Counter(S) n = c["W"] s = 0 i = 0 while "B" in S[0:n]: if S[i] == "B" and S[i + 1] == "W": S[i] = "W" and S[i + 1] = "B" s += 1 i = i else: i += 1 print(s)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s602234614
Wrong Answer
p03200
Input is given from Standard Input in the following format: S
S = input() # 1. S を BB..BWW...W の塊 M に分割 # 2. 各塊 M に対して、右から n>=1 番目の B を塊の右端から n 番目に移動させるためには len(W_in_M) 回の移動が必要
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s806449726
Runtime Error
p03200
Input is given from Standard Input in the following format: S
import numpy as np S = input() b_num = S.count('B') w_num = len(S) - b_num end = 2**(w_num + 1) - 1 start = 0 for i in range(len(S)): if S[i] = 'W': start += np.power(2, i) print(np.log2(start / end))
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s048220051
Runtime Error
p03200
Input is given from Standard Input in the following format: S
bws = input() count = 0 def check(from, to): for i in range(from, to): if (bws[i] == 'B' && bws[i + 1] == "W"): count = count + 1 bws[i] = reverse(bws[i]) bws[i + 1] = reverse(bws[i + 1]) check(i - 2, to) return def reverse(c): return 'W' if c == 'B' else 'B' check(0, len(bws) - 2) print(count)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s522635479
Runtime Error
p03200
Input is given from Standard Input in the following format: S
s = input() c = 0 while True: l = s.index('W') - s.index('B') if l < 0: break c += l s = s.replace('W', 'B', 1) s = s[1:] print(c)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s616920133
Runtime Error
p03200
Input is given from Standard Input in the following format: S
s=input() n=len(s) cnt=0 for i in range(n): if s[i]=='W': cnt+=1 ans=0 for i in range(n): if s[i]=='W': cnt-- else: ans+=cnt print(ans)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s147437853
Runtime Error
p03200
Input is given from Standard Input in the following format: S
S = input() white = 0 total = 0 for i in range len(S): if S[i] == "W": total += (i - white) white ++ print(total)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s588572225
Runtime Error
p03200
Input is given from Standard Input in the following format: S
S = input() white = 0 total = 0 for i in range len(S): if S[i] == "W": total += (i - white) white += 1 print(total)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s986306016
Runtime Error
p03200
Input is given from Standard Input in the following format: S
a=list(input()) i=0 result=0 while len(a)>i: if a[i]=='B' and a[i+1]=='W': i=0 result=result+1 else : i++ print(result)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s298612615
Runtime Error
p03200
Input is given from Standard Input in the following format: S
s = input() n =len(s) res = 0 ans = 0 for i in range(n): if s[i] == 'B': res+=1AC else: ans+=res print(ans)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s619807575
Runtime Error
p03200
Input is given from Standard Input in the following format: S
S = str(input()) count = 0; for i in range(100000) count=count+S.count('BW'); S = S.replace('BW','WB'); if 'BW' not in S:break; print(count)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s650044572
Runtime Error
p03200
Input is given from Standard Input in the following format: S
print(TODO)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s044857870
Runtime Error
p03200
Input is given from Standard Input in the following format: S
S=input()[::-1] ans,tmp=0,0 for i in S: if i=='W' tmp+=1 else: ans+=tmp print(ans)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s079904265
Runtime Error
p03200
Input is given from Standard Input in the following format: S
S = array(input()) print(S)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s393172506
Runtime Error
p03200
Input is given from Standard Input in the following format: S
S=list(input()) a=0 for i in range(len(S): if S[i]=='W': a+=L[:i].count('B') print(a)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s592024629
Wrong Answer
p03200
Input is given from Standard Input in the following format: S
print(0)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s540999450
Accepted
p03200
Input is given from Standard Input in the following format: S
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from heapq import heapify, heappop, heappush def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def S_MAP(): return map(str, input().split()) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") mod = 10**9 + 7 S = input() N = len(S) tmp = 0 ans = 0 A = 0 B = 0 b_num = 0 for i in range(1, N + 1): if S[i - 1] == "B": b_num += 1 A += i all_wa = N * (N + 1) // 2 B = all_wa - (N - b_num) * (N - b_num + 1) // 2 print(B - A)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s727151510
Accepted
p03200
Input is given from Standard Input in the following format: S
def query_sum(bit, idx): sum_ = 0 while idx > 0: sum_ += bit[idx] idx -= idx & -idx return sum_ def add_sum(bit, idx, value): """ add value to a[i]. """ while idx <= len(bit): bit[idx] += value idx += idx & -idx S = input() bit = [0] * (len(S) + 1000) num_whites = 0 for i, char in enumerate(S, start=1): if char == "W": add_sum(bit, i, 1) num_whites += 1 num_flips = 0 for i, char in enumerate(S, start=1): if char == "B": this_num_flips = num_whites - query_sum(bit, i) num_flips += this_num_flips print(num_flips)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s089823094
Accepted
p03200
Input is given from Standard Input in the following format: S
s = list(str(input())) sm = [1 if s[i] == "B" else 0 for i in range(len(s))] smr = list(reversed(sm)) t = [] for i in range(len(s)): if smr[i] == 1: t.append(i) u = [i for i in range(len(t))] v = [t[i] - u[i] for i in range(len(t))] ans = sum(v) print(ans)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
Print the maximum possible number of times the operation can be performed. * * *
s485548433
Wrong Answer
p03200
Input is given from Standard Input in the following format: S
S = input() l = list(S) count = 0 end = False while end != True: for i in range(len(l) - 1): temp_count = 0 if l[i] == "B" and l[i + 1] == "W": l[i] = "W" l[i + 1] = "B" count += 1 temp_count += 1 if temp_count == 0: end = True print(count)
Statement There are N Reversi pieces arranged in a row. (A _Reversi piece_ is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the following operation: * Choose i (1 \leq i < N) such that the i-th piece from the left is showing black and the (i+1)-th piece from the left is showing white, then flip both of those pieces. That is, the i-th piece from the left is now showing white and the (i+1)-th piece from the left is now showing black. Find the maximum possible number of times this operation can be performed.
[{"input": "BBW", "output": "2\n \n\nThe operation can be performed twice, as follows:\n\n * Flip the second and third pieces from the left.\n * Flip the first and second pieces from the left.\n\n* * *"}, {"input": "BWBWBW", "output": "6"}]
If the assignment is possible, print `POSSIBLE`; otherwise, print `IMPOSSIBLE`. * * *
s074709213
Wrong Answer
p03650
Input is given from Standard Input in the following format: N p_1 p_2 ... p_N
# F N = int(input()) p_list = list(map(int, input().split())) # usagi to kame # start from 1 usagi = 1 kame = 1 def back(i): return p_list[i - 1] usagi = back(back(usagi)) kame = back(kame) while usagi != kame: usagi = back(back(usagi)) kame = back(kame) # begin loop # length of loop L = 1 usagi = back(back(usagi)) kame = back(kame) while usagi != kame: usagi = back(back(usagi)) kame = back(kame) L += 1 if L % 2 == 0: print("POSSIBLE") else: print("IMPOSSIBLE")
Statement There is a directed graph with N vertices and N edges. The vertices are numbered 1, 2, ..., N. The graph has the following N edges: (p_1, 1), (p_2, 2), ..., (p_N, N), and the graph is weakly connected. Here, an edge from Vertex u to Vertex v is denoted by (u, v), and a weakly connected graph is a graph which would be connected if each edge was bidirectional. We would like to assign a value to each of the vertices in this graph so that the following conditions are satisfied. Here, a_i is the value assigned to Vertex i. * Each a_i is a non-negative integer. * For each edge (i, j), a_i \neq a_j holds. * For each i and each integer x(0 ≤ x < a_i), there exists a vertex j such that the edge (i, j) exists and x = a_j holds. Determine whether there exists such an assignment.
[{"input": "4\n 2 3 4 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {0, 1, 0, 1} or {a_i} = {1, 0, 1, 0}.\n\n* * *"}, {"input": "3\n 2 3 1", "output": "IMPOSSIBLE\n \n\n* * *"}, {"input": "4\n 2 3 1 1", "output": "POSSIBLE\n \n\nThe assignment is possible: {a_i} = {2, 0, 1, 0}.\n\n* * *"}, {"input": "6\n 4 5 6 5 6 4", "output": "IMPOSSIBLE"}]