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 |
|---|---|---|---|---|---|---|---|
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s910604886 | Runtime Error | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | n, m, k = map(int, input().split())
# if n*m%2 == 0:
# if k%2 == 0 and k >= min(n, m):
# ans = 1
# else:
# ans = 0
# else:
# ans = 1
# if ans:
# print("Yes")
# else:
# print("No")
n, m, K = map(int, input().split())
print(
"YNeos"[
all(
k * m - K + l * n - k * l * 2 for k in range(n + 1) for l in range(m + 1)
) :: 2
]
)
| Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s265913603 | Runtime Error | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | h,w=map(int,input().split())
a,l=[list(input())for i in range(h)],[0]*26
for i in a:
for j in i:l[ord(j)-97]+=1
o,t,f=(h//2)*(w//2),(h//2)*(w%2)+(w//2)*(h%2),(h%2)*(w%2)
for i in l:
while o and i>3:o-=1;i-=4
while t and i>1:t-=1i-=2
f-=i
print("Yes"if o==t==f==0else"No") | Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s253699485 | Wrong Answer | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | print("Yes")
| Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s815075729 | Accepted | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | mod = 10**9 + 7
mod2 = 2**61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right
_NUMINT_ALL = list(range(10))
def main():
ans = solve()
if ans in [True, False]:
YesNo(ans)
elif ans is not None:
print(ans)
def solve():
H, W = iip(False)
A = []
for i in range(H):
A.extend([i for i in input()])
d = count_elements(A)
a = 0
b = 0
for i in d.values():
if i % 4 == 1:
a += 1
elif i % 4 == 2:
b += 1
elif i % 4 == 3:
a += 1
b += 1
ans = True
h = H % 2 == 0
w = W % 2 == 0
# print(a, b)
if h and w:
if a == 0 and b == 0:
return True
else:
return False
elif w:
if b <= W / 2 and a == 0:
return True
else:
return False
elif h:
if b <= H / 2 and a == 0:
return True
else:
return False
else:
if b <= (H + W) / 2 - 1 and a <= 1:
return True
else:
return False
#####################################################ライブラリ集ここから
def iip(listed=True, num_only=True): # 数字のinputをlistで受け取る
if num_only:
ret = [int(i) for i in input().split()]
else:
ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]
if len(ret) == 1 and not listed:
return ret[0]
return ret
def saidai_kouyakusuu(A): # 最大公約数
l = len(A)
while True:
m = min(A)
mx = max(A)
if m == mx:
return m
for i in range(l):
if A[i] % m == 0:
A[i] = m
else:
A[i] %= m
def sort_tuples(l, index): # タプルのリストを特定のインデックスでソートする
if isinstance(l, list):
l.sort(key=lambda x: x[index])
return l
else:
l = list(l)
return sorted(l, key=lambda x: x[index])
def count_elements(l): # リストの中身の個数を種類分けして辞書で返す
d = {}
for i in l:
if i in d:
d[i] += 1
else:
d[i] = 1
return d
def safeget(
l, index, default="exception"
): # listの中身を取り出す時、listからはみ出たり
if index >= len(l): # マイナスインデックスになったりするのを防ぐ
if default == "exception":
raise Exception(
"".join(
[
"safegetに不正な値 ",
index,
"が渡されました。配列の長さは",
len(l),
"です",
]
)
)
else:
return default
elif index < 0:
if default == "exception":
raise Exception(
"".join(
[
"safegetに不正な値 ",
index,
"が渡されました。負の値は許可されていません",
]
)
)
else:
return default
else:
return l[index]
def iipt(
l, listed=False, num_only=True
): # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
ret = []
for i in range(l):
ret.append(iip(listed=listed, num_only=num_only))
return ret
def sortstr(s): # 文字列をソートする
return "".join(sorted(s))
def iip_ord(startcode="a"): # 文字列を数字の列に変換する(数字と文字は1:1対応)
if isinstance(startcode, str):
startcode = ord(startcode)
return [ord(i) - startcode for i in input()]
def YesNo(s): # TrueFalseや1, 0をYesNoに変換する
if s:
print("Yes")
else:
print("No")
def fprint(s): # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
for i in s:
print(i)
def bitall(N): # ビット全探索用のインデックスを出力
ret = []
for i in range(2**N):
a = []
for j in range(N):
a.append(i % 2)
i //= 2
ret.append(a)
return ret
def split_print_space(s): # リストの中身をスペース区切りで出力する
print(" ".join([str(i) for i in s]))
def split_print_enter(s): # リストの中身を改行区切りで出力する
print("\n".join([str(i) for i in s]))
def soinsuu_bunkai(n): # 素因数分解
ret = []
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
n //= i
ret.append(i)
if i > n:
break
if n != 1:
ret.append(n)
return ret
def conbination(n, r, mod, test=False): # nCrをmodを使って計算する
if n <= 0:
return 0
if r == 0:
return 1
if r < 0:
return 0
if r == 1:
return n
ret = 1
for i in range(n - r + 1, n + 1):
ret *= i
ret = ret % mod
bunbo = 1
for i in range(1, r + 1):
bunbo *= i
bunbo = bunbo % mod
ret = (ret * inv(bunbo, mod)) % mod
if test:
# print(f"{n}C{r} = {ret}")
pass
return ret
def inv(n, mod): # modnにおける逆元を計算
return power(n, mod - 2)
def power(n, p, mod_=mod): # 繰り返し二乗法でn**p % modを計算
if p == 0:
return 1
if p % 2 == 0:
return (power(n, p // 2, mod_) ** 2) % mod_
if p % 2 == 1:
return (n * power(n, p - 1, mod_)) % mod_
if __name__ == "__main__":
main()
| Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s717841574 | Accepted | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | import sys
import collections
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
def main():
H, W = [int(x) for x in input().split()]
A = [input().strip() for _ in range(H)]
c = collections.Counter()
for a in A:
for aa in a:
c[aa] += 1
four_cnt = (H // 2) * (W // 2)
two_cnt = (H % 2) * (W // 2) + (W % 2) * (H // 2)
one_cnt = (H % 2) * (W % 2)
for k in c.keys():
if c[k] >= 4:
q, r = divmod(c[k], 4)
mi = min(four_cnt, q)
c[k] -= mi * 4
four_cnt -= mi
for k in c.keys():
if c[k] >= 2:
q, r = divmod(c[k], 2)
mi = min(two_cnt, q)
c[k] -= mi * 2
two_cnt -= mi
for k in c.keys():
if c[k] >= 1:
q, r = divmod(c[k], 1)
mi = min(one_cnt, q)
c[k] -= mi * 1
one_cnt -= mi
if sum([four_cnt, two_cnt, one_cnt]) == 0:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
| Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s255285077 | Accepted | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | n, m = [int(c) for c in input().split(" ")]
mx = [input() for _ in range(n)]
table = [[0] * m for _ in range(n)]
counter = 0
for i in range(n):
for j in range(m):
if table[i][j]:
continue
counter += 1
# print("Set {} for ({},{}), ({},{}), ({},{}), ({},{}).".format(
# counter, i, j, n-i-1, j, i, m-j-1, n-i-1, m-j-1
# ))
table[i][j] = table[n - i - 1][j] = table[i][m - j - 1] = table[n - i - 1][
m - j - 1
] = counter
# print(table)
cnt_need = [0] * counter
cnt_had = [0] * 26
for i in range(n):
for j in range(m):
cnt_need[table[i][j] - 1] += 1
cnt_had[ord(mx[i][j]) - ord("a")] += 1
cnt_need.sort()
cnt1, cnt2, cnt4 = [0] * 3
for cnt in cnt_need:
if cnt == 1:
cnt1 += 1
elif cnt == 2:
cnt2 += 1
elif cnt == 4:
cnt4 += 1
else:
raise RuntimeError("Unexpected count: {}".format(cnt))
assert cnt1 in [0, 1], "Unexpected count of units: {}".format(cnt1)
possible = 1
for had in cnt_had:
if had % 2:
if cnt1 > 0:
cnt1 -= 1
had -= 1
else:
possible = 0
if had % 4:
if cnt2 > 0:
cnt2 -= 1
had -= 2
else:
possible = 0
print("Yes" if possible else "No")
| Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s000796059 | Runtime Error | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | h, w, k = map(int, input().split())
ans = "No"
for i in range(h + 1):
for j in range(w + 1):
if i * j + (h - i) * (w - j) == k:
ans = "Yes"
print(ans)
| Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
If Snuke can create a matrix satisfying the condition, print `Yes`; otherwise,
print `No`.
* * * | s020617107 | Runtime Error | p03593 | Input is given from Standard Input in the following format:
H W
a_{11}a_{12}...a_{1W}
:
a_{H1}a_{H2}...a_{HW} | import collections
H,W = list(map(int , input().split()))
D = []
for j in range(H):
x=list(input())
D.extend(x)
s = len((set(D)))
c = collections.Counter(D)
Q = []
for i in range(s):
Q.append(c.most_common()[i][1])
if ((H*W)%2 == 1):
seigen = (H//2+1)*(W//2 +1)
q = 0
for k in range(s):
q += (Q[k] % 2)
if (q == 1)and(s<=seigen):
print("Yes")
else:
print("No")
elif ((H%2) == 0)and((W %2) ==0):
q = 0
for k in range(s):
q += (Q[k] % 4)
if ((s % 2) == 0)and(q == 0):
print("Yes")
else:
print("No")
else:
q = 0
if ((H%2) == 1):
seigen = (H//2+1)*W
elif ((W%2) == 1):
seigen = (W//2+1)*H
for k in range(s):
q += (Q[k] % 2)
if (q == 0)and(s<=seigen):
#print("Yes")
else:
#print("No")
| Statement
We have an H-by-W matrix. Let a_{ij} be the element at the i-th row from the
top and j-th column from the left. In this matrix, each a_{ij} is a lowercase
English letter.
Snuke is creating another H-by-W matrix, A', by freely rearranging the
elements in A. Here, he wants to satisfy the following condition:
* Every row and column in A' can be read as a palindrome.
Determine whether he can create a matrix satisfying the condition. | [{"input": "3 4\n aabb\n aabb\n aacc", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n abba\n acca\n abba\n \n\n* * *"}, {"input": "2 2\n aa\n bb", "output": "No\n \n\nIt is not possible to create a matrix satisfying the condition, no matter how\nwe rearrange the elements in A.\n\n* * *"}, {"input": "5 1\n t\n w\n e\n e\n t", "output": "Yes\n \n\nFor example, the following matrix satisfies the condition.\n\n \n \n t\n e\n w\n e\n t\n \n\n* * *"}, {"input": "2 5\n abxba\n abyba", "output": "No\n \n\n* * *"}, {"input": "1 1\n z", "output": "Yes"}] |
Print the minimum number of stones that needs to be recolored.
* * * | s622100089 | Wrong Answer | p03069 | Input is given from Standard Input in the following format:
N
S | print(sum(map(len, input().split("#")[1:])))
| Statement
There are N stones arranged in a row. Every stone is painted white or black. A
string S represents the color of the stones. The i-th stone from the left is
white if the i-th character of S is `.`, and the stone is black if the
character is `#`.
Takahashi wants to change the colors of some stones to black or white so that
there will be no white stone immediately to the right of a black stone. Find
the minimum number of stones that needs to be recolored. | [{"input": "3\n #.#", "output": "1\n \n\nIt is enough to change the color of the first stone to white.\n\n* * *"}, {"input": "5\n #.##.", "output": "2\n \n\n* * *"}, {"input": "9\n .........", "output": "0"}] |
Print the minimum number of stones that needs to be recolored.
* * * | s267338994 | Wrong Answer | p03069 | Input is given from Standard Input in the following format:
N
S | a = int(input())
b = input()
count = 0
ten_count = [0, 0]
if b[0] == "#":
ten_count[0] += 1
for i in range(1, a):
if b[i] == "#" and b[i - 1] == "#":
ten_count[0] += 1
elif b[i - 1] == "#" and b[i] == ".":
ten_count[1] += 1
if i == a - 1:
count = min(ten_count[0], ten_count[1])
elif b[i - 1] == "." and b[i] == ".":
ten_count[1] += 1
if i == a - 1:
count = min(ten_count[0], ten_count[1])
elif b[i - 1] == "." and b[i] == "#":
count = min(ten_count[0], ten_count[1])
ten_count[0] += 1
print(count)
| Statement
There are N stones arranged in a row. Every stone is painted white or black. A
string S represents the color of the stones. The i-th stone from the left is
white if the i-th character of S is `.`, and the stone is black if the
character is `#`.
Takahashi wants to change the colors of some stones to black or white so that
there will be no white stone immediately to the right of a black stone. Find
the minimum number of stones that needs to be recolored. | [{"input": "3\n #.#", "output": "1\n \n\nIt is enough to change the color of the first stone to white.\n\n* * *"}, {"input": "5\n #.##.", "output": "2\n \n\n* * *"}, {"input": "9\n .........", "output": "0"}] |
Print the minimum number of stones that needs to be recolored.
* * * | s091044977 | Wrong Answer | p03069 | Input is given from Standard Input in the following format:
N
S | stp = int(input())
s = [j for j in input()]
cut = ["#", "."]
b, ans = [], 0
ass = 0 if s.count(".") < s.count("#") else 1
for x, y in enumerate(s):
if y == "#":
b.append(x)
for i in reversed(b):
if i + 1 < stp:
if s[i + 1] == ".":
ans += 1
s[i] = cut[ass]
print(ans)
| Statement
There are N stones arranged in a row. Every stone is painted white or black. A
string S represents the color of the stones. The i-th stone from the left is
white if the i-th character of S is `.`, and the stone is black if the
character is `#`.
Takahashi wants to change the colors of some stones to black or white so that
there will be no white stone immediately to the right of a black stone. Find
the minimum number of stones that needs to be recolored. | [{"input": "3\n #.#", "output": "1\n \n\nIt is enough to change the color of the first stone to white.\n\n* * *"}, {"input": "5\n #.##.", "output": "2\n \n\n* * *"}, {"input": "9\n .........", "output": "0"}] |
Print the minimum number of stones that needs to be recolored.
* * * | s926452088 | Accepted | p03069 | Input is given from Standard Input in the following format:
N
S | n = int(input()) # 数値入�?
str = list(input()) # 一�?字ずつ格�?
dotto = str.count(".")
ans = dotto
syapu = 0
for i in range(0, n):
if str[i] == ".":
dotto -= 1
else:
syapu += 1
if dotto + syapu < ans:
ans = dotto + syapu
print(ans)
| Statement
There are N stones arranged in a row. Every stone is painted white or black. A
string S represents the color of the stones. The i-th stone from the left is
white if the i-th character of S is `.`, and the stone is black if the
character is `#`.
Takahashi wants to change the colors of some stones to black or white so that
there will be no white stone immediately to the right of a black stone. Find
the minimum number of stones that needs to be recolored. | [{"input": "3\n #.#", "output": "1\n \n\nIt is enough to change the color of the first stone to white.\n\n* * *"}, {"input": "5\n #.##.", "output": "2\n \n\n* * *"}, {"input": "9\n .........", "output": "0"}] |
Print the minimum number of stones that needs to be recolored.
* * * | s555535263 | Wrong Answer | p03069 | Input is given from Standard Input in the following format:
N
S | N = int(input())
S = input()
# . = しろ
# # = 黒
# #の横に.がないようにしたい
# #の横に.があったら#を.に変える
# or #の横に.があったら.を#に変える
# when do you replace now char to .
#
# テストケース
"""
9
.#.#.#.#.
"""
# => .....# = 2
def inorderReplace(S, N):
S = list(S)
cnt = 0
for i in range(N - 1):
nowChar = S[i]
nextChar = S[i + 1]
if nowChar == "#" and nextChar == ".":
cnt += 1
S[i + 1] = "#"
return cnt
def calcCount(S, N):
countingChar = S[0]
rst = []
count = 1
for s in S[1:]:
if countingChar == s:
count += 1
else:
rst.append((countingChar, count))
count = 1
countingChar = s
rst.append((countingChar, count))
return rst
def countRightChange(countingList):
# 全部を.に変えるコスト
cnt = 0
for elem in countingList:
if elem[0] == "#":
cnt += elem[1]
return cnt
def countLeftChange(countingList):
# 全部を#に変えるコスト
cnt = 0
for elem in countingList:
if elem[0] == ".":
cnt += elem[1]
return cnt
def calcPoint(countingList):
minVal = 9999999999999
for i in range(len(countingList)):
a = countRightChange(countingList[:i])
b = countLeftChange(countingList[i:])
if minVal > a + b:
minVal = a + b
return minVal
# cnt = inorderReplace(S , N)
countingList = calcCount(S, N)
cnt2 = calcPoint(countingList)
print(cnt2)
| Statement
There are N stones arranged in a row. Every stone is painted white or black. A
string S represents the color of the stones. The i-th stone from the left is
white if the i-th character of S is `.`, and the stone is black if the
character is `#`.
Takahashi wants to change the colors of some stones to black or white so that
there will be no white stone immediately to the right of a black stone. Find
the minimum number of stones that needs to be recolored. | [{"input": "3\n #.#", "output": "1\n \n\nIt is enough to change the color of the first stone to white.\n\n* * *"}, {"input": "5\n #.##.", "output": "2\n \n\n* * *"}, {"input": "9\n .........", "output": "0"}] |
Print the minimum number of stones that needs to be recolored.
* * * | s197058623 | Wrong Answer | p03069 | Input is given from Standard Input in the following format:
N
S | inp_num = int(input())
inp = input()
w1 = 0
b1 = 0
bf = 0
wf = 0
for i in range(len(inp)):
if inp[i] == "#" and wf == 0:
wf = 1
b1 = b1 + 1
elif inp[i] == "#" and wf == 1:
b1 = b1 + 1
elif inp[i] == "." and wf == 1:
w1 = w1 + 1
w2 = 0
b2 = 0
for i in range(len(inp)):
if inp[len(inp) - i - 1] == "." and bf == 0:
bf = 1
w2 = w2 + 1
elif inp[len(inp) - i - 1] == "#" and bf == 1:
b2 = b2 + 1
elif inp[len(inp) - i - 1] == "." and bf == 1:
w2 = w2 + 1
line = [b1, w1, b2, w2]
# print(line)
print(min(line))
| Statement
There are N stones arranged in a row. Every stone is painted white or black. A
string S represents the color of the stones. The i-th stone from the left is
white if the i-th character of S is `.`, and the stone is black if the
character is `#`.
Takahashi wants to change the colors of some stones to black or white so that
there will be no white stone immediately to the right of a black stone. Find
the minimum number of stones that needs to be recolored. | [{"input": "3\n #.#", "output": "1\n \n\nIt is enough to change the color of the first stone to white.\n\n* * *"}, {"input": "5\n #.##.", "output": "2\n \n\n* * *"}, {"input": "9\n .........", "output": "0"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s015386871 | Accepted | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | N = int(input())
X = [int(_) for _ in input().split()]
Y = [int(_) for _ in input().split()]
def calc_dist_mink(list_x, list_y, p):
list_xy = [abs(list_x[i] - list_y[i]) for i in range(len(list_x))]
list_xy_p = [i**p for i in list_xy]
ans = sum(list_xy_p) ** (1 / p)
return ans
list_ans = []
ans_1 = calc_dist_mink(X, Y, 1)
list_ans.append(ans_1)
ans_2 = calc_dist_mink(X, Y, 2)
list_ans.append(ans_2)
ans_3 = calc_dist_mink(X, Y, 3)
list_ans.append(ans_3)
ans_4 = max([abs(X[i] - Y[i]) for i in range(N)])
list_ans.append(ans_4)
for ans in list_ans:
print(f"{ans:.5f}")
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s906703734 | Accepted | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | mark_list = [1, 2, 3, "∞"]
n = int(input())
element_x = [int(i) for i in input().split()]
element_y = [int(l) for l in input().split()]
for p in mark_list:
if p == 1:
m_distance = 0
for o in range(n):
x = element_x[o]
y = element_y[o]
m_distance += abs(x - y)
print(m_distance)
if p == 2:
y_distance = 0
y_distance2 = 0
for m in range(n):
x = element_x[m]
y = element_y[m]
y_distance2 += pow(abs(x - y), 2)
y_distance = pow(y_distance2, 0.5)
print(y_distance)
if p == 3:
third_distance = 0
third_distance2 = 0
for q in range(n):
x = element_x[q]
y = element_y[q]
third_distance2 += pow(abs(x - y), 3)
third_distance = pow(third_distance2, 1 / 3)
print(third_distance)
if p == "∞":
c_distance = 0
difference = 0
for r in range(n):
x = element_x[r]
y = element_y[r]
difference = abs(x - y)
if difference > c_distance:
c_distance = difference
print(c_distance)
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s270307004 | Accepted | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | n = int(input())
x = input().strip().split()
y = input().strip().split()
x = [float(s) for s in x]
y = [float(s) for s in y]
m_d = 0
y_d = 0
u_d = 0
mmm = [0] * n
md = 0
for i in range(n):
md = abs(x[i] - y[i])
m_d += md
y_d += md**2
u_d += md**3
mmm[i] = md
print(m_d)
print(y_d**0.5)
print(u_d ** (1 / 3))
print(max(mmm))
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s671423292 | Accepted | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | n = int(input())
x_l = list(map(int, input().split()))
y_l = list(map(int, input().split()))
p1 = sum(abs(x_l[i]-y_l[i]) for i in range(n))
p2 = (sum(abs(x_l[i]-y_l[i])**2 for i in range(n)))**0.5
p3 = (sum(abs(x_l[i]-y_l[i])**3 for i in range(n)))**(1/3)
p_max = max(abs(x_l[i]-y_l[i]) for i in range(n))
print(p1, p2, p3, p_max)
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s760803766 | Accepted | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | # Problem - ミンコフスキー距離
def minkowski(x_list, y_list, p):
tmp_ans = 0
for i in range(len(x_list)):
tmp = abs(x_list[i] - y_list[i]) ** p
tmp_ans += tmp
tmp_ans = tmp_ans ** (1 / p)
return tmp_ans
def minkowski_max(x_list, y_list):
tmp_ans = 0
for i in range(len(x_list)):
tmp = abs(x_list[i] - y_list[i])
tmp_ans = max(tmp_ans, tmp)
return tmp_ans
# input
n = int(input())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
# output
print(minkowski(x_list, y_list, 1))
print(minkowski(x_list, y_list, 2))
print(minkowski(x_list, y_list, 3))
print(minkowski_max(x_list, y_list))
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s426517566 | Accepted | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | input()
P1 = []
P2 = []
P3 = []
for a, b in zip(map(int, input().split()), map(int, input().split())):
t = abs(a - b)
P1.append(t)
P2.append(t**2)
P3.append(t**3)
print("{:f}".format(sum(P1)))
print(sum(P2) ** (1 / 2))
print(sum(P3) ** (1 / 3))
print("{:f}".format(max(P1)))
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s830438206 | Wrong Answer | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | n=int(input())
s_str=[]
for i in range(2):
s_str.append(input().split())
s_int=[]
for i in s_str:
s_int.append([int(s) for s in i])
manh=0
yu=0
p_3=0
che=[]
for i in range(n):
manh+=abs(s_int[0][i]-s_int[1][i])
yu+=(s_int[0][i]-s_int[1][i])**2
p_3+=(s_int[0][i]-s_int[1][i])**3
che.append(abs(s_int[0][i]-s_int[1][i]))
print(manh)
print(yu**(1/2))
print(p_3**(1/3))
print(max(che))
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
Print the distance where $p = 1, 2, 3$ and $\infty$ in a line respectively.
The output should not contain an absolute error greater than 10-5. | s134541276 | Accepted | p02382 | In the first line, an integer $n$ is given. In the second and third line, $x =
\\{x_1, x_2, ... x_n\\}$ and $y = \\{y_1, y_2, ... y_n\\}$ are given
respectively. The elements in $x$ and $y$ are given in integers. | import math
deg = int(input())
li_x = list(map(int, input().split()))
li_y = list(map(int, input().split()))
p1_dis = 0.0
p2_dis = 0.0
p2_temp = 0.0
p3_dis = 0.0
p3_temp = 0.0
p4_dis = 0.0
p4_temp = []
for i in range(deg):
p1_dis += math.fabs(li_x[i] - li_y[i])
p2_temp += (li_x[i] - li_y[i]) ** 2.0
p3_temp += math.fabs(li_x[i] - li_y[i]) ** 3.0
p4_temp.append(math.fabs(li_x[i] - li_y[i]))
p2_dis = math.sqrt(p2_temp)
p3_dis = math.pow(p3_temp, 1.0 / 3.0)
p4_dis = max(p4_temp)
print("{0:.6f}".format(p1_dis))
print("{0:.6f}".format(p2_dis))
print("{0:.6f}".format(p3_dis))
print("{0:.6f}".format(p4_dis))
| Distance II
Your task is to calculate the distance between two $n$ dimensional vectors $x
= \\{x_1, x_2, ..., x_n\\}$ and $y = \\{y_1, y_2, ..., y_n\\}$.
The Minkowski's distance defined below is a metric which is a generalization
of both the Manhattan distance and the Euclidean distance.
\\[ D_{xy} = (\sum_{i=1}^n |x_i - y_i|^p)^{\frac{1}{p}} \\]
It can be the Manhattan distance
\\[ D_{xy} = |x_1 - y_1| + |x_2 - y_2| + ... + |x_n - y_n| \\]
where $p = 1 $.
It can be the Euclidean distance
\\[ D_{xy} = \sqrt{(|x_1 - y_1|)^{2} + (|x_2 - y_2|)^{2} + ... + (|x_n -
y_n|)^{2}} \\]
where $p = 2 $.
Also, it can be the Chebyshev distance
\\[ D_{xy} = max_{i=1}^n (|x_i - y_i|) \\]
where $p = \infty$
Write a program which reads two $n$ dimensional vectors $x$ and $y$, and
calculates Minkowski's distance where $p = 1, 2, 3, \infty$ respectively. | [{"input": "1 2 3\n 2 0 4", "output": ".000000\n 2.449490\n 2.154435\n 2.000000"}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s969889861 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | N, M = map(int, input().split())
li = []
for i in range(M):
li.append(list(map(int, input().split())))
ans = [0] * (N + 1)
print(ans)
que = [1]
print(li)
def saiki():
global que
global li
global ans
print(que)
q = que.pop(0)
count = 0
while True:
if count == len(li):
break
print(li)
print(count)
if li[count][0] == q and ans[li[count][1]] == 0:
que.append(li[count][1])
ans[li[count][1]] = q
li.pop(count)
elif li[count][1] == q and ans[li[count][0]] == 0:
que.append(li[count][0])
ans[li[count][0]] = q
li.pop(count)
else:
count += 1
if len(que) == 0:
for ai in ans:
if ai != 0:
print(ai)
else:
saiki()
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s871863262 | Accepted | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | from collections import defaultdict as dd
N, M = map(int, input().split())
A2B = dd(list)
B2A = dd(list)
for a in range(M):
A, B = input().split()
A2B[A].append(B)
B2A[B].append(A)
# 探索するノードの一覧
nodes_seek = set([str(x) for x in range(1, N + 1)])
# 探索したノードの一覧
disc_nodes = set([])
# 各ノードの最短経路を保管する辞書
shortest_path = dd(list)
# 各ノードの暫定の最短ホップ数を保管する辞書
shops = dd(int)
# 各ノードの最短経路における、手前のノードを記憶する辞書
sprev = dd(str)
# ノード1から順に探索
## ノード1に入った⇒ 隣接する部屋のリスト一覧を取得
nxt_nodes = dd(list)
nxt_nodes["1"] = A2B["1"]
nxt_nodes["1"] += B2A["1"]
## ノード1への距離を0として記入
shops["1"] = 0
shortest_path["1"] = []
sprev["1"] = []
disc_nodes.add("1")
# 取得した隣接リストを使う(が、幅優先で考える)
count = 0
while len(disc_nodes) < N:
# 現在の隣接リストをあたり、次の隣接ノードのリストを作成する
nnxt_nodes = dd(list)
for key in nxt_nodes.keys():
## 現在の隣接リストから、すでに見つかったノードを省く
tnxt_nodes = set(nxt_nodes[key]) - disc_nodes
for n in tnxt_nodes:
# 現在の隣接リストで見つかったノードについて、
## 手前のノードとして、現在のKeyを記入
shops[n] = shops[key] + 1
sprev[n] = str(key)
## 探索済みノードとして追記
disc_nodes.add(n)
## 次の隣接リストを取得、記載する
nnxt_nodes[n] += A2B[n]
nnxt_nodes[n] += B2A[n]
nxt_nodes = nnxt_nodes
# count += 1
# if count >100:
# break
ans = "Yes"
# print(" ----------------------- ")
# for i in range(1,N+1):
# print("i:",i)
# print("-- shops --")
# print(shops[str(i)])
# print("-- sprev --")
# print(sprev[str(i)])
# print("disc_nodes")
# print(disc_nodes)
for i in range(1, N + 1):
if i == 1:
print(ans)
else:
# print(i,sprev[str(i)])
print(sprev[str(i)])
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s560475610 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | import heapq
from collections import deque
class Graph:
def __init__(self, v, edgelist, w_v=None, directed=False):
super().__init__()
self.v = v
self.w_e = [{} for _ in [0] * self.v]
self.neighbor = [[] for _ in [0] * self.v]
self.w_v = w_v
self.directed = directed
for i, j, w in edgelist:
self.w_e[i][j] = w
self.neighbor[i].append(j)
def dijkstra(self, v_n):
d = [float("inf")] * self.v
d[v_n] = 0
prev = [-1] * self.v
queue = []
for i, d_i in enumerate(d):
heapq.heappush(queue, (d_i, i))
while len(queue) > 0:
d_u, u = queue.pop()
if d[u] < d_u:
continue
for v in self.neighbor[u]:
alt = d[u] + self.w_e[u][v]
if d[v] > alt:
d[v] = alt
prev[v] = u
heapq.heappush(queue, (alt, v))
return d, prev
def warshallFloyd(self):
d = [[10**18] * self.v for _ in [0] * self.v]
for i in range(self.v):
d[i][i] = 0
for i in range(self.v):
for j in self.neighbor[i]:
d[i][j] = self.w_e[i][j]
for i in range(self.v):
for j in self.neighbor[i]:
d[i][j] = self.w_e[i][j]
for k in range(self.v):
for i in range(self.v):
for j in range(self.v):
check = d[i][k] + d[k][j]
if d[i][j] > check:
d[i][j] = check
return d
def prim(self):
gb = GraphBuilder(self.v, self.directed)
queue = []
for i, w in self.w_e[0].items():
heapq.heappush(queue, (w, 0, i))
rest = [True] * self.v
rest[0] = False
while len(queue) > 0:
w, i, j = heapq.heappop(queue)
if rest[j]:
gb.addEdge(i, j, w)
rest[j] = False
for k, w in self.w_e[j].items():
if rest[k]:
heapq.heappush(queue, (w, j, k))
return gb
def bfs(self, vartex=0):
todo = [True] * self.v
queue = deque([vartex])
while len(queue) > 0:
v = queue.popleft
todo[v] = False
yield v
for v_i in self.neighbor[v]:
if todo[v_i]:
queue.append(v_i)
def dfs(self, vartex=0):
seen = [False] * self.v
def recdfs(v):
seen[vartex] = True
for next_v in self.neighbor[vartex]:
if seen[next_v]:
continue
recdfs(next_v)
class Tree:
def __init__(self, v, e):
pass
class GraphBuilder:
def __init__(self, v, directed=False, edge=None, weights=None):
self.v = v
self.directed = directed
self.edge = []
self.weights = []
if edge is not None:
self.addEdges(edge)
if weights is not None:
self.addVartex(weights)
def addEdge(self, i, j, w=1):
if not self.directed:
self.edge.append((j, i, w))
self.edge.append((i, j, w))
def addEdges(self, edgelist, weight=True):
if weight:
if self.directed:
for i, j, w in edgelist:
self.edge.append((i, j, w))
else:
for i, j, w in edgelist:
self.edge.append((i, j, w))
self.edge.append((j, i, w))
else:
if self.directed:
for i, j in edgelist:
self.edge.append((i, j, 1))
else:
for i, j in edgelist:
self.edge.append((i, j, 1))
self.edge.append((j, i, 1))
def addVartex(self, weights):
if len(weights) != self.v:
return
self.weights.extend(weights)
def addAdjMat(self, mat):
for i, mat_i in enumerate(mat):
for j, w in enumerate(mat_i):
self.edge.append((i, j, w))
def buildTree(self):
pass
def buildGraph(self):
return Graph(self.v, self.edge, directed=self.directed)
def main():
n, m = tuple([int(t) for t in input().split()])
edge = []
for i in range(m):
a, b = tuple([int(t) for t in input().split()])
edge.append((a - 1, b - 1, 1))
gb = GraphBuilder(n, edge=edge)
g = gb.buildGraph()
queue = deque([0])
root = [-1] * n
checked = [False] * n
while len(queue) > 0:
p = queue.popleft()
if checked[p]:
continue
checked[p] = True
for q in g.neighbor[p]:
root[q] = p + 1
queue.append(q)
if all(checked):
print("Yes")
for i in root[1:]:
print(i)
if __name__ == "__main__":
main()
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s866853724 | Accepted | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | (n, m), *t = [map(int, t.split()) for t in open(0)]
(*e,) = eval("[]," * -~n)
for a, b in t:
e[a] += (b,)
e[b] += (a,)
q = [1]
d = [0] * -~n
for v in q:
for w in e[v]:
if d[w] < 1:
d[w] = v
q += (w,)
print("Yes", *d[2:])
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s138610114 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | n,m = map(int,input().split())
d = {i:set([]) for i in range(1,n+1)}
e={i:0 for i in range(1,n+1)}
s={i for i in range(1,n+1)}
for _ in range(m):
a,b = map(int,input().split())
d[a]|={b}
d[b]|={a}
s-={a,b}
if len(s)!=0:
print("No")
else:
print("Yes",d)
s={1}
point=0
while(n>0):
t=set([])
point+=1
for i in s:
for j in d[i]:
if e[j]==0:
e[j]=point
t|={j}
n-=1
s=t
for k,v in e.items():
if k>0:
print(v) | Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s127860335 | Accepted | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | # ダイクストラ法で部屋1から各部屋への最短経路を出す
import queue
n, m = list(map(int, input().split()))
edges = [list(map(int, input().split())) for _ in range(m)]
# 隣接行列の作成
edges_dict = {}
for edge in edges:
a, b = edge
if a not in edges_dict:
edges_dict[a] = [b]
else:
edges_dict[a].append(b)
if b not in edges_dict:
edges_dict[b] = [a]
else:
edges_dict[b].append(a)
# 定数
COST = 1
INF = 1e10
# i=0は未使用, i>0は部屋iへの最短距離
dist_list = [INF] * (n + 1)
# i=0は未使用, i>0は部屋iの最短経路がたどる次の部屋 = 道しるべ
prev_list = [None] * (n + 1)
q = queue.PriorityQueue()
# 初期化
q.put((0, 1)) # (最短経路, 部屋番号)
dist_list[1] = 0
prev_list[1] = 1
while not q.empty():
min_dist, v = q.get()
# print("min_dist={}, v={}".format(min_dist, v))
if dist_list[v] < min_dist:
# print("waste")
continue
# print("check edges: ", edges_dict[v])
for w in edges_dict[v]:
cost = dist_list[v] + COST
if dist_list[w] > cost:
# print("push path {} -> {}; cost {}; path {}".format(v, w, cost, prev_list[v]))
dist_list[w] = cost
prev_list[w] = v # prev_list[v]
q.put((cost, w))
print("Yes")
# print(edges_dict)
# print(dist_list)
# print(prev_list)
for v in prev_list[2:]:
print(v)
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s094023659 | Runtime Error | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | N, M = map(int, input().split())
l = []
v = [-1] * M
v[0] = 0
for i in range(M):
a, b = list(map(int, input().strip().split()))
if a > b:
c = a
a = b
b = c
l.append([a, b])
# print(a, b)
l.sort()
for i in range(M):
room_1 = l[i][0] - 1
room_2 = l[i][1] - 1
if v[room_2] == -1:
v[room_2] = v[room_1] + 1
elif v[room_1] < v[room_2]:
v[room_2] = v[room_1] + 1
elif v[room_1] > v[room_2]:
v[room_1] = v[room_2] + 1
# print(l)
# print(v)
print("Yes")
for i in v:
if i != 0:
print(i)
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s887671885 | Runtime Error | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | n, m = map(int, input().split())
L = [[] for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
A = a - 1
B = b - 1
L[A].append(B)
L[B].append(A)
BFS = list()
BFS.append([0])
ans = [[] for i in range(n - 1)]
while [] in ans:
BFS.append([])
for i in BFS[-2]:
for j in L[i]:
BFS[-1].append(j)
ans[j - 1].append(i + 1)
L[j].remove(i)
for k in range(len(ans)):
print(ans[k][0])
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s840499156 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | n, m = map(int, input().split())
lis = [list(map(int, input().split())) for i in range(m)]
path = [[] for i in range(n)]
for a, b in lis:
path[a - 1].append(b - 1)
path[b - 1].append(a - 1)
gone = [0] * n
gone[0] = 1
ans = [-1] * n
now = {0}
while now:
a = now.pop()
for go in path[a]:
if gone[go] == 0:
gone[go] = 1
ans[go] = a
now.add(go)
print("Yes")
for num in ans:
if num != -1:
print(num + 1)
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s876543284 | Accepted | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | import sys
sys.setrecursionlimit(10**8)
def ii():
return int(sys.stdin.readline())
def mi():
return map(int, sys.stdin.readline().split())
def li():
return list(map(int, sys.stdin.readline().split()))
def li2(N):
return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j):
return [[ini] * i for i2 in range(j)]
def dp3(ini, i, j, k):
return [[[ini] * i for i2 in range(j)] for i3 in range(k)]
# import bisect #bisect.bisect_left(B, a)
# from collections import defaultdict #d = defaultdict(int) d[key] += value
# from collections import Counter # a = Counter(A).most_common()
# from itertools import accumulate #list(accumulate(A))
from collections import deque
N, M = mi()
# U = UnionFind(N)
rel = [[] for _ in range(N)]
mark = [-1] * N
flag = [0] * N
mark[0] = 0
l = deque([0])
"""
def dfs(s):
print(mark)
if rel[s]:
for num in rel[s]:
if mark[num] == -1:
mark[num] = s
for num in rel[s]:
if rel[num]:
dfs(num)
"""
for i in range(M):
s, t = mi()
s -= 1
t -= 1
rel[s].append(t)
rel[t].append(s)
# dfs(0)
flag[0] = 1
while l != deque([]):
a = l.popleft()
for num in rel[a]:
if not flag[num]:
mark[num] = a
flag[num] = 1
l.append(num)
if sum(flag) != N:
print("No")
exit()
print("Yes")
for i in range(1, N):
print(mark[i] + 1)
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s635944008 | Accepted | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | from collections import deque
def main():
n, m = [int(x) for x in input().split()]
corridors = [list() for _ in range(n)]
for _ in range(m):
a, b = [int(x) - 1 for x in input().split()]
corridors[a].append(b)
corridors[b].append(a)
qu = deque()
# dist = [-1] * n
ans = [None] * n
# initialize
qu.append(0)
ans[0] = 0
# search
while len(qu):
v = qu.popleft()
for new in corridors[v]:
if ans[new] is not None:
continue
# dist[new] = dist[v] + 1
ans[new] = v + 1
qu.append(new)
# for i, x in enumerate(ans):
# if i == 0:
# continue
# print('room', i+1, ':', x)
print("Yes")
for x in ans[1:]:
print(x)
if __name__ == "__main__":
main()
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s799614396 | Accepted | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | # coding: utf-8
def dijkstra(costs, s, t, INF=10**10):
"""
2020/04/11
https://atcoder.jp/contests/abc079/tasks/abc079_d
Parameters
----------
costs: list of list of int
e.g. [[-1, 4, 1, -1],
[ 4, -1, 5, -1],
[ 1, 5, -1, 6],
[-1, -1, 6, -1]]
"""
costs = [[c if c >= 0 else INF for c in row] for row in costs]
n_node = len(costs)
# adjacents = {}
# for i in range(n_node):
# adjacents[i] = set([j for j in range(n_node) if 0 < costs[i][j] < INF])
dist_from_s = [INF] * n_node
dist_from_s[s] = 0
checked = [] # nodes having fixed shortest distance
while True:
print(dist_from_s)
# not checked nodes (not fixed nodes)
nodes = [node for node in range(n_node) if node not in checked]
# find the node having minimum cost from s
# initialize
shortest_node, shortest_dist = nodes[0], dist_from_s[nodes[0]]
for node in nodes:
if dist_from_s[node] < shortest_dist:
shortest_node, shortest_dist = node, dist_from_s[node]
if shortest_node == t:
return dist_from_s[t]
checked.append(shortest_node) # fix
# not checked nodes (not fixed nodes)
nodes = [node for node in range(n_node) if node not in checked]
# update
for node in nodes:
dist_from_s[node] = min(
dist_from_s[shortest_node] + costs[shortest_node][node],
dist_from_s[node],
)
def main():
N, M = map(int, input().split())
A = [None] * M
B = [None] * M
for i in range(M):
A[i], B[i] = map(int, input().split())
A[i] -= 1
B[i] -= 1
edge_info = {i: [] for i in range(N)}
for i in range(M):
edge_info[A[i]].append(B[i])
edge_info[B[i]].append(A[i])
# dists = [None] * N
# dists[0] = 0
prenodes = [None] * N
prenodes[0] = 0
queue = [0]
queue_size = 1
queue_idx = 0
while True:
# 貪欲に
if queue_idx == queue_size:
break
x = queue[queue_idx]
queue_idx += 1
nexts = [y for y in edge_info[x] if prenodes[y] is None]
for node in nexts:
prenodes[node] = x
queue.append(node)
queue_size += 1
print("Yes")
for i in range(1, N):
print(prenodes[i] + 1)
main()
# print(main())
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s673882946 | Accepted | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | nm = input().split()
n = int(nm[0])
m = int(nm[1])
load = []
load_roomn = {}
for i in range(m):
l = list(map(lambda x: int(x), input().split()))
load.append(l)
# print(l)
if l[0] in load_roomn:
load_roomn[l[0]].append(i)
else:
load_roomn[l[0]] = [i]
if l[1] in load_roomn:
load_roomn[l[1]].append(i)
else:
load_roomn[l[1]] = [i]
# print(load)
# print(load_roomn)
visitCost = [10 ^ 5 + 1] * (n + 1) # 部屋が10^5個しかないのでこれがinfでいいはず
marker = [-1] * (n + 1)
marker[1] = 0
visitable = [1]
visited = []
visitednum = 1
# count = 0
while visitednum < n:
# count += 1
# 最短で行ける場所確認
visiting = visitable.pop(0)
# print("visit from " + str(visiting))
for i in load_roomn[visiting]:
if load[i][0] == visiting:
if marker[load[i][1]] == -1:
visitable.append(load[i][1])
marker[load[i][1]] = visiting
visitednum += 1
# print("visit" + str(load[i][1]))
elif load[i][1] == visiting:
if marker[load[i][0]] == -1:
visitable.append(load[i][0])
marker[load[i][0]] = visiting
visitednum += 1
# print("visit" + str(load[i][0]))
else:
print("error")
print("Yes")
for i in range(2, n + 1):
print(marker[i])
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s044506974 | Runtime Error | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | num_room, num_path = map(int, input().split())
room_paths_dict = {}
start_room_to_paths = set()
result = {}
for i in range(num_path):
a_room_num, b_room_num = map(int, input().split())
if a_room_num == 1:
start_room_to_paths.add(b_room_num)
continue
elif b_room_num == 1:
start_room_to_paths.add(a_room_num)
continue
result[a_room_num] = 0
result[b_room_num] = 0
if not room_paths_dict.get(a_room_num):
room_paths_dict[a_room_num] = set()
if not room_paths_dict.get(b_room_num):
room_paths_dict[b_room_num] = set()
room_paths_dict[a_room_num].add(b_room_num)
room_paths_dict[b_room_num].add(a_room_num)
def search(room_num):
targets = []
for next_room in room_paths_dict[room_num]:
if result[next_room] == 0:
result[next_room] = room_num
targets.append(room_num)
for t in targets:
search(t)
for start_room_to_path in start_room_to_paths:
result[start_room_to_path] = 1
search(start_room_to_path)
if 0 in result.values():
print("No")
else:
print("Yes")
for key in sorted(result.keys()):
print(result[key])
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s081753760 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | N,M=map(int,input().split())
A=[0]*M
B=[0]*M
for i in range(M):
A[i],B[i]=map(int,input().split())
list=[0]*N
mitisirube=[0]*N
dest=[0]*M
pren=0
def voiddelete(x):
i=len(x)-1
while(x[i]==0):
del x[i]
i-=1
return(x)
def voidcount(x):
for i in range(len(x)):
if(x[i]==0):
break
return(i)
def move(pren,n):
mitisirube[n-1]=pren
list[voidcount(list)]=n
dest=[0]*M
for i in range(M):
if(A[i]==n):
if(not B[i] in dest):
dest[voidcount(dest)]=B[i]
if(B[i]==n):
if(not A[i] in dest):
dest[voidcount(dest)]=A[i]
dest=voiddelete(dest)
for i in range(len(dest)):
if(not dest[i] in list):
move(n,dest[i])
move(0,1)
list=voiddelete(list)
del mitisirube[0]
if(len(list)==N):
print('Yes')
print(*mitisirube,sep='\n')
else:
print('No') | Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s563241493 | Runtime Error | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | N, M = list(map(int, input().split()))
A = [0] * M
B = [0] * M
X = [float("inf")] * N
for i in range(M):
A[i], B[i] = map(int, input().split())
if A[i] == 1:
X[B[i] - 1] = 1
box = B[i]
cout = i
elif B[i] == 1:
X[A[i] - 1] = 1
box = A[i]
cout = i
for j in range(1, N):
for i in range(M):
if i == cout:
continue
if A[i] == box:
X[B[i] - 1] = j + 1
box = B[i]
cout = i
elif B[i] == box:
X[A[i] - 1] = j + 1
box = A[i]
cout = i
print("Yes")
for i in range(1, N + 1):
print(X[i])
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s728453208 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | N, M = map(int, input().split())
A = [0] * (M + 1)
B = [1] * (M + 1)
Dist = [1000000] * (N + 1)
Flug = [0] * (N + 1)
Dist[0] = 0
for i in range(1, M + 1):
c1, c2 = map(int, input().split())
A[i] = min(c1, c2)
B[i] = max(c1, c2)
for j in range(N):
for i in range(M + 1):
if Dist[A[i]] == j and Dist[B[i]] > j:
Dist[B[i]] = j + 1
Flug[B[i]] = A[i]
elif Dist[B[i]] == j and Dist[A[i]] > j:
Dist[A[i]] = j + 1
Flug[A[i]] = B[i]
print("yes")
for i in range(1, N + 1):
print(Flug[i])
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s901738791 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | from collections import deque
def show_2d_array(array):
[print(a) for a in array]
N, M = map(int, input().split())
cave = [[] for i in range(N)]
for i in range(M):
a, b = map(int, input().split())
cave[a - 1].append(b - 1)
cave[b - 1].append(a - 1)
# show_2d_array(cave)
def bfs(tree, p):
seen = [False] * len(tree)
queue = deque((p,))
depth = [0] * N
depth[p] = 0
current_depth = depth[p]
while len(queue) > 0:
# print(queue)
q = queue.popleft()
seen[q] = True
# print(q)
current_depth += 1
for v in tree[q]:
if not seen[v]:
depth[v] = current_depth
queue.append(v)
seen[v] = True
# print(depth)
return depth
depth = bfs(cave, 0)
sign = [0] * N
ans = "Yes"
for i in range(1, N):
current = i
found = False
while not found:
next = -1
for j in cave[current]:
if depth[j] == depth[current] - 1:
if sign[current] <= 0:
next = j
sign[current] = next
break
else:
next = sign[current]
break
if next < 0:
ans = "No"
break
current = next
if current == 0:
found = True
print(ans)
if ans == "Yes":
[print(s + 1) for s in sign[1:]]
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s907302896 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | n, m = map(int, input().split(" "))
ar = [[] for i in range(n)]
br = [0 for i in range(n - 1)]
for i in range(m):
x, y = map(int, input().split(" "))
ar[x - 1].append(y - 1)
ar[y - 1].append(x - 1)
cr = [0]
dr = []
c = 0
del ar[0]
while True:
c += 1
for r in cr:
for i in range(n - 1):
if r in ar[i] and br[i] == 0:
br[i] = c
dr.append(i + 1)
if br.count(0) == 0:
break
cr = dr
print("Yes")
for r in br:
print(r)
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s088123154 | Wrong Answer | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | n,m=map(int,input().split())
#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
a,b=map(int,input().split())
l[a-1].append(b)
l[b-1].append(a)
#深さのリストを作る
l1=sum(l, []) #一次元化
l_depth=list(dict.fromkeys(l1))#深さのリスト
#解の出力
print('Yes')
for i in range(1,n):
#各部屋の通じてる部屋リストを浅い順にソート
ll=sorted(l[i], key=lambda data:l_depth.index(data))
print(ll[0]) | Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
If there is no way to place signposts satisfying the objective, print `No`.
Otherwise, print N lines. The first line should contain `Yes`, and the i-th
line (2 \leq i \leq N) should contain the integer representing the room
indicated by the signpost in Room i.
* * * | s088239001 | Runtime Error | p02678 | Input is given from Standard Input in the following format:
N M
A_1 B_1
:
A_M B_M | n, m = map(int, input().split())
ans = [0] * m
route = {}
for i in range(m):
a, b = map(int, input().split())
if a in route:
li = route[a]
li.append(b)
route[a] = li
else:
route[a] = [b]
if b in route:
li = route[b]
li.append(a)
route[b] = li
else:
route[b] = [a]
que = [1]
while sorted(ans)[0] == 0:
x = que.pop(0)
que.extend(route[x])
for k in route[x]:
if ans[k - 1] == 0:
ans[k - 1] = x
ans.pop(0)
print("Yes")
for k in ans:
print(k)
| Statement
There is a cave.
The cave has N rooms and M passages. The rooms are numbered 1 to N, and the
passages are numbered 1 to M. Passage i connects Room A_i and Room B_i
bidirectionally. One can travel between any two rooms by traversing passages.
Room 1 is a special room with an entrance from the outside.
It is dark in the cave, so we have decided to place a signpost in each room
except Room 1. The signpost in each room will point to one of the rooms
directly connected to that room with a passage.
Since it is dangerous in the cave, our objective is to satisfy the condition
below for each room except Room 1.
* If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.
Determine whether there is a way to place signposts satisfying our objective,
and print one such way if it exists. | [{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 2", "output": "Yes\n 1\n 2\n 2\n \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n 3 4\n 6 1\n 2 4\n 5 3\n 4 6\n 1 5\n 6 2\n 4 5\n 5 6", "output": "Yes\n 6\n 5\n 5\n 1\n 1\n \n\nIf there are multiple solutions, any of them will be accepted."}] |
For each dataset, output the shortest spell. | s791437574 | Wrong Answer | p00645 | The first line of each test case has an integer _n_. Following _n_ lines are
information of an array of enemies. The format is same as described in the
problem statement.
Input terminates when n = 0. You may assume that one or more enemy have
fighting capability. | code = """\
#include <bits/stdc++.h>
using namespace std;
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define all(c) begin(c),end(c)
int main()
{
static array<int,225> ms;
{
int k=0;
rep(t,5) repi(b,t,5) rep(l,5) repi(r,l,5){
int m=0;
repi(i,t,b+1) repi(j,l,r+1) m|=1<<(i*5+j);
ms[k++]=m;
}
}
static array<uint8_t,1<<25> ds; ds.fill(-1); ds[0]=0;
for(int i=0;count(all(ds),i);i++)
rep(j,1<<25) if(ds[j]==i)
for(int m:ms) ds[j^m]=min<uint8_t>(ds[j^m],i+1);
for(int n;cin>>n && n;){
int x=0;
rep(i,n) rep(j,n){
int b; cin>>b;
x|=b<<(i*5+j);
}
string res;
rep(i,ds[x]) res+="myon";
cout<<res<<endl;
}
}
"""
import os, tempfile
(_, filename) = tempfile.mkstemp(".cpp")
f = open(filename, "w")
f.write(code)
f.close()
os.system("g++ -std=c++0x -O2 {}".format(filename))
os.system("./a.out")
| I: Mysterious Onslaught
In 2012, human beings have been exposed to fierce onslaught of unidentified
mysterious extra-terrestrial creatures. We have exhaused because of the long
war and can't regist against them any longer. Only you, an excellent wizard,
can save us. Yes, it's time to stand up!
The enemies are dispatched to the earth with being aligned like an _n_ * _n_
square. Appearently some of them have already lost their fighting capabilities
for some unexpected reason. You have invented a highest grade magic spell
'MYON' to defeat them all. An attack of this magic covers any rectangles
(which is parallel to axis). Once you cast a spell "myon," then all the
enemies which the magic covers will lose their fighting capabilities because
of tremendous power of the magic. However, the magic seems to activate
enemies' self-repairing circuit. Therefore if any enemy which have already
lost its fighting capability is exposed to the magic, the enemy repossesses
its fighting capability. You will win the war when all the enemies will lose
their fighting capabilities.
Let me show an example. An array of enemies below have dispatched:
1 1 1 1 1
1 0 0 0 1
1 0 1 0 1
1 0 0 0 1
1 1 1 1 1
Here, '0' means an enemy that doesn't possess fighting capability, and '1'
means an enemy that possesses. First, you cast a spell "myon" with covering
all the enemies, which results in;
0 0 0 0 0
0 1 1 1 0
0 1 0 1 0
0 1 1 1 0
0 0 0 0 0
Next, cast once again with covering central 3 * 3 enemies.
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
Now you can defeat them all by casting a spell covers remaining one. Therefore
you can cast "myonmyonmyon," which is the shortest spell for this case.
You are given the information of the array. Please write a program that
generates the shortest spell that can defeat them all. | [{"input": "1 1 1 1 1\n 1 0 0 0 1\n 1 0 1 0 1\n 1 0 0 0 1\n 1 1 1 1 1\n 3\n 1 1 1\n 1 1 1\n 1 1 1\n 5\n 1 1 1 1 0\n 1 1 1 1 0\n 1 0 0 0 1\n 0 1 1 1 1\n 0 1 1 1 1\n 0", "output": "myonmyonmyon\n myon\n myonmyon"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s489834550 | Accepted | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | (N, M) = list(map(int, input().split()))
p = [input() for _ in range(M)]
array_flag = [False] * N
array_cnt = [0] * N
for i in p:
(pos, result) = i.split()
pos = int(pos) - 1
if result == "AC":
array_flag[pos] = True
else:
if array_flag[pos] == True:
continue
else:
array_cnt[pos] += 1
answerd_cnt = 0
penalty_cnt = 0
for i in range(len(array_flag)):
if array_flag[i] == True:
answerd_cnt += 1
penalty_cnt += array_cnt[i]
print(answerd_cnt, penalty_cnt)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s130329150 | Accepted | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | N, M = map(int, input().split())
S = [[0 for j in range(2)] for i in range(M)]
for i in range(M):
X = input().split()
S[i][0] = int(X[0])
S[i][1] = str(X[1])
A = [0] * N
p = 0
s = 0
for i in range(M):
if S[i][1] == "WA":
if A[S[i][0] - 1] != "x":
A[S[i][0] - 1] += 1
if S[i][1] == "AC":
if A[S[i][0] - 1] != "x":
p += A[S[i][0] - 1]
A[S[i][0] - 1] = "x"
s += 1
arr = [s, p]
print(*arr)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s894508995 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | num = list(map(int, input().split()))
if num[1] == 0:
count_ac_all = 0
count_wa_all = 0
else:
group = set()
new_num = []
num_list = []
for i in range(0, num[1]):
num_list.append(list(input().split()))
# group.add(num_list[i][0])
#
# set_list = list(group)
# num_list_1 = num_list
# for i in range(0,len(set_list)):
# for j in range(0,len(num_list_1)):
# if num_list[j][0] == set_list[i]:
## new_num.append(num_list[j])
# num_list_1.remove(num_list[j])
# num_list = num_list_1
count_ac = 0
count_wa = 0
count_ac_all = 0
count_wa_all = 0
base = num_list[0][0]
count = 0
set_list = []
for i in range(0, len(num_list)):
if not num_list[i][0] in set_list:
if not num_list[i][0] == base:
base = num_list[i][0]
count = 0
count_ac = 0
count_wa = 0
if count == 0:
if num_list[i][1] == "WA":
count_wa = count_wa + 1
elif num_list[i][1] == "AC":
count_ac = count_ac + 1
count = 1
if count == 1:
count_ac_all = count_ac_all + count_ac
count_wa_all = count_wa_all + count_wa
count = -1
set_list.append(num_list[i][0])
print(count_ac_all, count_wa_all)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s733982273 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | N, M = map(int, input().split(" "))
ac_list, wc_list = list(), list()
for i in range(M):
num, result = input().split(" ")
if result == "AC":
if not (num in ac_list):
ac_list.append(num)
elif not (num in ac_list):
wc_list.append(num)
print(len(ac_list), len(wc_list))
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s939941131 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | d, f = map(int, input().split())
n = []
aw = []
ww = 0
for i in range(f):
a, b = input().split()
if not a in n:
n.append(a)
aw.append([a, b])
else:
h = n.index(a)
if b == "AC" or (b == "WA" and not "AC" in aw[h]):
aw[h].append(b)
y = len(aw)
for qu in aw:
ww += qu.count("WA")
print(y, ww)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s618059188 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | N, M = map(int, input().split())
num = []
TF = []
for i in range(M):
tmp_num, tmp_TF = input().split()
num.append(int(tmp_num))
TF.append(tmp_TF)
accurate_num = []
WA_num = 0
for i, k in zip(num, TF):
if k == "AC":
accurate_num.append(i)
if (k == "WA") & (i not in accurate_num):
WA_num += 1
accurate_num = list(set(accurate_num))
print(len(accurate_num), WA_num)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s163923912 | Accepted | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | n, m = [int(x) for x in input().split()]
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
xg = 0
for _ in range(m):
p, q = input().split()
# print(p,q)
if q == "AC":
# print("fir")
rg = a[int(p) - 1]
if rg == 0:
a[int(p) - 1] = 1
xg += b[int(p) - 1]
else:
# print("sec")
b[int(p) - 1] += 1
print(sum(a), xg)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s995147195 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | params = list(map(int, input().split()))
fails = [0] * params[0]
suceeds = [False] * params[0]
for _ in range(params[1]):
result = input().split()
index = int(result[0]) - 1
if result[1] == "AC":
suceeds[index] = True
if sum(suceeds) == params[0]:
break
elif suceeds[index] is False:
fails[index] += 1
print(str(sum(suceeds)) + " " + str(sum(fails)))
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s165132405 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | n, m = map(int, input().split())
a = [input().split() for i in range(m)]
b = [0] * n
c = [0] * n
for j in range(m):
if a[j][1] == "AC":
b[int(a[j][0]) - 1] = 1
else:
if b[int(a[j][0]) - 1] == 0:
c[int(a[j][0]) - 1] += 1
print(str(sum(b)), str(sum(c)))
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s444339973 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | N, M = [int(n) for n in input().split()]
p = {}
s = {}
for i in range(M):
P, S = input().split()
if S == "WA" and P not in p:
c = s.setdefault(P, 0)
c += 1
s[P] = c
else:
if not p.setdefault(P, 0):
p[P] = 1
for k in s:
if k not in p:
s[P] = 0
print(sum(p.values()), sum(s.values()))
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s755207307 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | N, M = map(int, input().split())
L = [list(input().split()) for _ in range(M)]
D_1 = {str(c): False for c in range(1, N + 1)}
D_2 = {str(c): 0 for c in range(1, N + 1)}
for l in L:
if l[1] == "WA" and D_1[l[0]] == False:
D_2[l[0]] += 1
else:
D_1[l[0]] = True
S_1 = sum(D_2[k] for k, v in D_2.items() if v)
S_2 = sum(D_1.values())
print(S_2, S_1)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s015899432 | Accepted | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | input_int_list = list(map(int, input().split()))
N = input_int_list[0]
M = input_int_list[1]
Q_ans_list = [0] * (N + 1)
ans_correct = 0
ans_penalty = 0
for i in range(M):
input_list_i = list(input().split())
Q_num = int(input_list_i[0])
if input_list_i[1] == "WA":
if Q_ans_list[Q_num] != -1:
Q_ans_list[Q_num] = Q_ans_list[Q_num] + 1
elif input_list_i[1] == "AC":
if Q_ans_list[Q_num] != -1:
ans_correct = ans_correct + 1
ans_penalty = ans_penalty + Q_ans_list[Q_num]
Q_ans_list[Q_num] = -1
print(ans_correct, ans_penalty)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s467273234 | Accepted | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | n, m = map(int, input().split())
a = [[] for ii in range(n)]
for ii in range(m):
p, s = input().split()
p = int(p) - 1
a[p].append(s)
r = 0
q = 0
for ii in range(n):
# print(a[ii])
if "AC" in a[ii]:
r += 1
q += a[ii].index("AC")
print(r, q)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s467719729 | Accepted | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | # coding: utf-8
# Your code here!
def pin(type=int):
return map(type, input().split())
# 1行ごとに読み込んでいる
# 変数一個だけのときはカンマを入れるだけ、input()相当。ちょろい。
# sum関数などintを相手にした関数を書く時に便利なのでデフォルトをint型にする
N, M = pin()
p = [0 for j in range(0, M)]
S = [0 for j in range(0, M)]
for j in range(0, M):
p[j], S[j] = pin(str) # p_i,S_iにそれぞれ対応
# print("sah")
# O(3M)...?
# print(p)
# print(p,S)
# ACした問題番号と各々の問題(後々AC下かを考えない)ペナ数を問題番号別にまとめた配列
AC = [0 for i in range(0, N)]
Penalties = [0 for i in range(0, N)]
# 問題番号iと回答番号jについて,
"""
for i in range(0,N):
for j in range(0,M):
#jがiの回答である時に,WAだったらPenaltiesに1個加算
if int(p[j])-1==i:
if (S[j]) == 'WA':
Penalties[int(p[j])-1] += 1
else:#それが初めてのACならば、AC数に1を足してcontinueで次の問題i+1へ移る
AC[int(p[j])-1] = 1
break
#print(AC,Penalties)
"""
# double-loop だと TLEしてしまう O(n^2)はだめみたい
# singleloopしかないねぇ
# 回答番号jに着目する
for j in range(0, M):
if S[j] == "AC":
if AC[int(p[j]) - 1] == 1:
continue
else:
AC[int(p[j]) - 1] = 1
else: # wa or something
if AC[int(p[j]) - 1] == 1:
continue
else:
Penalties[int(p[j]) - 1] += 1
# print(AC,Penalties)
for i in range(0, N):
if AC[i] == 0:
Penalties[i] = 0
# print("///////")
# print(AC,Penalties)
# ACリスト内の1の数を数えるのは iter.countだね
print(AC.count(1), sum(Penalties))
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s132214936 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | x, y = list(map(int, input().split()))
z = [0] * x
for i in range(y):
a, b = list(map(str, input().split()))
a = int(a)
if b == "AC" and z[a - 1] < 10**6:
z[a - 1] = z[a - 1] + 10**6
if b == "WA" and z[a - 1] < 10**6:
z[a - 1] = z[a - 1] + 1
ansa = str(sum(z) // (10**6))
ansb = str(sum(z) % (10**6))
print(ansa + " " + ansb)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s251552694 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | n, m = map(int, input().split())
results = []
for i in range(m):
results.append(input().split())
passed = 0
failed = 0
dicto = {}
for item in results:
key = item[0]
status = item[1]
if key not in dicto.keys():
dicto[key] = []
dicto[key].append(status)
if status == "WA":
failed += 1
else:
passed += 1
else:
# key exists already and has something in it
if status not in dicto[key]:
# status not in dicto[key]
if status == "AC":
# failed is in dicto[key]
passed += 1
dicto[key].append(status)
else:
# status already exists in dicto[key]
if status == "WA" and "AC" not in dicto[key]:
failed += 1
print(failed, passed)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print the number of Takahashi's correct answers and the number of Takahashi's
penalties.
* * * | s526789282 | Wrong Answer | p02802 | Input is given from Standard Input in the following format:
N M
p_1 S_1
:
p_M S_M | q, sub = map(int, input().split())
ac = [0 for i in range(q)]
sum_wa = [0 for i in range(q)]
waans = 0
for i in range(sub):
m, n = input().split()
m = int(m)
if n == "WA":
if sum_wa[m - 1] == 0:
waans += 1
elif n == "AC" and ac[m - 1] == 0:
ac[m - 1] += 1
sum_wa[m - 1] += 1
print(sum(ac), waans)
| Statement
Takahashi participated in a contest on AtCoder.
The contest had N problems.
Takahashi made M submissions during the contest.
The i-th submission was made for the p_i-th problem and received the verdict
S_i (`AC` or `WA`).
The number of Takahashi's correct answers is the number of problems on which
he received an `AC` once or more.
The number of Takahashi's penalties is the sum of the following count for the
problems on which he received an `AC` once or more: the number of `WA`s
received before receiving an `AC` for the first time on that problem.
Find the numbers of Takahashi's correct answers and penalties. | [{"input": "2 5\n 1 WA\n 1 AC\n 2 WA\n 2 AC\n 2 WA", "output": "2 2\n \n\nIn his second submission, he received an `AC` on the first problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nIn his fourth submission, he received an `AC` on the second problem for the\nfirst time. Before this, he received one `WA` on this problem.\n\nThus, he has two correct answers and two penalties.\n\n* * *"}, {"input": "100000 3\n 7777 AC\n 7777 AC\n 7777 AC", "output": "1 0\n \n\nNote that it is pointless to get an `AC` more than once on the same problem.\n\n* * *"}, {"input": "6 0", "output": "0 0"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s463805240 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | #!/usr/bin/env python3
def debug(N, st):
print(*[st.query(i, i + 1) for i in range(N)], sep=" ")
def solve(N, Q, Queries):
from itertools import accumulate
row = SegmentTreeLazy([float("inf")] * N, float("inf"), float("inf"), min, min, min)
col = SegmentTreeLazy([float("inf")] * N, float("inf"), float("inf"), min, min, min)
rmin = list(accumulate([N if c == 2 else x for c, x in Queries], min))
cmin = list(accumulate([N if c == 1 else x for c, x in Queries], min))
ans = 0
def f(st, emin, i, step):
st.update(i, N, step)
idx = st.query(i, i + 1)
return emin[idx] - 2
for step, (c, x) in enumerate(Queries):
if c == 1:
ans += f(row, cmin, x - 1, step)
else:
ans += f(col, rmin, x - 1, step)
return (N - 2) ** 2 - ans
# https://judge.yosupo.jp/submission/9146
class SegmentTreeLazy:
def __init__(self, arr, ti, ei, func, op, merge):
self.h = (len(arr) - 1).bit_length()
self.n = 2**self.h
self.func = func
self.op = op
self.merge = merge
self.ti = ti
self.ei = ei
self.val = [ti for _ in range(2 * self.n)]
for i in range(len(arr)):
self.val[self.n + i] = arr[i]
for i in range(1, self.n)[::-1]:
self.val[i] = self.func(self.val[2 * i], self.val[2 * i + 1])
self.laz = [ei for _ in range(2 * self.n)]
def reflect(self, k):
if self.laz[k] == self.ei:
return self.val[k]
return self.op(self.val[k], self.laz[k])
def propagate(self, k):
if self.laz[k] == self.ei:
return
self.laz[2 * k] = self.merge(self.laz[2 * k], self.laz[k])
self.laz[2 * k + 1] = self.merge(self.laz[2 * k + 1], self.laz[k])
self.val[k] = self.reflect(k)
self.laz[k] = self.ei
def thrust(self, k):
for i in range(1, self.h + 1)[::-1]:
self.propagate(k >> i)
def recalc(self, k):
while k:
k >>= 1
self.val[k] = self.func(self.reflect(2 * k), self.reflect(2 * k + 1))
def update(self, lt, rt, x):
lt += self.n
rt += self.n
vl = lt
vr = rt
self.thrust(lt)
self.thrust(rt - 1)
while rt - lt > 0:
if lt & 1:
self.laz[lt] = self.merge(self.laz[lt], x)
lt += 1
if rt & 1:
rt -= 1
self.laz[rt] = self.merge(self.laz[rt], x)
lt >>= 1
rt >>= 1
self.recalc(vl)
self.recalc(vr - 1)
def query(self, lt, rt):
lt += self.n
rt += self.n
self.thrust(lt)
self.thrust(rt - 1)
vl = vr = self.ti
while rt - lt > 0:
if lt & 1:
vl = self.func(vl, self.reflect(lt))
lt += 1
if rt & 1:
rt -= 1
vr = self.func(self.reflect(rt), vr)
lt >>= 1
rt >>= 1
return self.func(vl, vr)
# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
N, Q = map(int, input().split())
Queries = [list(map(int, input().split())) for _ in range(Q)]
print(solve(N, Q, Queries))
def test():
import doctest
doctest.testmod()
if __name__ == "__main__":
# test()
main()
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s971893786 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | #!/usr/bin/env python3
import sys
def input():
return sys.stdin.readline().rstrip()
class LazySegmentTree:
def __init__(self, init, unitX, unitA, f, g, h):
self.f = f # (X, X) -> X
self.g = g # (X, A, size) -> X
self.h = h # (A, A) -> A
self.unitX = unitX
self.unitA = unitA
self.f = f
if type(init) == int:
self.n = init
# self.n = 1 << (self.n - 1).bit_length()
self.X = [unitX] * (self.n * 2)
self.size = [1] * (self.n * 2)
else:
self.n = len(init)
# self.n = 1 << (self.n - 1).bit_length()
self.X = [unitX] * self.n + init + [unitX] * (self.n - len(init))
self.size = [0] * self.n + [1] * len(init) + [0] * (self.n - len(init))
for i in range(self.n - 1, 0, -1):
self.X[i] = self.f(self.X[i * 2], self.X[i * 2 | 1])
for i in range(self.n - 1, 0, -1):
self.size[i] = self.size[i * 2] + self.size[i * 2 | 1]
self.A = [unitA] * (self.n * 2)
def update(self, i, x):
i += self.n
self.X[i] = x
i >>= 1
while i:
self.X[i] = self.f(self.X[i * 2], self.X[i * 2 | 1])
i >>= 1
def calc(self, i):
return self.g(self.X[i], self.A[i], self.size[i])
def calc_above(self, i):
i >>= 1
while i:
self.X[i] = self.f(self.calc(i * 2), self.calc(i * 2 | 1))
i >>= 1
def propagate(self, i):
self.X[i] = self.g(self.X[i], self.A[i], self.size[i])
self.A[i * 2] = self.h(self.A[i * 2], self.A[i])
self.A[i * 2 | 1] = self.h(self.A[i * 2 | 1], self.A[i])
self.A[i] = self.unitA
def propagate_above(self, i):
H = i.bit_length()
for h in range(H, 0, -1):
self.propagate(i >> h)
def propagate_all(self):
for i in range(1, self.n):
self.propagate(i)
def getrange(self, l, r):
l += self.n
r += self.n
l0, r0 = l // (l & -l), r // (r & -r) - 1
self.propagate_above(l0)
self.propagate_above(r0)
al = self.unitX
ar = self.unitX
while l < r:
if l & 1:
al = self.f(al, self.calc(l))
l += 1
if r & 1:
r -= 1
ar = self.f(self.calc(r), ar)
l >>= 1
r >>= 1
return self.f(al, ar)
def getvalue(self, i):
i += self.n
self.propagate_above(i)
return self.calc(i)
def operate_range(self, l, r, a):
l += self.n
r += self.n
l0, r0 = l // (l & -l), r // (r & -r) - 1
self.propagate_above(l0)
self.propagate_above(r0)
while l < r:
if l & 1:
self.A[l] = self.h(self.A[l], a)
l += 1
if r & 1:
r -= 1
self.A[r] = self.h(self.A[r], a)
l >>= 1
r >>= 1
self.calc_above(l0)
self.calc_above(r0)
# Find r s.t. calc(l, ..., r-1) = True and calc(l, ..., r) = False
def max_right(self, l, z):
if l >= self.n:
return self.n
l += self.n
s = self.unitX
while 1:
while l % 2 == 0:
l >>= 1
if not z(self.f(s, self.calc(l))):
while l < self.n:
l *= 2
if z(self.f(s, self.calc(l))):
s = self.f(s, self.calc(l))
l += 1
return l - self.n
s = self.f(s, self.calc(l))
l += 1
if l & -l == l:
break
return self.n
# Find l s.t. calc(l, ..., r-1) = True and calc(l-1, ..., r-1) = False
def min_left(self, r, z):
if r <= 0:
return 0
r += self.n
s = self.unitX
while 1:
r -= 1
while r > 1 and r % 2:
r >>= 1
if not z(self.f(self.calc(r), s)):
while r < self.n:
r = r * 2 + 1
if z(self.f(self.calc(r), s)):
s = self.f(self.calc(r), s)
r -= 1
return r + 1 - self.n
s = self.f(self.calc(r), s)
if r & -r == r:
break
return 0
f = lambda x, y: (x + y)
g = lambda x, a, s: min(x, a)
h = lambda a, b: min(a, b)
unitX = 0
unitA = 10**10
N, Q = map(int, input().split())
A = [N - 2] * (N - 2)
sttate = LazySegmentTree(A, unitX, unitA, f, g, h)
styoko = LazySegmentTree(A, unitX, unitA, f, g, h)
ans = (N - 2) ** 2
for _ in range(Q):
q1, q2 = map(int, input().split())
if q1 == 1:
horu = sttate.getrange(q2 - 2, q2 - 1)
ans -= horu
sttate.operate_range(q2 - 2, q2 - 1, 0)
styoko.operate_range(0, horu, q2 - 2)
if q1 == 2:
horu = styoko.getrange(q2 - 2, q2 - 1)
ans -= horu
styoko.operate_range(q2 - 2, q2 - 1, 0)
sttate.operate_range(0, horu, q2 - 2)
print(ans)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s360629283 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | import os
import sys
import numpy as np
def solve(inp):
SEGTREE_TABLES = []
COMMON_STACK = np.zeros(10**7, dtype=np.int64)
INF = 10**18
def bit_length(n):
ret = 0
while n:
n >>= 1
ret += 1
return ret
def segtree_init(n):
n2 = 1 << bit_length(n)
table = np.full((n2 << 1, 2), INF, dtype=np.int64)
SEGTREE_TABLES.append(table)
return len(SEGTREE_TABLES) - 1
def segtree_build(ins, arr):
table = SEGTREE_TABLES[ins]
offset = table.shape[0] >> 1
table[offset : offset + len(arr), 0] = arr
for i in range(offset - 1, 0, -1):
ch = i << 1
table[i, 0] = min(table[ch, 0], table[ch + 1, 0])
def segtree_eval(table, offset, i):
lazy_min = table[i, 1]
if i < offset:
ch = i << 1
table[ch, 1] = min(table[ch, 1], lazy_min)
table[ch + 1, 1] = min(table[ch + 1, 1], lazy_min)
table[i, 0] = min(table[i, 0], lazy_min)
table[i, 1] = INF
def segtree_bottomup(table, i):
lch = i << 1
rch = lch + 1
l_dat = min(table[lch, 0], table[lch, 1])
r_dat = min(table[rch, 0], table[rch, 1])
table[i, 0] = min(l_dat, r_dat)
def segtree_range_update(ins, l, r, mn):
table = SEGTREE_TABLES[ins]
offset = table.shape[0] >> 1
stack = COMMON_STACK
stack[:3] = (1, 0, offset)
si = 3
updated = []
while si:
i, a, b = stack[si - 3 : si]
segtree_eval(table, offset, i)
if b <= l or r <= a:
si -= 3
continue
if l <= a and b <= r:
table[i, 1] = min(table[i, 1], mn)
si -= 3
continue
updated.append(i)
m = (a + b) // 2
stack[si - 3 : si] = (i << 1, a, m)
stack[si : si + 3] = ((i << 1) + 1, m, b)
si += 3
while updated:
i = updated.pop()
segtree_bottomup(table, i)
def segtree_query(ins, l, r):
"""sum [l, r)"""
table = SEGTREE_TABLES[ins]
offset = table.shape[0] >> 1
stack = COMMON_STACK
stack[:3] = (1, 0, offset)
si = 3
res = INF
updated = []
while si:
i, a, b = stack[si - 3 : si]
segtree_eval(table, offset, i)
if b <= l or r <= a:
si -= 3
continue
if l <= a and b <= r:
res = min(res, table[i, 0])
si -= 3
continue
updated.append(i)
m = (a + b) // 2
stack[si - 3 : si] = (i << 1, a, m)
stack[si : si + 3] = ((i << 1) + 1, m, b)
si += 3
while updated:
i = updated.pop()
segtree_bottomup(table, i)
return res
def segtree_debug_print(ins):
table = SEGTREE_TABLES[ins]
offset = table.shape[0] >> 1
for t in range(2):
i = 1
while i <= offset:
print(table[i : 2 * i, t])
i <<= 1
n = inp[0]
q = inp[1]
ops = inp[2::2]
xxx = inp[3::2]
ins1 = segtree_init(n - 2)
ins2 = segtree_init(n - 2)
init = np.full(n - 2, n - 2, dtype=np.int64)
segtree_build(ins1, init)
segtree_build(ins2, init)
ans = (n - 2) * (n - 2)
for qi in range(q):
o = ops[qi]
x = xxx[qi]
if o == 1:
k = segtree_query(ins1, x - 2, x - 1)
ans -= k
segtree_range_update(ins2, 0, k + 1, x - 2)
else:
k = segtree_query(ins2, x - 2, x - 1)
ans -= k
segtree_range_update(ins1, 0, k + 1, x - 2)
# print(qi, o, x, k, ans)
# segtree_debug_print(ins1)
# segtree_debug_print(ins2)
return ans
if sys.argv[-1] == "ONLINE_JUDGE":
from numba.pycc import CC
cc = CC("my_module")
cc.export("solve", "(i8[:],)")(solve)
cc.compile()
exit()
if os.name == "posix":
# noinspection PyUnresolvedReferences
from my_module import solve
else:
from numba import njit
solve = njit("(i8[:],)", cache=True)(solve)
print("compiled", file=sys.stderr)
inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=" ")
ans = solve(inp)
print(ans)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s457178114 | Wrong Answer | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | import numpy as np
from numba import njit
from numba.types import i8
ni8 = np.int64
@njit((i8, i8[:, ::-1]), cache=True)
def solve(n, qr):
col = np.full(n - 1, n - 2)
col[0] = 0
col_min = n - 1
prev_col_min = n - 1
row = np.full(n - 1, n - 2)
row[0] = 0
row_min = n - 1
prev_row_min = n - 1
white = 0
for i in range(qr.shape[0]):
j = qr[i, 1] - 1
if qr[i, 0] == 1:
if row_min < prev_row_min:
for m in range(1, col_min):
col[m] = min(col[m], j - 1)
prev_row_min = row_min
u = col[j]
white += u
col[j] = 0
if j < col_min:
col_min = j
else:
if col_min < prev_col_min:
for m in range(1, row_min):
row[m] = min(row[m], j - 1)
prev_col_min = col_min
u = row[j]
white += u
row[j] = 0
if j < row_min:
row_min = j
return white
def main():
f = open(0)
n, q = [int(x) for x in f.readline().split()]
qr = np.fromstring(f.read(), ni8, sep=" ").reshape((-1, 2))
white = solve(n, qr)
print((n - 2) ** 2 - white)
main()
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s286460348 | Wrong Answer | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | n, q = list(map(int, input().split()))
res = (n - 2) ** 2
lx = [n - 1 for _ in range(n)]
ly = [n - 1 for _ in range(n)]
for _ in range(q):
q1, q2 = list(map(int, input().split()))
q2 -= 1
if q1 == 1:
res -= lx[q2] - 1
for i in range(1, q2 + 1):
if ly[i] >= q2:
ly[i] = q2
else:
res -= ly[q2] - 1
for i in range(1, q2 + 1):
if lx[i] >= q2:
lx[i] = q2
print(res)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s762704976 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | # -*- coding: utf-8 -*-
def input_int_array():
return map(int, input().split())
class Board:
def __init__(self, w, h, parent):
self.w = w
self.h = h
self.parent = parent
def answer(n, q):
min_board = Board(n - 2, n - 2, None)
black = (n - 2) * (n - 2)
for i in range(q):
a, pos = input_int_array()
pos -= 1
board = min_board
use_min = True
if a == 1:
while pos > board.w:
board = board.parent
use_min = False
black -= board.h
if use_min:
b = Board(pos - 1, board.h, board)
min_board = b
else:
while pos > board.h:
board = board.parent
use_min = False
black -= board.w
if use_min:
b = Board(board.w, pos - 1, board)
min_board = b
print(black)
n, q = input_int_array()
answer(n, q)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s699183156 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | from sys import stdin
input = stdin.buffer.readline
def main():
n, q = map(int, input().split())
height, width = n, n
mark1 = [0] * n
mark2 = [0] * n
ans = (n - 2) * (n - 2)
for _ in range(q):
typ, x = map(int, input().split())
if typ == 1:
if x < width:
ans -= height - 2
for i in range(x, width):
mark1[i] = height - 2
width = x
else:
ans -= mark1[x]
else:
if x < height:
ans -= width - 2
for i in range(x, height):
mark2[i] = width - 2
height = x
else:
ans -= mark2[x]
print(ans)
main()
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s227502763 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | f = lambda: map(int, input().split())
N, Q = f()
a, b = N, N
black = (N - 2) * (N - 2)
B = [-1] * (N + 1)
W = [-1] * (N + 1)
for _ in range(Q):
q, x = f()
if q == 1:
if B[x] > 0:
black -= B[x]
B[x] = 0
else:
black -= b - 2
a = x
for j in range(a + 1, N + 1):
if B[j] == -1:
B[j] = b - 2
else:
break
if j == N - 1:
break
else:
if W[x] > 0:
black -= W[x]
W[x] = 0
else:
black -= a - 2
b = x
for j in range(b + 1, N + 1):
if W[j] == -1:
W[j] = a - 2
else:
break
if j == N - 1:
break
print(black)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s271376507 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | import sys
def solve():
input = sys.stdin.readline
N, Q = map(int, input().split())
total = (N - 2) ** 2
rb = N
db = N
D = [N] * (N + 1)
R = [N] * (N + 1)
for _ in range(Q):
a, b = map(int, input().split())
if a == 1: # 横向き
if b < db:
total -= rb - 2
for i in range(b, db):
R[i] = rb
db = b
else:
total -= R[b] - 2
else: # 縦向き
if b < rb:
total -= db - 2
for i in range(b, rb):
D[i] = db
rb = b
else:
total -= D[b] - 2
print(total)
return 0
if __name__ == "__main__":
solve()
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s377002899 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | import sys
sys.setrecursionlimit(10**7)
rl = sys.stdin.readline
def solve():
N, Q = map(int, rl().split())
left = top = N
row, col = [N] * (N + 1), [N] * (N + 1)
ans = (N - 2) ** 2
for _ in range(Q):
com, x = map(int, rl().split())
if com == 1:
if x < left:
for i in range(x, left):
col[i] = top
left = x
ans -= col[x] - 2
else:
if x < top:
for i in range(x, top):
row[i] = left
top = x
ans -= row[x] - 2
print(ans)
if __name__ == "__main__":
solve()
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s127386204 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | # from collections import deque,defaultdict
printn = lambda x: print(x, end="")
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
ins = lambda: input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
# R = 998244353
def ddprint(x):
if DBG:
print(x)
# # # # class Segtree # # # #
# 0
# 1 2
# 3 4 5 6
# :
# leaf i - n-1+i
# parent - (i-1)//2
# children - 2*i+1, 2*i+2
class Segtree:
# modify UNIT and oper depending on the reduce operation
# UNIT = 0 # sum/or:0 and:fff..f min:BIG max:-BIG gcd:0 lcm:1 ..
# @classmethod
# def oper(c,x,y):
# return x|y # sum:+ or/and/min/max/gcd/lcm:(same)
# call like this: sgt = Segtree(n, 0, lambda x,y: max(x,y))
def __init__(s, l, unit, oper):
s.unit = unit
s.oper = oper
s.n = 1
while s.n < l:
s.n *= 2
s.ary = [s.unit for i in range(2 * s.n - 1)]
def get(s, i):
return s.ary[i + s.n - 1]
def set(s, i, v):
k = i + s.n - 1
s.ary[k] = v
while k > 0:
k = (k - 1) // 2
s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])
def setary(s, a):
for i, v in enumerate(a):
s.ary[i + s.n - 1] = v
for k in range(s.n - 2, -1, -1):
s.ary[k] = s.oper(s.ary[2 * k + 1], s.ary[2 * k + 2])
def query(s, x, y):
l = x + s.n - 1
r = y + s.n - 1
res = s.unit
while l < r:
if not l % 2:
res = s.oper(res, s.ary[l])
l += 1
if not r % 2:
r -= 1
res = s.oper(res, s.ary[r])
l >>= 1
r >>= 1
return res
# # # # class Segtree end # # # #
n, q = inm()
b = (n - 2) ** 2
minx = x = n - 1
miny = y = n - 1
sx = Segtree(n, n - 1, lambda x, y: min(x, y))
sy = Segtree(n, n - 1, lambda x, y: min(x, y))
z = [n - 1] * n
sx.setary(z)
sy.setary(z)
# ddprint(sx.ary)
# ddprint(sy.ary)
for i in range(q):
t, k = inm()
k -= 1
if t == 1:
b -= sy.query(k, n) - 1
if k < minx:
sx.set(miny, k)
minx = k
else:
b -= sx.query(k, n) - 1
if k < miny:
sy.set(minx, k)
miny = k
# ddprint(f"{i=} {b=} {minx=} {miny=}")
# ddprint(sx.ary)
# ddprint(sy.ary)
print(b)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s484531057 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | import sys
sys.setrecursionlimit(500000)
def input():
return sys.stdin.readline()[:-1]
class SegmentTree:
def __init__(self, L, op, ide):
self.op = op
self.ide = ide
self.sz = len(L)
self.n = 1
self.s = 1
for i in range(1000):
self.n *= 2
self.s += 1
if self.n >= self.sz:
break
self.node = [self.ide] * (2 * self.n - 1)
for i in range(self.sz):
self.node[i + self.n - 1] = L[i]
for i in range(self.n - 2, -1, -1):
self.node[i] = self.op(self.node[i * 2 + 1], self.node[i * 2 + 2])
def add(self, a, x):
k = a + self.n - 1
self.node[k] += x
for i in range(1000):
k = (k - 1) // 2
self.node[k] = self.op(self.node[2 * k + 1], self.node[2 * k + 2])
if k <= 0:
break
def substitute(self, a, x):
k = a + self.n - 1
self.node[k] = self.op(x, self.node[k])
for i in range(1000):
k = (k - 1) // 2
self.node[k] = self.op(self.node[2 * k + 1], self.node[2 * k + 2])
if k <= 0:
break
def get_one(self, a):
k = a + self.n - 1
return self.node[k]
def get(self, l, r):
res = self.ide
n = self.n
if self.sz <= r or 0 > l:
return False
for i in range(self.s):
count = 2**i - 1
a = (r + 1) // n
b = (l - 1) // n
if a - b == 3:
res = self.op(self.node[count + b + 1], res)
res = self.op(self.node[count + b + 2], res)
right = a * n
left = (b + 1) * n - 1
break
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
right = a * n
left = (b + 1) * n - 1
break
n = n // 2
# left
n1 = n // 2
for j in range(i + 1, self.s):
count = 2**j - 1
a = (left + 1) // n1
b = (l - 1) // n1
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
left = (b + 1) * n1 - 1
n1 = n1 // 2
# right
n1 = n // 2
for j in range(i + 1, self.s):
count = 2**j - 1
a = (r + 1) // n1
b = (right - 1) // n1
if a - b == 2:
res = self.op(self.node[count + b + 1], res)
right = a * n1
n1 = n1 // 2
return res
def smin(a, b):
if a > b:
return b
else:
return a
def main():
N, Q = list(map(int, input().split()))
ST1 = SegmentTree([N - 2] * (N - 2), smin, N - 2)
ST2 = SegmentTree([N - 2] * (N - 2), smin, N - 2)
ans = 0
for i in range(Q):
a, b = list(map(int, input().split()))
b -= 2
if a == 1:
c = ST1.get(b, N - 3)
ans += c
ST2.substitute(c - 1, b)
else:
c = ST2.get(b, N - 3)
ans += c
ST1.substitute(c - 1, b)
# print(ans)
# print(*[ST1.get_one((i)) for i in range(N-2)])
# print(*[ST2.get_one((i)) for i in range(N-2)])
print((N - 2) ** 2 - ans)
if __name__ == "__main__":
main()
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s362850343 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | N, Q = map(int, input().split())
area_W = N - 2
area_H = N - 2
walls_H = []
walls_V = []
count = (N - 2) * (N - 2)
# search smallest i ( s <= i < e ) such that f(i) == True
def bisearch_smallest(f, s, e=None):
if e == None:
e = s - 1
s = 0
else:
e -= 1
while s < e:
m = (s + e) // 2
if f(m):
e = m
else:
s = m + 1
if s == e and f(s):
return s
else:
return -1
for _ in range(Q):
q, i = input().split()
i = int(i) - 2
if q == "1":
if i < area_W:
area_W = i
count -= area_H
walls_H.append((i, area_H))
else:
j = bisearch_smallest(lambda j: walls_H[j][0] < i, 0, len(walls_H))
count -= walls_H[j][1]
else:
if i < area_H:
area_H = i
count -= area_W
walls_V.append((i, area_W))
else:
j = bisearch_smallest(lambda j: walls_V[j][0] < i, 0, len(walls_V))
count -= walls_V[j][1]
# print(area_W, area_H)
print(count)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s296355368 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | N, Q = map(int, input().split())
N -= 2
BIT = [[0 for i in range(N + 1)] for _ in range(2)]
n = N
def BIT_query(idx, BIT):
res_sum = 0
while idx > 0:
res_sum += BIT[idx]
idx -= idx & (-idx)
return res_sum
def BIT_update(idx, x, BIT):
while idx <= n:
BIT[idx] += x
idx += idx & (-idx)
return
now = N * N
max_x = [0, 0]
for _ in range(Q):
s, x = map(int, input().split())
s -= 1
x -= 1
x = N + 1 - x
# print()
depth = N + BIT_query(x, BIT[s])
now -= depth
# print(x, s, depth, now, BIT_query(x, BIT[s]), max_x[s])
if x > max_x[s]:
BIT_update(N - depth + 1, max_x[s] - x, BIT[1 - s])
max_x[s] = x
print(now)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s379099852 | Wrong Answer | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | n, q = map(int, input().split())
query = []
for _ in range(q):
t, x = map(int, input().split())
query.append((t, x))
black = (n - 2) ** 2
l1 = r1 = l2 = r2 = b1 = b2 = n
for t, x in query:
if t == 1:
if x < b1:
black -= l1 - 2
r2 = l2
l2 = x
b2 = l1
else:
black -= r1 - 2
else:
if x < b2:
black -= l2 - 2
r1 = l1
l1 = x
b1 = l2
else:
black -= r2 - 2
print(black)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s391391074 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | from bisect import bisect_left as bl
N, Q = map(int, input().split())
ans = 0
q1 = []
q2 = []
query = []
for _ in range(Q):
n, p = map(int, input().split())
query.append((n, p))
if n == 1:
q1.append(p)
else:
q2.append(p)
q1.sort()
q2.sort()
board = [N - 2, N - 2]
count1 = len(q1)
count2 = len(q2)
for n, p in query:
if n == 1:
if p > board[1] + 1:
continue
index = bl(q1, p)
ans += board[0] * (count1 - index)
board[1] = p - 2
count1 = index
else:
if p > board[0] + 1:
continue
index = bl(q2, p)
ans += board[1] * (count2 - index)
board[0] = p - 2
count2 = index
print((N - 2) ** 2 - ans)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s001184691 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
inf = 10**10
class Seg_min:
def __init__(self, x):
#####単位元######
self.ide_ele_min = inf
self.func = min
self.n = len(x)
# num_max:n以上の最小の2のべき乗
self.num_max = 2 ** (self.n - 1).bit_length()
self.x = [self.ide_ele_min] * 2 * self.num_max
for i, num in enumerate(x, self.num_max):
self.x[i] = num
for i in range(self.num_max - 1, 0, -1):
self.x[i] = self.func(self.x[i << 1], self.x[(i << 1) + 1])
def update(self, i, x):
i += self.num_max
self.x[i] = x
while i > 0:
i = i // 2
self.x[i] = self.func(self.x[i << 1], self.x[(i << 1) + 1])
def query(self, i, j):
res = self.ide_ele_min
if i >= j:
return res
i += self.num_max
j += self.num_max - 1
while i <= j:
if i == j:
res = self.func(res, self.x[i])
break
if i & 1:
res = self.func(res, self.x[i])
i += 1
if not j & 1:
res = self.func(res, self.x[j])
j -= 1
i = i >> 1
j = j >> 1
return res
n, q, *query = list(map(int, read().split()))
wall_ns = Seg_min([inf] * (n - 2))
wall_ew = Seg_min([inf] * (n - 2))
min_ns = [n - 2] * (q + 1)
min_ew = [n - 2] * (q + 1)
ans = (n - 2) * (n - 2)
for i in range(1, q + 1):
x = query[i * 2 - 1] - 2
if query[i * 2 - 2] == 1:
last = wall_ns.query(0, x)
if last == inf:
last = i - 1
ans -= min_ew[last]
wall_ns.update(x, i)
min_ns[i] = min(min_ns[i - 1], x)
min_ew[i] = min_ew[i - 1]
else:
last = wall_ew.query(0, x)
if last == inf:
last = i - 1
ans -= min_ns[last]
wall_ew.update(x, i)
min_ew[i] = min(min_ew[i - 1], x)
min_ns[i] = min_ns[i - 1]
print(ans)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print how many black stones there are on the grid after processing all Q
queries.
* * * | s781048902 | Accepted | p02551 | Input is given from Standard Input in the following format:
N Q
Query_1
\vdots
Query_Q | N, Q = map(int, input().split())
Min_x = [-1 for _ in range(N)] # 一番遠い位置にある黒(0index)
# Min_x[N-1] = -1
Min_y = [-1 for _ in range(N)] # 一番遠い位置にある黒(0index)
# Min_y[N-1] = -1
black = (N - 2) ** 2
a = N - 2
b = N - 2 # 左上の四角の部分
for query in range(Q):
# print(black)
temp = list(map(int, input().split())) # 1index #x-=1 #0index
if temp[0] == 1: # 上に置く
w = temp[1] - 1 # 0index
if w <= b:
# 左上の更新する四角の中の場合、更新前の値が裏返りに使われる。
black -= a # 一番遠い黒-1 (0行目にはない)裏返る。0indexなのでそのまま引いてよい。
for yoko in range(w, b + 1): # w~bまで
Min_y[yoko] = a
b = w - 1
else:
# 既に更新する四角から外れている場合には既存の値を入れる。
black -= Min_y[
w
] # 一番遠い黒-1 (0行目にはない)裏返る。0indexなのでそのまま引いてよい。
else: # 横に置く
h = temp[1] - 1 # 0index
if h <= a:
# 左上の更新する四角の中の場合、更新前の値が裏返りに使われる。
black -= b # 一番遠い黒-1 (0行目にはない)裏返る。0indexなのでそのまま引いてよい。
# print(h,a)
for tate in range(h, a + 1): # w~bまで
Min_x[tate] = b
a = h - 1
else:
# 既に更新する四角から外れている場合には既存の値を入れる。
black -= Min_x[
h
] # 一番遠い黒-1 (0行目にはない)裏返る。0indexなのでそのまま引いてよい。
# print("x",Min_x)
# print("y",Min_y)
# print("black", black)
print(black)
| Statement
There is a grid with N rows and N columns of squares. Let (i, j) be the square
at the i-th row from the top and the j-th column from the left.
Each of the central (N-2) \times (N-2) squares in the grid has a black stone
on it. Each of the 2N - 1 squares on the bottom side and the right side has a
white stone on it.
Q queries are given. We ask you to process them in order. There are two kinds
of queries. Their input format and description are as follows:
* `1 x`: Place a white stone on (1, x). After that, for each black stone between (1, x) and the first white stone you hit if you go down from (1, x), replace it with a white stone.
* `2 x`: Place a white stone on (x, 1). After that, for each black stone between (x, 1) and the first white stone you hit if you go right from (x, 1), replace it with a white stone.
How many black stones are there on the grid after processing all Q queries? | [{"input": "5 5\n 1 3\n 2 3\n 1 4\n 2 2\n 1 2", "output": "1\n \n\nAfter each query, the grid changes in the following way:\n\n\n\n* * *"}, {"input": "200000 0", "output": "39999200004\n \n\n* * *"}, {"input": "176527 15\n 1 81279\n 2 22308\n 2 133061\n 1 80744\n 2 44603\n 1 170938\n 2 139754\n 2 15220\n 1 172794\n 1 159290\n 2 156968\n 1 56426\n 2 77429\n 1 97459\n 2 71282", "output": "31159505795"}] |
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space
character between adjacent elements. | s227426059 | Accepted | p02414 | In the first line, three integers $n$, $m$ and $l$ are given separated by
space characters
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$
matrix $B$ are given. | # 初期値の挿入
list_nml = list(map(int, input().split()))
list_nm = list()
list_ml = list()
result_nl = [[0] * list_nml[2] for n in range(list_nml[0])]
# インプットdataの格納
for n in range(list_nml[0]):
list_nm.append(list(map(int, input().split())))
for m in range(list_nml[1]):
list_ml.append(list(map(int, input().split())))
# 計算
for n in range(list_nml[0]):
for l in range(list_nml[2]):
result_temp = 0
for m in range(list_nml[1]):
result_temp += list_nm[n][m] * list_ml[m][l]
result_nl[n][l] = result_temp
# 計算結果の表示
for a in result_nl:
print(*a)
| Matrix Multiplication
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$
matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of
matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$
respectively. | [{"input": "2 3\n 1 2\n 0 3\n 4 5\n 1 2 1\n 0 3 2", "output": "8 5\n 0 9 6\n 4 23 14"}] |
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space
character between adjacent elements. | s115443793 | Accepted | p02414 | In the first line, three integers $n$, $m$ and $l$ are given separated by
space characters
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$
matrix $B$ are given. | a, b, c = map(int, input().split())
d = []
for i in range(a):
d.append(list(map(int, list(input().split()))))
e = []
for i in range(b):
e.append(list(map(int, list(input().split()))))
g = []
f = []
total = 0
for k in range(a):
for i in range(c):
for j in range(b):
total += d[k][j] * e[j][i]
f.append(total)
total = 0
g.append(f)
f = []
for i in range(a):
for j in range(c):
if j == c - 1:
print("{}".format(g[i][j]), end="")
else:
print("{} ".format(g[i][j]), end="")
print()
| Matrix Multiplication
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$
matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of
matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$
respectively. | [{"input": "2 3\n 1 2\n 0 3\n 4 5\n 1 2 1\n 0 3 2", "output": "8 5\n 0 9 6\n 4 23 14"}] |
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space
character between adjacent elements. | s057639379 | Accepted | p02414 | In the first line, three integers $n$, $m$ and $l$ are given separated by
space characters
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$
matrix $B$ are given. | n, m, l = list(map(int, input().split(" ")))
matrix_a = [list(map(int, input().split(" "))) for i in range(n)]
matrix_b = [list(map(int, input().split(" "))) for j in range(m)]
matrix_c = [[0 for k in range(l)] for o in range(n)]
ans = 0
for a in range(n):
for b in range(l):
ans = 0
for c in range(m):
ans += matrix_a[a][c] * matrix_b[c][b]
matrix_c[a][b] = ans
for matrix in matrix_c:
print(*matrix)
| Matrix Multiplication
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$
matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of
matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$
respectively. | [{"input": "2 3\n 1 2\n 0 3\n 4 5\n 1 2 1\n 0 3 2", "output": "8 5\n 0 9 6\n 4 23 14"}] |
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space
character between adjacent elements. | s333177619 | Accepted | p02414 | In the first line, three integers $n$, $m$ and $l$ are given separated by
space characters
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$
matrix $B$ are given. | def matrixMultiplication(n, m, l, A, B):
result = list()
for i in range(n):
temp = list()
for j in range(l):
temp2 = list()
for k in range(m):
temp2.append(A[i][k] * B[k][j])
temp.append(sum(temp2))
result.append(temp)
return result
nml = [int(x) for x in input().split()]
A = list()
for i in range(nml[0]):
A.append([int(x) for x in input().split()])
B = list()
for i in range(nml[1]):
B.append([int(x) for x in input().split()])
C = matrixMultiplication(nml[0], nml[1], nml[2], A, B)
for i in range(len(C)):
for j in range(len(C[i])):
print(C[i][j], end=" " if j < len(C[i]) - 1 else "\n")
| Matrix Multiplication
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$
matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of
matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$
respectively. | [{"input": "2 3\n 1 2\n 0 3\n 4 5\n 1 2 1\n 0 3 2", "output": "8 5\n 0 9 6\n 4 23 14"}] |
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space
character between adjacent elements. | s130204299 | Accepted | p02414 | In the first line, three integers $n$, $m$ and $l$ are given separated by
space characters
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$
matrix $B$ are given. | if __name__ == "__main__":
n, m, l = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n)]
B = [[int(i) for i in input().split()] for j in range(m)]
B = list(map(list, zip(*B))) # trace
C = [[sum(map(lambda x, y: x * y, A[i], B[j])) for j in range(l)] for i in range(n)]
for i in C:
print(" ".join([str(x) for x in i]))
| Matrix Multiplication
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$
matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of
matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$
respectively. | [{"input": "2 3\n 1 2\n 0 3\n 4 5\n 1 2 1\n 0 3 2", "output": "8 5\n 0 9 6\n 4 23 14"}] |
Print elements of the $n \times l$ matrix $C$ ($c_{ij}$). Print a single space
character between adjacent elements. | s814145706 | Runtime Error | p02414 | In the first line, three integers $n$, $m$ and $l$ are given separated by
space characters
In the following lines, the $n \times m$ matrix $A$ and the $m \times l$
matrix $B$ are given. | 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")
elif m + f >= 80:
print("A")
elif 65 <= m + f:
print("B")
elif 50 <= m + f:
print("C")
elif 30 <= m + f:
if r >= 50:
print("C")
else:
print("D")
else:
print("F")
| Matrix Multiplication
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$
matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of
matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$
respectively. | [{"input": "2 3\n 1 2\n 0 3\n 4 5\n 1 2 1\n 0 3 2", "output": "8 5\n 0 9 6\n 4 23 14"}] |
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i
is an anagram of s_j.
* * * | s109158213 | Wrong Answer | p02947 | Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N | N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
D = {}
count = 0
for s in S:
if s in D:
D[s] = D[s] + 1
else:
D[s] = 0
V = list(D.values())
print(sum(V))
# #import sys
# # import math
#
# def modc(a, b, m):
# c = 1
# for i in range(b):
# c = c * (a - i) % m
# c = c * modinv(i + 1, m) % m
# return c
#
#
# def egcd(a, b):
# (x, lastx) = (0, 1)
# (y, lasty) = (1, 0)
# while b != 0:
# q = a // b
# (a, b) = (b, a % b)
# (x, lastx) = (lastx - q * x, x)
# (y, lasty) = (lasty - q * y, y)
# return (lastx, lasty, a)
#
#
# def modinv(a, m):
# (inv, q, gcd_val) = egcd(a, m)
# return inv % m
#
# N = int(input())
# #A, B = list(map(int,input().split()))
# S = [''.join(sorted(input())) for _ in range(N)]
# D = {}
# for s in S :
# if s in D :
# D[s] += 1
# else :
# D[s] = 1
# V = list(D.values())
#
# count = 0
# for v in V :
# if v == 1 :
# count += 0
# elif v == 2 :
# count += 1
# elif v >= 3 :
# count += modc(v, 2, 2 ** 63 - 1)
# print(count)
| Statement
We will call a string obtained by arranging the characters contained in a
string a in some order, an _anagram_ of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the
same character occurs multiple times, that character must be used that number
of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length
of 10 and consists of lowercase English characters. Additionally, all of these
strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j
\leq N) such that s_i is an anagram of s_j. | [{"input": "3\n acornistnt\n peanutbomb\n constraint", "output": "1\n \n\ns_1 = `acornistnt` is an anagram of s_3 = `constraint`. There are no other\npairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\n* * *"}, {"input": "2\n oneplustwo\n ninemodsix", "output": "0\n \n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\n* * *"}, {"input": "5\n abaaaaaaaa\n oneplustwo\n aaaaaaaaba\n twoplusone\n aaaabaaaaa", "output": "4\n \n\nNote that the answer may not fit into a 32-bit integer type, though we cannot\nput such a case here."}] |
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i
is an anagram of s_j.
* * * | s814881134 | Runtime Error | p02947 | Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N | number = int(input())
List = [list(map(input() for i in range(number)))]
print(List)
| Statement
We will call a string obtained by arranging the characters contained in a
string a in some order, an _anagram_ of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the
same character occurs multiple times, that character must be used that number
of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length
of 10 and consists of lowercase English characters. Additionally, all of these
strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j
\leq N) such that s_i is an anagram of s_j. | [{"input": "3\n acornistnt\n peanutbomb\n constraint", "output": "1\n \n\ns_1 = `acornistnt` is an anagram of s_3 = `constraint`. There are no other\npairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\n* * *"}, {"input": "2\n oneplustwo\n ninemodsix", "output": "0\n \n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\n* * *"}, {"input": "5\n abaaaaaaaa\n oneplustwo\n aaaaaaaaba\n twoplusone\n aaaabaaaaa", "output": "4\n \n\nNote that the answer may not fit into a 32-bit integer type, though we cannot\nput such a case here."}] |
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i
is an anagram of s_j.
* * * | s997105066 | Wrong Answer | p02947 | Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N | n = int(input())
s = [str(sorted(input())) for _ in range(n)]
se = set(s)
print(len(s) - len(se))
| Statement
We will call a string obtained by arranging the characters contained in a
string a in some order, an _anagram_ of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the
same character occurs multiple times, that character must be used that number
of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length
of 10 and consists of lowercase English characters. Additionally, all of these
strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j
\leq N) such that s_i is an anagram of s_j. | [{"input": "3\n acornistnt\n peanutbomb\n constraint", "output": "1\n \n\ns_1 = `acornistnt` is an anagram of s_3 = `constraint`. There are no other\npairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\n* * *"}, {"input": "2\n oneplustwo\n ninemodsix", "output": "0\n \n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\n* * *"}, {"input": "5\n abaaaaaaaa\n oneplustwo\n aaaaaaaaba\n twoplusone\n aaaabaaaaa", "output": "4\n \n\nNote that the answer may not fit into a 32-bit integer type, though we cannot\nput such a case here."}] |
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i
is an anagram of s_j.
* * * | s077733874 | Accepted | p02947 | Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N | n = int(input())
N = []
for i in range(n):
N.append(input())
Nn = [sorted(j) for j in N]
Nn.sort()
Nh = []
for let in Nn:
Nh.append(("").join(let))
c_dict = {}
for letters in Nh:
if letters not in c_dict:
c_dict[letters] = 1
elif letters in c_dict:
c_dict[letters] += 1
ans_list = []
for letter, num in c_dict.items():
ans_list.append((num * (num - 1)) // 2)
print(sum(ans_list))
| Statement
We will call a string obtained by arranging the characters contained in a
string a in some order, an _anagram_ of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the
same character occurs multiple times, that character must be used that number
of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length
of 10 and consists of lowercase English characters. Additionally, all of these
strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j
\leq N) such that s_i is an anagram of s_j. | [{"input": "3\n acornistnt\n peanutbomb\n constraint", "output": "1\n \n\ns_1 = `acornistnt` is an anagram of s_3 = `constraint`. There are no other\npairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\n* * *"}, {"input": "2\n oneplustwo\n ninemodsix", "output": "0\n \n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\n* * *"}, {"input": "5\n abaaaaaaaa\n oneplustwo\n aaaaaaaaba\n twoplusone\n aaaabaaaaa", "output": "4\n \n\nNote that the answer may not fit into a 32-bit integer type, though we cannot\nput such a case here."}] |
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i
is an anagram of s_j.
* * * | s855266528 | Accepted | p02947 | Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N | char_num = int(input())
char_length = 10
chars = []
for i in range(char_num):
chars.append(input())
class CharArrange:
def __init__(self, char):
self.char = char
def char_run(self):
list_char = self.str2ord_list(self.char)
for pos in range(1, len(list_char)):
self.insert_sort(list_char, pos, list_char[pos])
self.char = self.ordList2Str(list_char)
def order_run(self, chars):
for i, char in enumerate(chars):
chars[i] = self.ord_list2ord_concat(self.str2ord_list(char))
for pos in range(len(chars)):
self.insert_sort(chars, pos, chars[pos])
self.ord_chars = chars
def str2ord_list(self, char):
return list(map(ord, char))
def ordList2Str(self, ordList):
return "".join(list(map(chr, ordList)))
def ord_list2ord_concat(self, ord_list):
self.ord_concat = ""
for ord_num in ord_list:
self.ord_concat += str(ord_num)
return int(self.ord_concat)
def insert_sort(self, A, pos, value):
i = pos - 1
while i >= 0 and A[i] > value:
A[i + 1] = A[i]
i = i - 1
A[i + 1] = value
return A
counter = 0
hash_table = {}
for i, char in enumerate(chars):
CA = CharArrange(char)
CA.char_run()
if CA.char in hash_table:
hash_table[CA.char] += 1
else:
hash_table[CA.char] = 0
counter += hash_table[CA.char]
print(counter)
| Statement
We will call a string obtained by arranging the characters contained in a
string a in some order, an _anagram_ of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the
same character occurs multiple times, that character must be used that number
of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length
of 10 and consists of lowercase English characters. Additionally, all of these
strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j
\leq N) such that s_i is an anagram of s_j. | [{"input": "3\n acornistnt\n peanutbomb\n constraint", "output": "1\n \n\ns_1 = `acornistnt` is an anagram of s_3 = `constraint`. There are no other\npairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\n* * *"}, {"input": "2\n oneplustwo\n ninemodsix", "output": "0\n \n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\n* * *"}, {"input": "5\n abaaaaaaaa\n oneplustwo\n aaaaaaaaba\n twoplusone\n aaaabaaaaa", "output": "4\n \n\nNote that the answer may not fit into a 32-bit integer type, though we cannot\nput such a case here."}] |
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i
is an anagram of s_j.
* * * | s869710438 | Runtime Error | p02947 | Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N | import numpy as np
N = int(input())
a = []
b = []
c = np.array([[0] * 26, [0] * 26, [0] * 26])
count = 0
for i in range(N):
a.append(input())
for i in range(N):
b = a[i]
for j in range(10):
if b[j] == "a":
c[i][0] += 1
elif b[j] == "b":
c[i][1] += 1
elif b[j] == "c":
c[i][2] += 1
elif b[j] == "d":
c[i][3] += 1
elif b[j] == "e":
c[i][4] += 1
elif b[j] == "f":
c[i][5] += 1
elif b[j] == "g":
c[i][6] += 1
elif b[j] == "h":
c[i][7] += 1
elif b[j] == "i":
c[i][8] += 1
elif b[j] == "j":
c[i][9] += 1
elif b[j] == "k":
c[i][10] += 1
elif b[j] == "l":
c[i][11] += 1
elif b[j] == "m":
c[i][12] += 1
elif b[j] == "n":
c[i][13] += 1
elif b[j] == "o":
c[i][14] += 1
elif b[j] == "p":
c[i][15] += 1
elif b[j] == "q":
c[i][16] += 1
elif b[j] == "r":
c[i][17] += 1
elif b[j] == "s":
c[i][18] += 1
elif b[j] == "t":
c[i][19] += 1
elif b[j] == "u":
c[i][20] += 1
elif b[j] == "v":
c[i][21] += 1
elif b[j] == "w":
c[i][22] += 1
elif b[j] == "x":
c[i][23] += 1
elif b[j] == "w":
c[i][24] += 1
elif b[j] == "z":
c[i][25] += 1
for i in range(N):
for j in range(1, N):
if i != j:
if (c[i] == c[j]).all():
count += 1
print(count)
| Statement
We will call a string obtained by arranging the characters contained in a
string a in some order, an _anagram_ of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the
same character occurs multiple times, that character must be used that number
of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length
of 10 and consists of lowercase English characters. Additionally, all of these
strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j
\leq N) such that s_i is an anagram of s_j. | [{"input": "3\n acornistnt\n peanutbomb\n constraint", "output": "1\n \n\ns_1 = `acornistnt` is an anagram of s_3 = `constraint`. There are no other\npairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\n* * *"}, {"input": "2\n oneplustwo\n ninemodsix", "output": "0\n \n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\n* * *"}, {"input": "5\n abaaaaaaaa\n oneplustwo\n aaaaaaaaba\n twoplusone\n aaaabaaaaa", "output": "4\n \n\nNote that the answer may not fit into a 32-bit integer type, though we cannot\nput such a case here."}] |
Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i
is an anagram of s_j.
* * * | s141251780 | Runtime Error | p02947 | Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N | def giaithua1(x):
if x == 1:
return 1
else:
return x * giaithua1(x - 1)
n = int(input())
s = []
t = input()
a = [0] * 27
for i in t:
a[ord(i) - 97] += 1
a[26] = 1
s.append(a)
for i in range(n - 1):
t = input()
a = [0] * 27
for j in t:
a[ord(j) - 97] += 1
t = set(t)
l = len(s)
ok = 0
for j in range(l):
tam = 1
for k in t:
b = ord(k) - 97
if a[b] != s[j][b]:
tam = 0
break
if tam == 1:
s[j][26] += 1
ok = 1
break
# print(ok)
if ok == 0:
a[26] = 1
s.append(a)
kq = 0
for i in range(len(s)):
if s[i][26] == 2:
kq += 1
elif s[i][26] > 2:
t = giaithua1(s[i][26]) / (giaithua1(2) * giaithua1(s[i][26] - 2))
kq += t
print(int(kq))
| Statement
We will call a string obtained by arranging the characters contained in a
string a in some order, an _anagram_ of a.
For example, `greenbin` is an anagram of `beginner`. As seen here, when the
same character occurs multiple times, that character must be used that number
of times.
Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length
of 10 and consists of lowercase English characters. Additionally, all of these
strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j
\leq N) such that s_i is an anagram of s_j. | [{"input": "3\n acornistnt\n peanutbomb\n constraint", "output": "1\n \n\ns_1 = `acornistnt` is an anagram of s_3 = `constraint`. There are no other\npairs i, j such that s_i is an anagram of s_j, so the answer is 1.\n\n* * *"}, {"input": "2\n oneplustwo\n ninemodsix", "output": "0\n \n\nIf there is no pair i, j such that s_i is an anagram of s_j, print 0.\n\n* * *"}, {"input": "5\n abaaaaaaaa\n oneplustwo\n aaaaaaaaba\n twoplusone\n aaaabaaaaa", "output": "4\n \n\nNote that the answer may not fit into a 32-bit integer type, though we cannot\nput such a case here."}] |
Print the number of the different good touring plans, modulo 10^9+7.
* * * | s281248502 | Wrong Answer | p03655 | Input is given from Standard Input in the following format:
X_1 X_2 X_3 X_4 X_5 X_6
Y_1 Y_2 Y_3 Y_4 Y_5 Y_6 | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M, *X = map(int, read().split())
MOD = 10**9 + 7
def mult(a, b, c, d, e, f):
# (a+bx+cx^2)(d+ex+fx^2) modulo 1-4x+2x^2-x^3
a, b, c, d, e = a * d, a * e + b * d, a * f + b * e + c * d, b * f + c * e, c * f
b += e
c -= 4 * e
d += 2 * e
e = 0
a += d
b -= 4 * d
c += 2 * d
d = 0
a %= MOD
b %= MOD
c %= MOD
return a, b, c
# (1/x)^i modulo (1-4x+2x^2-x^3)
M = 10**5
A1 = [0] * (M + 1)
a, b, c = 1, 0, 0
for i in range(M + 1):
A1[i] = (a, b, c)
a, b, c = b + 4 * a, c - 2 * a, a
a %= MOD
b %= MOD
c %= MOD
# (1/x)^Mi modulo (1-4x+2x^2-x^3)
A2 = [0] * (M + 1)
a, b, c = 1, 0, 0
d, e, f = A1[M]
for i in range(M + 1):
A2[i] = (a, b, c)
a, b, c = mult(a, b, c, d, e, f)
def power(n):
# (1/x)^n modulo (1-4x+2x^2-x^3)
q, r = divmod(n, M)
a, b, c = A1[r]
d, e, f = A2[q]
return mult(a, b, c, d, e, f)
X.append(N)
a, b, c = 0, 1, 1
prev_x = 0
for x in X:
a, b, c = mult(a, b, c, *power(x - prev_x))
b -= a
c -= a
prev_x = x
answer = a
print(answer)
| Statement
Joisino is planning on touring Takahashi Town. The town is divided into square
sections by north-south and east-west lines. We will refer to the section that
is the x-th from the west and the y-th from the north as (x,y).
Joisino thinks that a _touring plan_ is good if it satisfies the following
conditions:
* Let (p,q) be the section where she starts the tour. Then, X_1 \leq p \leq X_2 and Y_1 \leq q \leq Y_2 hold.
* Let (s,t) be the section where she has lunch. Then, X_3 \leq s \leq X_4 and Y_3 \leq t \leq Y_4 hold.
* Let (u,v) be the section where she ends the tour. Then, X_5 \leq u \leq X_6 and Y_5 \leq v \leq Y_6 hold.
* By repeatedly moving to the adjacent section (sharing a side), she travels from the starting section to the ending section in the shortest distance, passing the lunch section on the way.
Two touring plans are considered different if at least one of the following is
different: the starting section, the lunch section, the ending section, and
the sections that are visited on the way. Joisino would like to know how many
different good touring plans there are. Find the number of the different good
touring plans. Since it may be extremely large, find the count modulo 10^9+7. | [{"input": "1 1 2 2 3 4\n 1 1 2 2 3 3", "output": "10\n \n\nThe starting section will always be (1,1), and the lunch section will always\nbe (2,2). There are four good touring plans where (3,3) is the ending section,\nand six good touring plans where (4,3) is the ending section. Therefore, the\nanswer is 6+4=10.\n\n* * *"}, {"input": "1 2 3 4 5 6\n 1 2 3 4 5 6", "output": "2346\n \n\n* * *"}, {"input": "77523 89555 420588 604360 845669 973451\n 2743 188053 544330 647651 709337 988194", "output": "137477680"}] |
Print the maximum possible length of the sequence.
* * * | s109114709 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | # coding: utf-8
def main():
X, Y = map(int, input().split())
ans = 0
while (X <= Y){
x *= 2
ans += 1
}
print(ans)
if __name__ == "__main__":
main()
| Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s454055464 | Accepted | p03481 | Input is given from Standard Input in the following format:
X Y | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9 + 7
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def S():
return input()
def pf(s):
return print(s, flush=True)
def main():
x, y = LI()
r = 0
while x <= y:
x *= 2
r += 1
return r
print(main())
| Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s701268971 | Accepted | p03481 | Input is given from Standard Input in the following format:
X Y | import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range
def Golf():
n, *t = map(int, open(0).read().split())
def I():
return int(input())
def S_():
return input()
def IS():
return input().split()
def LS():
return [i for i in input().split()]
def MI():
return map(int, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def NI(n):
return [int(input()) for i in range(n)]
def NI_(n):
return [int(input()) - 1 for i in range(n)]
def StoLI():
return [ord(i) - 97 for i in input()]
def ItoS(n):
return chr(n + 97)
def LtoS(ls):
return "".join([chr(i + 97) for i in ls])
def Ra():
return map(int, open(0).read().split())
def GI(V, E, ls=None, Directed=False, index=1):
org_inp = []
g = [[] for i in range(V)]
FromStdin = True if ls == None else False
for i in range(E):
if FromStdin:
inp = LI()
org_inp.append(inp)
else:
inp = ls[i]
if len(inp) == 2:
a, b = inp
c = 1
else:
a, b, c = inp
if index == 1:
a -= 1
b -= 1
aa = (a, c)
bb = (b, c)
g[a].append(bb)
if not Directed:
g[b].append(aa)
return g, org_inp
def GGI(
h, w, search=None, replacement_of_found=".", mp_def={"#": 1, ".": 0}, boundary=1
):
# h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
mp = [boundary] * (w + 2)
found = {}
for i in R(h):
s = input()
for char in search:
if char in s:
found[char] = (i + 1) * (w + 2) + s.index(char) + 1
mp_def[char] = mp_def[replacement_of_found]
mp += [boundary] + [mp_def[j] for j in s] + [boundary]
mp += [boundary] * (w + 2)
return h + 2, w + 2, mp, found
def TI(n):
return GI(n, n - 1)
def accum(ls):
rt = [0]
for i in ls:
rt += [rt[-1] + i]
return rt
def bit_combination(n, base=2):
rt = []
for tb in R(base**n):
s = [tb // (base**bt) % base for bt in R(n)]
rt += [s]
return rt
def gcd(x, y):
if y == 0:
return x
if x % y == 0:
return y
while x % y != 0:
x, y = y, x % y
return y
def YN(x):
print(["NO", "YES"][x])
def Yn(x):
print(["No", "Yes"][x])
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
mo = 10**9 + 7
inf = float("inf")
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip("WENS", FourNb))
cursol = dict(zip("LRUD", FourNb))
l_alp = string.ascii_lowercase
sys.setrecursionlimit(10**9)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda: sys.stdin.readline().rstrip()
########################################################################################################################################################################
show_flg = False
show_flg = True
ans = 0
x, y = LI()
while y >= x:
y >>= 1
ans += 1
print(ans)
| Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s048197645 | Accepted | p03481 | Input is given from Standard Input in the following format:
X Y | from statistics import mean, median, variance, stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
# 以下てんぷら
def j(q):
if q == 1:
print("Yes")
elif q == 0:
print("No")
exit(0)
"""
def ct(x,y):
if (x>y):print("+")
elif (x<y): print("-")
else: print("?")
"""
def ip():
return int(input())
def printrow(a):
for i in range(len(a)):
print(a[i])
def combinations(n, r):
if n < r:
return 0
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n, r):
if n < r:
return 0
return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
# n = ip() #入力整数1つ
n, k = (int(i) for i in input().split()) # 入力整数横2つ以上
# a = [int(i) for i in input().split()] #入力整数配列
# a = input() #入力文字列
# a = input().split() #入力文字配列
# n = ip() #入力セット(整数改行あり)(1/2)
# a=[ip() for i in range(n)] #入力セット(整数改行あり)(2/2)
# a=[input() for i in range(n)] #入力セット(整数改行あり)(2/2)
# jの変数はしようできないので注意
# 全足しにsum変数使用はsum関数使用できないので注意
s = 0
while n <= k:
s += 1
n *= 2
print(s)
| Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s306868117 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | X=input()
Y=input()
cnt=0
for i in range(X:Y):
if i%X==0:
cnt+=1
print(cnt) | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s335048003 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | X, Y = map(int, input().split())
cnt = 0
while X <= Y
cnt += 1
X *= 2
print(cnt) | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Print the maximum possible length of the sequence.
* * * | s338160775 | Runtime Error | p03481 | Input is given from Standard Input in the following format:
X Y | X=input()
Y=input()
cnt=0
for i<Y:
if i%X==0:
cnt+=1
print(cnt) | Statement
As a token of his gratitude, Takahashi has decided to give his mother an
integer sequence. The sequence A needs to satisfy the conditions below:
* A consists of integers between X and Y (inclusive).
* For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i.
Find the maximum possible length of the sequence. | [{"input": "3 20", "output": "3\n \n\nThe sequence 3,6,18 satisfies the conditions.\n\n* * *"}, {"input": "25 100", "output": "3\n \n\n* * *"}, {"input": "314159265 358979323846264338", "output": "31"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.