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 there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s218265557 | Wrong Answer | p03285 | Input is given from Standard Input in the following format:
N | print("Yes" if int(input()) in [1, 2, 3, 5, 6, 9, 10, 13, 17] else "No")
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s207645889 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | n = input()
if n % 4 ==0 or n % 7 ==0:
print('Yes')
exit()
for i in range(n // 4 + 1):
for j in range (n // + 1):
if 4 * i + 7 * == n:
print('Yes')
exit()
print('No') | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s957892297 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | import math
n = int(input())
if n % 7 == 0 || n % 4 == 0:
print("Yes")
elif n % 7 % 4 == 0 || n % 4 % 7 == 0:
print("Yes")
else:
print("No")
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s663403464 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | def calc(a):
for a4 in range(26):
for a7 in range(16):
if a4*4+a7*7 is a:
return "Yes"
return "No"
if __name__ == '__main__':
calc(int(input())
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s434819623 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | a = int(input())
if a > 3:
if a % 4 == 0 or a % 7 == 0 or a % 7 == 4 or a % 7 == 1 or a % 4 == 3:
print("Yes")
else:
print("No")
else:
print("No")
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s565277984 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | N = int(input())
flag = False
for i in range(N//4 +1):
for j in range(N//7 +1):
if 4*i + 7*j == N:
print("Yes")
flag = True
break
if flag:
break
else:
print("No") | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s087434203 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | N = int(input())
flag = 0
for cake in range(26):
for donut in range(15):
if cake*4 + donut*7 == N:
flag = 1
break
if flag == 1:
break
if flag = 1:
print("Yes")
else :
print("No")
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s616634517 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | N = int(input())
for i in range(25)
for j in range(15)
if N == 4*i + 7*j:
print('Yes')
break
print('No')
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s633401869 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | n = int(input())
if n%4 ==0 or n%7 == 0:
print('Yes')
exit()
for _ in range(n//7):
n -=7
if n == 4:
print('Yes')
else:
print('No') | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s954031151 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | n = int(input())
p = 0
for i in range(26)
for j in range(16)
if 4*i + 7*j == n:
p == 1
break
if p == 0:
print("No")
else:
print("Yes") | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s916134139 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | N=int(input())
if N%4==0 or N%7==0:
print('Yes')
elif:
while 0<N:
N-=7
if N%4:
print('Yes')
break
else:
print('No')
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s257671983 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | n = int(input())
for i in range((n//4)+1):
for j in range((n//7)+1):
if (i*4) + (j*7) == n:
print("Yes")
exit()
print("No" | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s742570167 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | n=int(input())
swi = "No"
for a in range(n//4 +1)
if (n - 4*a) % 7 == 0 and n - 4*a >= 0:
swi="Yes"
break
print(swi)
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s135257615 | Accepted | p03285 | Input is given from Standard Input in the following format:
N | x = int(input())
print("No" if x < 4 or 4 < x < 7 or 8 < x < 11 or x == 13 or x == 17 else "Yes")
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s753703065 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | A = int(input())
if (A%4 == 3 or A%4 == 0 A%7 == 4 or A%7) and A != 3:
print('Yes')
else:
print('No') | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s085276707 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | n=int(input())
for i in range(15):
for j in range(26):
if i*7+j*4=n:
print('Yes')
exit()
print('No') | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s421855784 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | N = int(input())
for x in range(N/4)
for y in range(N/7)
if(4*x + 7*y ==)
print("Yes")
break
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s198821695 | Wrong Answer | p03285 | Input is given from Standard Input in the following format:
N | print("No") if int(input()) in [1, 2, 3, 5, 6, 9, 13, 17] else print("Yes")
| Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s377955050 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | A = int(input())
if (A%4 == 3 or A%4 == 0 A%7 == 4 or A%7 == 0) and A != 3:
print('Yes')
else:
print('No') | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
If there is a way to buy some cakes and some doughnuts for exactly N dollars,
print `Yes`; otherwise, print `No`.
* * * | s775068615 | Runtime Error | p03285 | Input is given from Standard Input in the following format:
N | N = int(input())
for i in range():
for j in range():
if 4*i+7*j==N:
print('YES')
else:
print('NO') | Statement
_La Confiserie d'ABC_ sells cakes at 4 dollars each and doughnuts at 7
dollars each. Determine if there is a way to buy some of them for exactly N
dollars. You can buy two or more doughnuts and two or more cakes, and you can
also choose to buy zero doughnuts or zero cakes. | [{"input": "11", "output": "Yes\n \n\nIf you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.\n\n* * *"}, {"input": "40", "output": "Yes\n \n\nIf you buy ten cakes, the total will be 4 \\times 10 = 40 dollars.\n\n* * *"}, {"input": "3", "output": "No\n \n\nThe prices of cakes (4 dollars) and doughnuts (7 dollars) are both higher than\n3 dollars, so there is no such way."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s476830639 | Runtime Error | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | from sys import stdin
from math import factorial
n, k = map(int, stdin.readline().rstrip().split())
li = list(map(int, stdin.readline().rstrip().split()))
li_to = li * 2
nai = 0
ato = 0
for i in range(len(li)):
for s in range(i + 1, len(li)):
if li[i] > li[s]:
nai += 1
for p in range(len(li), len(li_to)):
if li[i] > li_to[p]:
ato += 1
def combinations_count(n, r):
return factorial(n) // (factorial(n - r) * factorial(r))
point = 0
point += (nai * k) + (ato * combinations_count(k, 2))
print(point % (10**9 + 7))
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s864195221 | Accepted | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | import copy
def j(n):
if n:
print("Yes")
else:
print("No")
exit(0)
rem = 10**9 + 7
"""
def ct(x,y):
if (x>y):print("+")
elif (x<y): print("-")
else: print("?")
"""
def ip():
return int(input())
def iprow():
return [int(i) for i in input().split()]
def ips():
return (int(i) for i in input().split())
def printrow(a):
for i in a:
print(i)
s = 0
n, r = ips()
a = iprow()
other = 0
for i in range(n):
for k in range(n):
if a[i] > a[k] and i < k:
s += 1
elif i > k and a[i] > a[k]:
other += 1
adder = 0
rate = s
ans = 0
ans = ((s + (s * r)) * r) // 2 + ((other + other * (r - 1)) * (r - 1)) // 2
print(ans % rem)
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s767561757 | Wrong Answer | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | a = input().split(" ")
N = int(a[0])
K = int(a[1])
sequence_list = input().split(" ")
sequence = []
for i in range(0, N):
sequence.append(int(sequence_list[i]))
count = 0
for p in range(0, N):
count1 = 0
count2 = 0
for q in range(0, p):
if sequence[p] - sequence[q] > 0:
count1 += 1
print(sequence[p])
print("a")
if p != N - 1:
for r in range(p, N):
if sequence[p] - sequence[r] > 0:
count2 += 1
print(sequence[p])
print("b")
count += ((count1 + count2) * (K - 1) + count2 + count2) * K / 2
else:
count += (count1 * (K - 1)) * K / 2
print(sequence[p])
print("c")
print(int(count % (10**9 + 7)))
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s631101644 | Wrong Answer | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | N, K = (int(x) for x in input().split())
C = list((int(x) for x in input().split()))
B = [0 for i in range(N * K)]
A = []
for i in range(K):
A += C
sum00 = 0
sum0 = 0
for i in range(N * K):
B[A[i] - 1] += 1
sum0 += i + 1 - sum(B[: i + 1])
print(sum0)
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s894285694 | Accepted | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | # coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
# from heapq import heappop, heappush
# from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
# import numpy as np
# from copy import deepcopy
# from collections import deque
class segtree:
def __init__(self, n, init_val=0):
self.n = n
self.init_val = init_val
self.init = 0
self.k = math.ceil(math.log2(n))
if type(self.init_val) == int:
self.bins = [init_val] * (1 << (self.k + 1))
elif len(self.init_val) > 0:
self.bins = [self.init] * (1 << (self.k + 1))
for idx, i in enumerate(range(1 << self.k, 1 << (self.k + 1))):
if len(self.init_val) > idx:
self.bins[i] = init_val[idx]
else:
self.bins[i] = 0
else:
raise ValueError("init_val is invalid.")
self.caliculate()
def compare(self, l, r):
return l + r
def caliculate(self):
k = self.k
while k:
for i in range(1 << k, 1 << (k + 1)):
if not i % 2:
self.bins[i // 2] = self.compare(self.bins[i], self.bins[i + 1])
else:
continue
k -= 1
def update(self, idx, val):
"""idx : 0-started index"""
k = (1 << self.k) + idx
self.bins[k] = val
while k > 1:
self.bins[k // 2] = self.compare(
self.bins[k // 2 * 2], self.bins[k // 2 * 2 + 1]
)
k = k // 2
def eval(self, l, r):
ret = self.init
l = (1 << self.k) + l
r = (1 << self.k) + r
# print(l, r)
while True:
# print(l, r)
if r - l == 1:
ret = self.compare(ret, self.bins[l])
ret = self.compare(ret, self.bins[r])
break
elif l == r:
ret = self.compare(ret, self.bins[l])
break
else:
done = False
if l % 2:
ret = self.compare(ret, self.bins[l])
l += 1
done = True
if not r % 2:
ret = self.compare(ret, self.bins[r])
r -= 1
done = True
if not done:
l = l // 2
r = r // 2
# print(ret)
return ret
def value(self, ind):
return self.bins[(1 << self.k) + ind]
def run():
N, K = list(map(int, sysread().split()))
A = list(map(int, sysread().split()))
st = segtree(2001, 0)
T1 = [0] * N
for i in list(range(N))[::-1]:
T1[i] = st.eval(0, A[i] - 1)
st.update(A[i], st.value(A[i]) + 1)
# print(st.bins)
T2 = []
for a in A:
T2.append(st.eval(0, a - 1))
ret = 0
mod = 10**9 + 7
# print(T1, T2)
tmp_k2 = K * (K - 1) // 2
tmp_k2 %= mod
for t1, t2 in zip(T1, T2):
ret += K * t1 % mod
tmp = tmp_k2
tmp %= mod
tmp *= t2
tmp %= mod
ret += tmp
ret %= mod
print(ret)
if __name__ == "__main__":
run()
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s700764438 | Wrong Answer | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | import logging
logging.basicConfig(level=logging.INFO, format="%(message)s")
# logging.disable(logging.CRITICAL)
def count_inversion(sequence):
return sum(sum(m < n for m in sequence[i + 1 :]) for i, n in enumerate(sequence))
def count_ponpon(sequence):
counter = 0
split_count = 0
splited = 0
num = len(sequence)
for i in sequence:
split_count = sequence.count(i)
counter += num - split_count - splited
splited += 1
logging.info(counter)
return counter
def main():
N, K = map(int, input().split())
A_1 = list(map(int, input().split()))
MODI = 10**9 + 7
logging.info("Hello!")
A_counter = count_inversion(A_1)
k_counter = int((K) * (K - 1) / 2)
A_ = count_ponpon(A_1)
print((A_counter * K + k_counter * A_) % MODI)
if __name__ == "__main__":
main()
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s744431718 | Wrong Answer | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | print(1)
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s847774660 | Runtime Error | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
class BinaryIndexedTree:
"""
Parameters
----------
array : list
to construct BIT from
f : func
binary operation of the abelian group
fi : func
inverse mapping of f
i.e. f(a, b) == c <-> fi(c, a) == b
e :
identity element of the abelian group
size : int
limit for array size
"""
def __init__(self, array, f, fi, e, size):
self.f = f
self.fi = fi
self.e = e
self.size = size
self.n = len(array)
self.dat = [e] * (size + 1)
self.array = [e] * size
self.build(array)
def build(self, array_):
for i, v in enumerate(array_):
self.modify(i, v)
def modify(self, p, v):
"""
set value at position p (0-indexed)
"""
self.add(p, self.fi(v, self.array[p]))
def add(self, p, dv):
"""
add value at position p (0-indexed)
"""
fi, dat, f, size, array = self.fi, self.dat, self.f, self.size, self.array
array[p] = f(array[p], dv)
p += 1
while p <= size:
dat[p] = f(dat[p], dv)
p += p & -p
def query(self, l, r):
"""
result on interval [l, r) (0-indexed)
"""
return self.fi(self._query(r), self._query(l))
def _query(self, p):
dat, f, res = self.dat, self.f, self.e
while p:
res = f(res, dat[p])
p -= p & -p
return res
f = lambda x, y: x + y
fi = lambda z, x: z - x
e = 0
BIT = BinaryIndexedTree([0] * (N + 1), f=f, fi=fi, e=e, size=N + 1)
ans1 = N * (N + 1) // 2
for a in A:
BIT.add(a, 1)
ans1 -= BIT._query(a + 1)
BIT = BinaryIndexedTree([0] * (2 * N + 1), f=f, fi=fi, e=e, size=2 * N + 1)
ans2 = 2 * N * (2 * N + 1) // 2
for a in A:
BIT.add(a, 1)
ans2 -= BIT._query(a + 1)
for a in A:
BIT.add(a, 1)
ans2 -= BIT._query(a + 1)
BIT = BinaryIndexedTree([0] * (3 * N + 1), f=f, fi=fi, e=e, size=3 * N + 1)
ans3 = 3 * N * (3 * N + 1) // 2
for a in A:
BIT.add(a, 1)
ans3 -= BIT._query(a + 1)
for a in A:
BIT.add(a, 1)
ans3 -= BIT._query(a + 1)
for a in A:
BIT.add(a, 1)
ans3 -= BIT._query(a + 1)
x = ans1
y = ans2
z = ans3
mod = 10**9 + 7
K -= 1
print((((K - 2) * (K - 1) * x - 2 * K * (K - 2) * y + (K - 1) * K * z) // 2) % mod)
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s896996126 | Accepted | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | import sys
input = sys.stdin.readline
def read():
N, K = map(int, input().strip().split())
A = list(map(int, input().strip().split()))
return N, K, A
class ModInt(int):
MOD = 10**9 + 7
def __new__(cls, x, *args, **kwargs):
return super().__new__(cls, x % ModInt.MOD)
def __add__(self, other):
return ModInt(super().__add__(other) % ModInt.MOD)
def __radd__(self, other):
return ModInt(super().__radd__(other) % ModInt.MOD)
def __mul__(self, other):
return ModInt(super().__mul__(other) % ModInt.MOD)
def __rmul__(self, other):
return ModInt(super().__rmul__(other) % ModInt.MOD)
def __pow__(self, other, *args):
return ModInt(super().__pow__(other, ModInt.MOD))
def __rpow__(self, other, *args):
raise NotImplementedError()
def __truediv__(self, other):
return ModInt(super().__mul__(pow(other, ModInt.MOD - 2, ModInt.MOD)))
def __floordiv__(self, other):
return self.__truediv__(other)
def __rtruediv__(self, other):
return ModInt(self.__pow__(ModInt.MOD - 2).__mul__(other))
def __rfloordiv__(self, other):
return self.__rtruediv__(other)
def solve(N, K, A):
ModInt.MOD = 10**9 + 7
N = len(A)
k = ModInt(K)
t0 = k * (k + 1) // 2 # 三角数
t1 = (k - 1) * k // 2
c0 = 0
c1 = 0
for i in range(N):
for j in range(i + 1, N):
if A[i] > A[j]:
c0 += 1
elif A[i] < A[j]:
c1 += 1
return c0 * t0 + c1 * t1
if __name__ == "__main__":
inputs = read()
outputs = solve(*inputs)
if outputs is not None:
print("%s" % str(outputs))
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s727914344 | Wrong Answer | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | # https://atcoder.jp/contests/jsc2019-qual/tasks/jsc2019_qual_b
# B - Kleene Inversion
import math
n, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
w = (10**9) + 7
unit_c = 0
# 1個の中だと
for i, a in enumerate(a_list[:-1]):
unit_c += len([x for x in a_list[i:] if x < a])
appendix = 0
# print(a_list[-1], a_list[0])
if len(a_list) > 1:
for a in a_list:
# 自分より小さいやつの数
appendix += len([x for x in a_list if x < a])
# 2回以上繰り返す場合
# print('unit_c: {}'.format(unit_c))
# print('appendix: {}'.format(appendix))
# total_tento_1 = unit_c * (k-1)
if k - 1 == 1:
work = 1
elif (k - 1) % 2 == 0:
work = (1 + (k - 1)) * ((k - 1) / 2)
else:
mid_index = math.floor((k - 1) / 2) + 1
work = (1 + (k - 1)) * math.floor((k - 1) / 2)
work += mid_index
t_1 = (unit_c * k) % w
t_21 = appendix % w
t_22 = work % w
t_2 = (t_21 * t_22) % w
ans = int((t_1 + t_2) % w)
# ans = ((unit_c * k) + (appendix * work)) % w
# total_amari = int(total_tento % w)
print(ans)
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s663910713 | Accepted | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | N, K = map(int, input().split())
A_list = [int(i) for i in input().split()]
# 自分自身の中で、転倒するような数 * N-1
# 最後の繰り返しは、転倒しないので別途計算
## これじゃダメで、転倒数はどんどん減少していくはず。
# 順序が関係するのは最初のブロックだけ
# あとは、繰り返しになる(繰り返し数が減っていく)
# まず、順序を含めた合算個数を調べる
count_with_seq = 0
deal = 0
for i in range(N):
ai = A_list[i]
for k in range(i + 1, N):
deal += 1
ak = A_list[k]
if ai > ak:
# print(ai,ak)
count_with_seq += 1
count_without_seq = 0
for ai in A_list:
for ak in A_list:
if ai > ak:
count_without_seq += 1
# print(count_with_seq,count_without_seq)
# これらの塊の繰り返し数は、
# 初項:N回
# 初項以降 : sum(k) (1<=K<=n-1)
total_count = count_with_seq * K
# print(total_count)
rep = (1 + (K - 1)) * (K - 1) // 2
total_count += count_without_seq * rep
# print(rep)
print(total_count % 1000000007)
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the inversion number of B, modulo 10^9 + 7.
* * * | s860570792 | Accepted | p02928 | Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1} | n, k = map(int, input().split())
# 10**9+7 で割った余り
# k = k %(10**9 + 7)
# その文字iより前に大きな数字
before_cnt = 0
# その文字より後に大きな数字
after_cnt = 0
n_list = list(map(int, input().split()))
for i in range(n - 1):
for j in range(i + 1, n):
if n_list[i] > n_list[j]:
before_cnt += 1
elif n_list[i] < n_list[j]:
# print("i",i,"j",j)
after_cnt += 1
"""
if i < j:
after_cnt+=1
else:
before_cnt+=1
"""
kurikaesi = int((1 + k) * k // 2)
# print("type",type(k),"kurikaesi",kurikaesi)
# print(after_cnt, before_cnt)
print(((after_cnt * (kurikaesi - k) + before_cnt * kurikaesi)) % (10**9 + 7))
| Statement
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies
of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of
integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j. | [{"input": "2 2\n 2 1", "output": "3\n \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n * B_0 > B_1\n * B_0 > B_3\n * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n 1 1 1", "output": "0\n \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n 10 9 8 7 5 6 3 4 2 1", "output": "185297239\n \n\nBe sure to print the output modulo 10^9 + 7."}] |
Print the maximum angle in which we can tilt the bottle without spilling any
water, in degrees. Your output will be judged as correct when the absolute or
relative error from the judge's output is at most 10^{-6}.
* * * | s288723869 | Wrong Answer | p02882 | Input is given from Standard Input in the following format:
a b x | import math
a, b, x = [int(x) for x in input().split(" ")]
low, high = 0, math.pi / 2
while high - low > 1e-7:
alpha = (low + high) / 2
if math.atan(b / a) < alpha:
vol = a * (a * b - a * a * math.tan(alpha) / 2)
else:
vol = a * (a * b * math.tan(math.pi / 2 - alpha) / 2)
if vol >= x:
low = alpha
else:
high = alpha
print(low / math.pi * 180)
| Statement
Takahashi has a water bottle with the shape of a rectangular prism whose base
is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The
thickness of the bottle can be ignored.)
We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the
bottle around one of the sides of the base.
When will the water be spilled? More formally, find the maximum angle in which
we can tilt the bottle without spilling any water. | [{"input": "2 2 4", "output": "45.0000000000\n \n\nThis bottle has a cubic shape, and it is half-full. The water gets spilled\nwhen we tilt the bottle more than 45 degrees.\n\n* * *"}, {"input": "12 21 10", "output": "89.7834636934\n \n\nThis bottle is almost empty. When the water gets spilled, the bottle is nearly\nhorizontal.\n\n* * *"}, {"input": "3 1 8", "output": "4.2363947991\n \n\nThis bottle is almost full. When the water gets spilled, the bottle is still\nnearly vertical."}] |
Print the maximum angle in which we can tilt the bottle without spilling any
water, in degrees. Your output will be judged as correct when the absolute or
relative error from the judge's output is at most 10^{-6}.
* * * | s864472243 | Wrong Answer | p02882 | Input is given from Standard Input in the following format:
a b x | def resolve():
import sys
input = sys.stdin.readline
# 整数 1 つ
# n = int(input())
# 整数複数個
a, b, x = map(int, input().split())
# 整数 N 個 (改行区切り)
# N = [int(input()) for i in range(N)]
# 整数 N 個 (スペース区切り)
# N = list(map(int, input().split()))
# 整数 (縦 H 横 W の行列)
# A = [list(map(int, input().split())) for i in range(H)]
import math
import bisect
# 台形の場合
if 2 * x / (a**2) >= b:
Down = [
(x / (a**2) + a * math.tan(math.pi * i / (2 * 9 * 10**5)) / 2)
for i in range(9 * 10**5)
]
ind = bisect.bisect_left(Down, b)
# 三角形の場合
else:
Down = [
math.sqrt(2 * x / a * math.tan(math.pi * i / (2 * 9 * 10**5)))
for i in range(9 * 10**5)
]
ind = bisect.bisect_left(Down, b)
print(float(ind / 1000))
resolve()
| Statement
Takahashi has a water bottle with the shape of a rectangular prism whose base
is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The
thickness of the bottle can be ignored.)
We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the
bottle around one of the sides of the base.
When will the water be spilled? More formally, find the maximum angle in which
we can tilt the bottle without spilling any water. | [{"input": "2 2 4", "output": "45.0000000000\n \n\nThis bottle has a cubic shape, and it is half-full. The water gets spilled\nwhen we tilt the bottle more than 45 degrees.\n\n* * *"}, {"input": "12 21 10", "output": "89.7834636934\n \n\nThis bottle is almost empty. When the water gets spilled, the bottle is nearly\nhorizontal.\n\n* * *"}, {"input": "3 1 8", "output": "4.2363947991\n \n\nThis bottle is almost full. When the water gets spilled, the bottle is still\nnearly vertical."}] |
Print the maximum angle in which we can tilt the bottle without spilling any
water, in degrees. Your output will be judged as correct when the absolute or
relative error from the judge's output is at most 10^{-6}.
* * * | s844139307 | Runtime Error | p02882 | Input is given from Standard Input in the following format:
a b x | n = int(input())
f = 1
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
f = i
print(f - 1 + n // f - 1)
| Statement
Takahashi has a water bottle with the shape of a rectangular prism whose base
is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The
thickness of the bottle can be ignored.)
We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the
bottle around one of the sides of the base.
When will the water be spilled? More formally, find the maximum angle in which
we can tilt the bottle without spilling any water. | [{"input": "2 2 4", "output": "45.0000000000\n \n\nThis bottle has a cubic shape, and it is half-full. The water gets spilled\nwhen we tilt the bottle more than 45 degrees.\n\n* * *"}, {"input": "12 21 10", "output": "89.7834636934\n \n\nThis bottle is almost empty. When the water gets spilled, the bottle is nearly\nhorizontal.\n\n* * *"}, {"input": "3 1 8", "output": "4.2363947991\n \n\nThis bottle is almost full. When the water gets spilled, the bottle is still\nnearly vertical."}] |
Print the maximum angle in which we can tilt the bottle without spilling any
water, in degrees. Your output will be judged as correct when the absolute or
relative error from the judge's output is at most 10^{-6}.
* * * | s704805854 | Wrong Answer | p02882 | Input is given from Standard Input in the following format:
a b x | n, k, c = map(int, input().split())
t = n * n * k
t1 = max((c / t) * 90, (90 - (c / t) * 90))
print("{0:10f}".format(t1))
| Statement
Takahashi has a water bottle with the shape of a rectangular prism whose base
is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The
thickness of the bottle can be ignored.)
We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the
bottle around one of the sides of the base.
When will the water be spilled? More formally, find the maximum angle in which
we can tilt the bottle without spilling any water. | [{"input": "2 2 4", "output": "45.0000000000\n \n\nThis bottle has a cubic shape, and it is half-full. The water gets spilled\nwhen we tilt the bottle more than 45 degrees.\n\n* * *"}, {"input": "12 21 10", "output": "89.7834636934\n \n\nThis bottle is almost empty. When the water gets spilled, the bottle is nearly\nhorizontal.\n\n* * *"}, {"input": "3 1 8", "output": "4.2363947991\n \n\nThis bottle is almost full. When the water gets spilled, the bottle is still\nnearly vertical."}] |
Print the answer.
* * * | s390410317 | Wrong Answer | p02752 | Input is given from Standard Input in the following format:
N
a_1 b_1
\vdots
a_{N-1} b_{N-1} | import sys
input = sys.stdin.readline
mod = 998244353
N = int(input())
E = [[] for i in range(N + 1)]
for i in range(N - 1):
x, y = map(int, input().split())
E[x].append(y)
E[y].append(x)
Q = [1]
D = [-1] * (N + 1)
D[1] = 0
while Q:
x = Q.pop()
for to in E[x]:
if D[to] == -1:
D[to] = D[x] + 1
Q.append(to)
f = D.index(max(D))
Q = [f]
D = [-1] * (N + 1)
D[f] = 0
while Q:
x = Q.pop()
for to in E[x]:
if D[to] == -1:
D[to] = D[x] + 1
Q.append(to)
MAX = max(D)
l = D.index(MAX)
Q = [l]
D2 = [-1] * (N + 1)
D2[l] = 0
while Q:
x = Q.pop()
for to in E[x]:
if D2[to] == -1:
D2[to] = D2[x] + 1
Q.append(to)
if MAX % 2 == 0:
for i in range(N + 1):
if D[i] == MAX // 2 and D2[i] == MAX // 2:
c = i
break
TOP_SORT = []
Q = [c]
D = [-1] * (N + 1)
P = [-1] * (N + 1)
D[c] = 0
while Q:
x = Q.pop()
TOP_SORT.append(x)
for to in E[x]:
if D[to] == -1:
D[to] = D[x] + 1
Q.append(to)
P[to] = x
DP = [[[0, 0, 0] for i in range(3)] for i in range(N + 1)]
# DP[x][p][m]で, plusのものが0個, 1個, 2個以上, minusのものが0個, 1個, 2個以上
for x in TOP_SORT[::-1]:
if D[x] == MAX // 2:
DP[x][1][1] = 1
elif len(E[x]) == 1:
DP[x][0][0] = 1
else:
for to in E[x]:
if to == P[x]:
continue
X = [[0, 0, 0] for i in range(3)]
for i in range(3):
for j in range(3):
X[0][0] += DP[to][i][j]
X[i][0] += DP[to][i][j]
X[0][j] += DP[to][i][j]
if DP[x] == [[0, 0, 0] for i in range(3)]:
DP[x] = X
else:
Y = [[0, 0, 0] for i in range(3)]
for i in range(3):
for j in range(3):
for k in range(3):
for l in range(3):
Y[min(2, i + k)][min(2, j + l)] = (
Y[min(2, i + k)][min(2, j + l)]
+ X[i][j] * DP[x][k][l]
) % mod
DP[x] = Y
# print(DP)
print(DP[c][1][1] * pow(2, mod - 2, mod) % mod)
else:
for i in range(N + 1):
if D[i] == MAX // 2 and D2[i] == MAX // 2 + 1:
c1 = i
elif D[i] == MAX // 2 + 1 and D2[i] == MAX // 2:
c2 = i
TOP_SORT = []
Q = [c1, c2]
D = [-1] * (N + 1)
P = [-1] * (N + 1)
D[c1] = 0
D[c2] = 0
while Q:
x = Q.pop()
TOP_SORT.append(x)
for to in E[x]:
if D[to] == -1:
D[to] = D[x] + 1
Q.append(to)
P[to] = x
DP = [[[0, 0, 0] for i in range(3)] for i in range(N + 1)]
# DP[x][p][m]で, plusのものが0個, 1個, 2個以上, minusのものが0個, 1個, 2個以上
for x in TOP_SORT[::-1]:
if D[x] == MAX // 2:
DP[x][1][1] = 1
elif len(E[x]) == 1:
DP[x][0][0] = 1
else:
for to in E[x]:
if to == P[x]:
continue
X = [[0, 0, 0] for i in range(3)]
for i in range(3):
for j in range(3):
X[0][0] += DP[to][i][j]
X[i][0] += DP[to][i][j]
X[0][j] += DP[to][i][j]
if DP[x] == [[0, 0, 0] for i in range(3)]:
DP[x] = X
else:
Y = [[0, 0, 0] for i in range(3)]
for i in range(3):
for j in range(3):
for k in range(3):
for l in range(3):
Y[min(2, i + k)][min(2, j + l)] = (
Y[min(2, i + k)][min(2, j + l)]
+ X[i][j] * DP[x][k][l]
) % mod
DP[x] = Y
# print(DP)
print(DP[c2][1][1] * pow(2, mod - 2, mod) % mod)
| Statement
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects
Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the number of graphs H that satisfy the following conditions, modulo
998244353.
* H does not contain self-loops or multiple edges.
* The diameters of G and H are equal.
* For every pair of vertices in H that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph. | [{"input": "6\n 1 6\n 2 1\n 5 2\n 3 4\n 2 3", "output": "3\n \n\nFor example, adding the edges (1, 5), (3, 5) in G satisfies the conditions.\n\n* * *"}, {"input": "3\n 1 2\n 2 3", "output": "1\n \n\nThe only graph H that satisfies the conditions is G.\n\n* * *"}, {"input": "9\n 1 2\n 2 3\n 4 2\n 1 7\n 6 1\n 2 5\n 5 9\n 6 8", "output": "27\n \n\n* * *"}, {"input": "19\n 2 4\n 15 8\n 1 16\n 1 3\n 12 19\n 1 18\n 7 11\n 11 15\n 12 9\n 1 6\n 7 14\n 18 2\n 13 12\n 13 5\n 16 13\n 7 1\n 11 10\n 7 17", "output": "78732"}] |
Print the answer.
* * * | s769821626 | Runtime Error | p02752 | Input is given from Standard Input in the following format:
N
a_1 b_1
\vdots
a_{N-1} b_{N-1} | BASE = 9973
MOD1 = 10**9 + 7
MOD2 = 998244353
class RollingHash:
# 文字列Sのローリングハッシュを構築
# 計算量: O(N)
def __init__(self, S, MOD):
self.MOD = MOD
# acc[i]はS[0:i]のハッシュ値となる
self.acc = [0]
a = 0
# 累積和を計算するイメージ
for i, c in enumerate(S):
h = ord(c) - ord("a") + 1
offset = pow(BASE, i, MOD)
a = (a + (h * offset)) % MOD
self.acc.append(a)
# S[i:j]のハッシュ値を返す
# 計算量: O(1)
def hash(self, i, j):
# 累積和を用いて部分区間の和を計算するイメージ
# 注意: 基数によるオフセットをキャンセルする必要がある
offset = pow(BASE, i, self.MOD)
# 素数MODを法とする剰余類における除算は逆元を乗算することで計算できる
# 素数MODを法とする剰余類におけるxの逆元はx^(MOD - 2)に等しい
offset_inv = pow(offset, self.MOD - 2, self.MOD)
return ((self.acc[j] - self.acc[i]) * offset_inv) % self.MOD
N = int(input())
S = input()
# Sのローリングハッシュを計算しておく
rolling1 = RollingHash(S, MOD1)
rolling2 = RollingHash(S, MOD2)
# 長さmのダジャレがSに含まれるならば、長さm-1のダジャレも含まれる
# つまり、長さmのダジャレがSに含まれるならば真となる述語をP(m)とすると、以下を満たす整数cが存在する:
# - 0以上c以下の整数mについてP(m)は真
# - cより大きい整数mについてP(m)は偽
# ※ Pは単調関数ということ
# このcを二分探索で発見すれば高速化できる!
# P(ok)は真
ok = 0
# P(ng)は偽
ng = N
while ng - ok > 1:
# 区間[ok, ng)の中央値をmとする
m = (ok + ng) // 2
# 長さmのダジャレが存在するか判定する
# 長さmのformerのハッシュ値のキャッシュ
former_cache1 = set()
former_cache2 = set()
p = False
# latterに着目してループを回す
for i in range(m, N):
# ダジャレ長を決め打ちしているのでjを直接計算できる
j = i + m
# S[i:j]がSをはみ出したらループ終了
if j > N:
break
# formerのハッシュ値をキャッシュする
former_cache1.add(rolling1.hash(i - m, i))
former_cache2.add(rolling2.hash(i - m, i))
# キャッシャに同一のハッシュ値が存在する場合(ハッシュ値が衝突した場合)、ダジャレになっていると判定できる
# ハッシュ値の計算、キャッシュ存在判定は共にO(1)で処理できる!
if (
rolling1.hash(i, j) in former_cache1
and rolling2.hash(i, j) in former_cache2
):
p = True
# 区間[ok, ng) を更新
if p:
ok = m
else:
ng = m
# whileループを抜けると区間[ok, ng)は[c, c + 1) になっている
ans = ok
print(ans)
| Statement
We have a tree G with N vertices numbered 1 to N. The i-th edge of G connects
Vertex a_i and Vertex b_i.
Consider adding zero or more edges in G, and let H be the graph resulted.
Find the number of graphs H that satisfy the following conditions, modulo
998244353.
* H does not contain self-loops or multiple edges.
* The diameters of G and H are equal.
* For every pair of vertices in H that is not directly connected by an edge, the addition of an edge directly connecting them would reduce the diameter of the graph. | [{"input": "6\n 1 6\n 2 1\n 5 2\n 3 4\n 2 3", "output": "3\n \n\nFor example, adding the edges (1, 5), (3, 5) in G satisfies the conditions.\n\n* * *"}, {"input": "3\n 1 2\n 2 3", "output": "1\n \n\nThe only graph H that satisfies the conditions is G.\n\n* * *"}, {"input": "9\n 1 2\n 2 3\n 4 2\n 1 7\n 6 1\n 2 5\n 5 9\n 6 8", "output": "27\n \n\n* * *"}, {"input": "19\n 2 4\n 15 8\n 1 16\n 1 3\n 12 19\n 1 18\n 7 11\n 11 15\n 12 9\n 1 6\n 7 14\n 18 2\n 13 12\n 13 5\n 16 13\n 7 1\n 11 10\n 7 17", "output": "78732"}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s625612067 | Wrong Answer | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | I, O, T, J, L, S, Z = list(map(int, input().split()))
print((I >> 1) * 2 + O + (J >> 1) * 2 + (L >> 1) * 2)
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s006841300 | Runtime Error | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | I,O,T,J,L,S,Z = map(int,input().split())
if (I<2 and O=0 and J<2 and L<2) and (I != 1 or J != 1 or L!= 1):
print(max(((I-1)//2+(J-1)//2+(L-1)//2)*2+O+3,(I//2+J//2+L//2)*2+O))
else:
print(0)
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s598697811 | Runtime Error | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | I,O,T,J,L,S,Z = map(int,input().split())
if I==1 and J==1 and L==1:
print(3)
elif ((I-1)//2+(J-1)//2+(L-1)//2)*2+O==0 and (I//2+J//2+L//2)*2+O)==0):
print(0)
else:
print(max(((I-1)//2+(J-1)//2+(L-1)//2)*2+O+3,(I//2+J//2+L//2)*2+O))
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s657947779 | Accepted | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right
sys.setrecursionlimit(10**7)
def input():
return sys.stdin.readline()[:-1]
mod = 10**9 + 7
def I():
return int(input())
def LI():
return list(map(int, input().split()))
def LIR(row, col):
if row <= 0:
return [[] for _ in range(col)]
elif col == 1:
return [I() for _ in range(row)]
else:
read_all = [LI() for _ in range(row)]
return map(list, zip(*read_all))
#################
# T,S,Zは使えない
# I,J,Lを1つずつ使うと偶奇の調整ができる
A = LI()
d = defaultdict()
name = ["I", "O", "T", "J", "L", "S", "Z"]
for i, a in enumerate(A):
d[name[i]] = a
ans = d["O"]
use = ["I", "J", "L"]
odd = []
even = []
for k in use:
if d[k] % 2:
odd.append(k)
else:
even.append(k)
if len(odd) == 3:
ans += 3
for k in use:
ans += ((d[k] - 1) // 2) * 2
elif len(odd) == 2:
if d[even[0]] > 0:
ans += 3
for k in use:
ans += ((d[k] - 1) // 2) * 2
else:
for k in use:
ans += (d[k] // 2) * 2
elif len(odd) == 1:
for k in use:
ans += (d[k] // 2) * 2
else:
for k in use:
ans += (d[k] // 2) * 2
print(ans)
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s691443228 | Runtime Error | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | I,O,T,J,L,S,Z = map(int,input().split())
print(max(((I-1)//2+(J-1)//2+(L-1)//2)*2+O+3*(I>0*❨L>0❩*❨J>0❩,(I//2+J//2+L//2)*2+O))
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s609811950 | Runtime Error | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | a=list(map(int,input().split()))
ans=min(a[0],a[3],a[4])
a[0]-=ans
a[3]-=ans
a[4]-=ans
ans*=3
if(ans>0&&(a[0]%2+a[3]%2+a[4]%2==2)):
ans+=1
ans+=(a[0]//2*2)+(a[3]//2*2)+(a[4]//2*2)+a[1]
print(ans)
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s322101074 | Wrong Answer | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | a, b = input().split()[:2]
print(int(a) // 2 * 2 + int(b))
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s617511759 | Runtime Error | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | I,O,R,J,L,S,Z=map(int,input().split())
ans=O
m=min(I,J,L):
I-=m
J-=m
L-=m
ans+=m*3
ans+=I//2*2
ans+=J//2*2
ans+=L//2*2
print(ans) | Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s147573672 | Runtime Error | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | A = list(map(int, input().split()))
S = A[1]
S += (A[0] // 2) * 2
T = S
if A[4] > 0 and A[5] > 0 and A[0] % 2 == 1:
S += (A[4] // 2) * 2 + (A[5] // 2) * 2
A[4] -= 1
A[5] -= 1
T += 3
T += (A[4] // 2) * 2 + (A[5] // 2) * 2
print(max(S, T))
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s588060894 | Accepted | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | a_i, a_o, a_t, a_j, a_l, a_s, a_z = map(int, input().split())
tri_use = min(a_j, a_l, a_i)
p1 = tri_use * 3
j_ex = a_j - tri_use
l_ex = a_l - tri_use
i_ex = a_i - tri_use
p2 = j_ex // 2 * 2 + l_ex // 2 * 2 + i_ex // 2 * 2
extra = j_ex % 2 + l_ex % 2 + i_ex % 2
p3 = 0
if tri_use >= 1:
if extra == 2:
p3 = 1
elif extra == 3:
p3 = 3
print(p1 + p2 + p3 + a_o)
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s585376826 | Wrong Answer | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | i, o, t, j, l, s, z = map(int, input().split())
ans = 0
ans += o
if j % 2 == 1 and l % 2 == 1 and i % 2 == 1:
ans += j + i + l
if j % 2 == 1 and l % 2 == 1 and i % 2 == 0:
ans += j + i + l - 1
if j % 2 == 1 and l % 2 == 0 and i % 2 == 1:
ans += j + i + l - 1
if j % 2 == 1 and l % 2 == 0 and i % 2 == 0:
ans += j + i + l - 1
if j % 2 == 0 and l % 2 == 1 and i % 2 == 1:
ans += j + i + l - 1
if j % 2 == 0 and l % 2 == 1 and i % 2 == 0:
ans += j + i + l - 1
if j % 2 == 0 and l % 2 == 0 and i % 2 == 1:
ans += j + i + l - 1
if j % 2 == 0 and l % 2 == 0 and i % 2 == 0:
ans += j + i + l
print(ans)
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s430339701 | Wrong Answer | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | ## coding: UTF-8
# 最後の方のテストケースでREになってしまう。時間切れ。
# from decimal import *
# from itertools import permutations, combinations,combinations_with_replacement,product
# N = int(input())
s = input().split()
p = [int(w) for w in s]
# print(p)
I = p[0]
O = p[1]
# T = p[2] #使わない
J = p[3]
L = p[4]
# S = p[5] #使わない
# Z = p[6] #使わない
answer = 0
answer += O # O型は最初に全部使います。
if I % 2 == J % 2 and I % 2 == L % 2:
# [odd,odd,odd] or [even,even,even]
# [0,0,0],[0,0,even]
answer += I + J + L
elif (I + J + L) % 2 == 1:
# [even,even,odd]
# [0,0,odd]
answer += I + J + L - 1
else:
# [even,odd,odd]
# if(min(I,J,L) % 2 == 0):
# answer += I+J+L - 2
# else:
# answer += I+J+L - 1
answer += I + J + L - 1
print(answer)
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
Print the maximum possible value of K. If no rectangle can be formed, print
`0`.
* * * | s699451640 | Wrong Answer | p03840 | The input is given from Standard Input in the following format:
a_I a_O a_T a_J a_L a_S a_Z | # coding:utf-8
import sys
INF = float("inf")
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 LS():
return sys.stdin.readline().split()
def II():
return int(sys.stdin.readline())
def SI():
return input()
def main():
ai, ao, at, aj, al, a_s, az = LI()
aijl = min(ai, aj, al)
ai -= aijl
aj -= aijl
al -= aijl
ai //= 2
aj //= 2
al //= 2
return 2 * (ai + aj + al) + ao + aijl * 3
print(main())
| Statement
A _tetromino_ is a figure formed by joining four squares edge to edge. We will
refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and
Z-tetrominos, respectively:

Snuke has many tetrominos. The number of I-, O-, T-, J-, L-, S- and
Z-tetrominos in his possession are a_I, a_O, a_T, a_J, a_L, a_S and a_Z,
respectively. Snuke will join K of his tetrominos to form a rectangle that is
two squares tall and 2K squares wide. Here, the following rules must be
followed:
* When placing each tetromino, rotation is allowed, but reflection is not.
* Each square in the rectangle must be covered by exactly one tetromino.
* No part of each tetromino may be outside the rectangle.
Snuke wants to form as large a rectangle as possible. Find the maximum
possible value of K. | [{"input": "2 1 1 0 0 0 0", "output": "3\n \n\nOne possible way to form the largest rectangle is shown in the following\nfigure:\n\n\n\n* * *"}, {"input": "0 0 10 0 0 0 0", "output": "0\n \n\nNo rectangle can be formed."}] |
For each query, print the area of the cut polygon. The output values should be
in a decimal fraction with an error less than 0.00001. | s907422917 | Runtime Error | p02302 | The input is given in the following format:
g (the sequence of the points of the polygon)
q (the number of queries = the number of target lines)
1st query
2nd query
:
qth query
g is given as a sequence of points p1,..., pn in the following format:
n
x1 y1
x2 y2
:
xn yn
The first integer n is the number of points. The coordinate of the i-th point
pi is given by two integers xi and yi. The coordinates of points are given in
the order of counter-clockwise visit of them. Note that all interior angles of
given convex polygons are less than or equal to 180.
For each query, a line represented by two points p1 and p2 is given. The
coordinates of the points are given by four integers p1x, p1y, p2x and p2y. | def cross(a, b):
return a.real * b.imag - a.imag * b.real
def cross_point(c, d):
l = d - c
v1 = cross(lv, l)
v2 = cross(lv, lt - c)
return c + v2 / v1 * l
n = int(input())
points = [complex(*map(int, input().split())) for _ in range(n)]
point0 = points.pop(0)
points.append(point0)
q = int(input())
while q:
x1, y1, x2, y2 = map(int, input().split())
ls, lt = (x1 + 1j * y1, x2 + 1j * y2)
lv = lt - ls
area = 0
prev = point0
prev_flag = cross(lv, prev - ls) >= 0
cp1, cp2 = None, None
for p in points:
curr_flag = cross(lv, p - ls) >= 0
if prev_flag and curr_flag:
area += cross(prev, p)
elif prev_flag != curr_flag:
cp = cross_point(prev, p)
if prev_flag:
area += cross(prev, cp)
cp1 = cp
else:
area += cross(cp, p)
cp2 = cp
prev, prev_flag = p, curr_flag
area += cross(cp1, cp2)
print(area / 2)
q -= 1
| Convex Cut

As shown in the figure above, cut a convex polygon g by a line p1p2 and print
the area of the cut polygon which is on the left-hand side of the line.
g is represented by a sequence of points p1, p2,..., pn where line segments
connecting pi and pi+1 (1 ≤ i ≤ n−1) are sides of the convex polygon. The line
segment connecting pn and p1 is also a side of the polygon. | [{"input": "1 1\n 4 1\n 4 3\n 1 3\n 2\n 2 0 2 4\n 2 4 2 0", "output": ".00000000\n 4.00000000"}] |
Find the minimum number of edges that need to be removed.
* * * | s946106799 | Runtime Error | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | n, m = map(int, input().split())
nums = list(map(int, input().split()))
l = []
w = []
suv = [0] * n
d = 0
_sum = sum(nums)
for i in range(m):
a, b, y = map(int, input().split())
suv[a - 1] += 1
suv[b - 1] += 1
l.append((a, b))
w.append(y)
while True:
w_ = w[:]
l_ = l[:]
w = []
for i, y_ in enumerate(w_):
if y_ > _sum:
d += 1
del_a, del_b = l[i]
suv[del_a - 1] -= 1
suv[del_b - 1] -= 1
else:
w.append(y_)
l.append(l_[i])
if 0 in suv:
for i, s in enumerate(suv):
if s == 0:
_sum -= nums[i]
nums.pop(i)
suv.pop(i)
else:
break
print(d)
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s964226727 | Wrong Answer | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | N, m = map(int, input().split())
x = [0] + list(map(int, input().split()))
t = sorted([tuple(map(int, input().split())) for _ in range(m)], key=lambda x: -x[2])
# 各ノードの根(-1はそのノードが根)
follow = [-1] * (N + 1)
# (自分を含む)連結している数
num_follower = [1] * (N + 1)
def root_index_of(A):
r = A
while follow[r] > -1:
r = follow[r]
return r
def connected(A, B):
return root_index_of(A) == root_index_of(B)
def connect(A, B):
rA = root_index_of(A)
rB = root_index_of(B)
s_rA = x[rA]
s_rB = x[rB]
if rA == rB:
return
if num_follower[rA] < num_follower[rB]:
follow[rA] = rB
follow[A] = rB
num_follower[rB] += num_follower[rA]
x[rB] += s_rA
else:
follow[rB] = rA
follow[B] = rA
num_follower[rA] += num_follower[rB]
x[rA] += s_rB
count = dict()
for i in range(1, m + 1):
a, b, y = t.pop()
if not connected(a, b):
connect(a, b)
if x[root_index_of(a)] >= y:
count[root_index_of(a)] = i
if count == dict():
print(m)
else:
small_idx = min(count.values())
print(m - small_idx)
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s288594362 | Runtime Error | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | giveup
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s885397959 | Wrong Answer | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | import sys
import collections
N, M = map(int, sys.stdin.readline().strip().split())
pw = list(map(int, sys.stdin.readline().strip().split()))
es = {}
eps = {}
pes = {}
for i in range(N):
pes[i] = set()
for i in range(M):
p0, p1, w = map(int, sys.stdin.readline().strip().split())
p0 = p0 - 1 # 0開始にする
p1 = p1 - 1
# 点から直接つながっている辺の情報の追加
pes[p0].add(i)
pes[p1].add(i)
es[i] = [p0, p1, w]
# 辺から直接つながっている点の情報の追加
eps[i] = set([p0, p1])
# print("辺情報、始点終点ウェイト {}".format(es))
# print("辺情報、直接つながる点 {}".format(eps))
# print("点情報、直接つながる辺 {}".format(pes))
def countW(e):
# print(e)
p0 = es[e][0]
p1 = es[e][1]
# たどった辺の情報
e1 = set([e])
while True:
# 辺をとる
e2 = (pes[p0] | pes[p1]) - e1 # set演算
# 新しい辺がない場合
if len(e2) == 0:
break
e1 = e2 | e1
# print(e1)
pall = set()
for ei in e1:
# eの分も入る
# print(eps[ei])
pall = pall | eps[ei]
# print(pall)
# ウェイトの計算
w = 0
for pi in pall:
w += pw[pi]
return w
# print(countW(0))
survived = set(range(M))
# print(survived)
while True:
flag = False
snew = survived.copy()
# print(snew)
for i in survived:
# 辺の重みのほうが大きかったらTrue
if countW(i) < es[i][2]:
flag = True
snew.discard(i)
"""
そういう辺は全部消す。消したところで、点の重みの和が減っていくので、
だめだった他の辺が大丈夫になるようなことはない。
"""
pes[es[i][0]].discard(i)
pes[es[i][1]].discard(i)
# print(snew)
survived = snew
# すべて大丈夫だったら
if flag == False:
break
if len(survived) <= 0:
break
ans = M - len(survived)
print(ans)
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s645869153 | Wrong Answer | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | from collections import defaultdict
class UnionFind:
def __init__(self, n=0):
self.d = [-1] * n
def find(self, x):
if self.d[x] < 0:
return x
self.d[x] = self.find(self.d[x])
return self.d[x]
def unite(self, x, y):
x, y = self.find(x), self.find(y)
if x == y:
return False
if self.d[x] > self.d[y]:
x, y = y, x
self.d[x] += self.d[y]
self.d[y] = x
return True
def same(self, x, y):
return self.find(x) == self.find(y)
def size(self, x):
return -self.d[self.find(x)]
from collections import deque
def bfs(s, seen):
p = X[s]
MAX, argmax = 0, -1
todo = deque()
seen[s] = 1
todo.append(s)
while len(todo):
a = todo.popleft()
for b in G[a].keys():
if seen[b] == 0:
seen[b] = 1
todo.append(b)
if MAX < G[a][b]:
MAX = G[a][b]
argmax = tuple(sorted((a, b)))
p += X[b]
return p, MAX, argmax, seen
N, M = map(int, input().split())
(*X,) = map(int, input().split())
G = [{} for _ in range(N)]
uf = UnionFind(N)
sumX = sum(X)
ans = 0
for i in range(M):
a, b, c = map(int, input().split())
if c > sumX:
ans += 1
continue
G[a - 1][b - 1] = G[b - 1][a - 1] = c
uf.unite(a - 1, b - 1)
def solve(ite):
global uf, ans
update = 0
if ite > 0:
uf = UnionFind(N)
for i in range(N):
for j in G[i].keys():
uf.unite(i, j)
glist = defaultdict(set)
plist = defaultdict(int)
elist = defaultdict(dict)
for i in range(N):
if uf.d[i] != -1:
g = uf.find(i)
glist[g].add(i)
plist[g] += X[i]
tmp = {tuple(sorted((i, v))): G[i][v] for v in G[i].keys()}
elist[g].update(tmp)
for g in glist.keys():
argmax, MAX = sorted(elist[g].items(), key=lambda x: x[1], reverse=True)[0]
if MAX > plist[g]:
v1, v2 = argmax
del G[v1][v2], G[v2][v1]
ans += 1
update = 1
else:
seen = [0] * N
for i in range(N):
if not seen[i] and len(G[i].keys()):
p, MAX, argmax, seen = bfs(i, seen)
if MAX > p:
i, j = argmax
del G[i][j], G[j][i]
ans += 1
update = 1
return update
i = 0
while 1:
update = solve(i)
i += 1
if update == 0:
break
print(ans)
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s598955831 | Wrong Answer | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | N, M = map(int, input().split())
(*X,) = map(int, input().split())
ABY = [list(map(int, input().split())) for _ in [0] * M]
ABY = [(a - 1, b - 1, y) for a, b, y in ABY]
ABY.sort(key=lambda x: x[2])
import sys
sys.setrecursionlimit(10**7)
class UnionFind:
def __init__(self, N, X):
self.Parent = list(range(N))
self.Weight = X[:]
def get_Parent(self, n):
if self.Parent[n] == n:
return n
p = self.get_Parent(self.Parent[n])
self.Parent[n] = p
return p
def get_Weight(self, n):
n = self.get_Parent(n)
return self.Weight[n]
def merge(self, x, y):
x = self.get_Parent(x)
y = self.get_Parent(y)
if x != y:
self.Parent[y] = x
self.Weight[x] += self.Weight[y]
return
def is_united(self, x, y):
return self.get_Parent(x) == self.get_Parent(y)
# 最小全域木を作る
U0 = UnionFind(N, [0] * N)
E = [0] * M
Et = [[] for _ in [0] * N]
for i, aby in enumerate(ABY):
a, b, y = aby
if U0.is_united(a, b):
E[i] = -1 # -1 : 最小全域木に使わない
continue
U0.merge(a, b)
Et[a].append((b, y, i))
Et[b].append((a, y, i))
import heapq
hpush = heapq.heappush
hpop = heapq.heappop
U_final = UnionFind(N, X)
for i, aby in enumerate(ABY):
if E[i] != 0:
continue
a, b, y = aby
if U_final.get_Weight(a) + U_final.get_Weight(b) >= y:
U_final.merge(a, b)
E[i] = 3 # 3 : 本決め使用
continue
hq = [(y, i)]
U_tmp = UnionFind(N, X)
while hq:
y1, i1 = hpop(hq)
a, b, _ = ABY[i1]
E[i1] = 1 # 1 : 仮決めの仮定
U_tmp.merge(a, b)
q = [a, b]
while q:
j = q.pop()
for k, y2, ek in Et[j]:
if E[ek] == 4:
continue
if U_tmp.is_united(j, k):
continue
if E[ek] == 3:
U_tmp.merge(j, k)
q.append(k)
continue
if y2 > y1:
hpush(hq, (y2, ek))
continue
E[ek] = 2 # 2 : 仮決め従属で使用
U_tmp.merge(j, k)
if U_tmp.get_Weight(a) >= y1:
break
else:
for j in range(M):
if E[j] == 1:
E[j] = 4
elif E[j] == 2:
E[j] = 0
continue
for j in range(M):
if E[j] == 1 or E[j] == 2:
a, b, _ = ABY[j]
E[j] = 3
U_final.merge(a, b)
for j in range(M):
if E[j] != -1:
continue
a, b, y = ABY[j]
if not U_final.is_united(a, b):
E[j] = 4
elif U_final.get_Weight(a) >= y:
E[j] = 3
else:
E[j] = 4
print(E.count(4))
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s025104501 | Wrong Answer | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | import sys
from collections import defaultdict as dd
input = sys.stdin.readline
N, M = map(int, input().split())
a = [0] + list(map(int, input().split()))
edg = []
for i in range(1, M + 1):
u, v, c = map(int, input().split())
edg.append((u, v, c, i))
def check(x):
e = dd(list)
for u, v, c, i in edg:
if c > x:
continue
e[u].append((v, c, i))
e[v].append((u, c, i))
vis = [0] * (N + 1)
evis = [0] * (M + 1)
for i in range(1, N + 1):
if vis[i]:
continue
s = [i]
vs = 0
es = 0
while len(s):
p = s.pop()
if vis[p]:
continue
vis[p] = 1
vs += a[p]
for q, c, k in e[p]:
if evis[k]:
continue
es = max(es, c)
evis[k] = 1
s.append(q)
if vs < es:
return False
return True
ok = 0
ng = sum(a) + 1
while ng - ok > 1:
m = (ok + ng) // 2
if check(m):
ok = m
else:
ng = m
res = 0
for _, _, c, _ in edg:
res += c > ok
print(res)
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s505671582 | Wrong Answer | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | def main():
import sys
input = sys.stdin.buffer.readline
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def find_root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.find_root(self.root[x])
return self.root[x]
def unite(self, x, y):
x = self.find_root(x)
y = self.find_root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.find_root(x) == self.find_root(y)
def size(self, x):
return -self.root[self.find_root(x)]
N, M = map(int, input().split())
X = [0] + list(map(int, input().split()))
edge = [None] * M
for i in range(M):
edge[i] = tuple(map(int, input().split()))
edge.sort(key=lambda e: e[2])
UF = UnionFind(N + 1)
edge_num = [0] * (N + 1)
ok_num = [0] * (N + 1)
for a, b, y in edge:
if UF.isSameGroup(a, b):
root_a = UF.find_root(a)
edge_num[root_a] += 1
if X[root_a] >= y:
ok_num[root_a] += 1
else:
root_a = UF.find_root(a)
root_b = UF.find_root(b)
UF.unite(a, b)
root_new = UF.find_root(a)
root_old = root_a + root_b - root_new
X[root_new] += X[root_old]
X[root_old] = 0
edge_num[root_new] += edge_num[root_old] + 1
edge_num[root_old] = 0
if X[root_new] >= y:
ok_num[root_new] = edge_num[root_new]
ok_num[root_old] = 0
print(M - sum(ok_num))
if __name__ == "__main__":
main()
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s206054203 | Wrong Answer | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | import sys
from collections import Counter
input = sys.stdin.readline
N, M = map(int, input().split())
a = list(map(int, input().split()))
e = []
ee = [[] for _ in range(N + 1)]
for _ in range(M):
u, v, c = map(int, input().split())
e.append((c, u, v))
ee[u].append((v, c))
ee[v].append((u, c))
e.sort()
table = [0] + a[:]
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
uf = UnionFind(N)
edges = []
ng = set()
etable = [0] * (N + 1)
for i in range(M):
c, u, v = e[i]
if uf.isSameGroup(u, v):
rt = uf.Find_Root(u)
etable[rt] = max(etable[rt], c)
ng.discard(rt)
if table[rt] < etable[rt]:
ng.add(rt)
elif len(ng) == 0:
edges.append(i)
else:
ur = uf.Find_Root(u)
vr = uf.Find_Root(v)
uf.Unite(u, v)
rt = uf.Find_Root(u)
cmx = max(etable[ur], etable[vr], c)
etable[rt] = cmx
if table[ur] + table[vr] < cmx:
ng.add(rt)
else:
ng.discard(ur)
ng.discard(vr)
edges.append(i)
table[rt] = table[ur] + table[vr]
edges.reverse()
vis = [0] * (N + 1)
evis = Counter()
res = M
# print(edges)
for i in edges:
mx, s, _ = e[i]
if vis[s]:
continue
sta = [s]
vis[s] = 1
while len(sta):
x = sta.pop()
for y, c in ee[x]:
if c > mx:
continue
if evis[(min(x, y), max(x, y))]:
continue
evis[(min(x, y), max(x, y))] = 1
res -= 1
if vis[y]:
continue
sta.append(y)
vis[y] = 1
# print(vis, res, e[i])
print(res)
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Find the minimum number of edges that need to be removed.
* * * | s336840479 | Accepted | p03143 | Input is given from Standard Input in the following format:
N M
X_1 X_2 ... X_N
A_1 B_1 Y_1
A_2 B_2 Y_2
:
A_M B_M Y_M | import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
class UnionFind:
def __init__(self, n):
self.state = [-1] * n
self.weight = [0] * n
self.state0 = []
self.weight0 = []
def save(self):
self.state0 = self.state[:]
self.weight0 = self.weight[:]
def restore(self):
self.state = self.state0[:]
self.weight = self.weight0[:]
def root(self, u):
v = self.state[u]
if v < 0:
return u
self.state[u] = res = self.root(v)
return res
def merge(self, u, v):
ru = self.root(u)
rv = self.root(v)
if ru == rv:
return
du = self.state[ru]
dv = self.state[rv]
if du > dv:
ru, rv = rv, ru
if du == dv:
self.state[ru] -= 1
self.state[rv] = ru
self.weight[ru] += self.weight[rv]
return
def get_weight(self, u):
r = self.root(u)
return self.weight[r]
def main():
def dfs(u, w, ou=-1):
for y, ku, i in to[u]:
if ku == ou:
continue
if y > w:
continue
if use_edge[i]:
continue
use_edge[i] = True
dfs(ku, w, u)
to = defaultdict(list)
n, m = map(int, input().split())
xx = list(map(int, input().split()))
uf = UnionFind(n)
for i, x in enumerate(xx):
uf.weight[i] = x
edges = []
for i in range(m):
a, b, y = map(int, input().split())
a, b = a - 1, b - 1
edges.append([y, a, b, i])
to[a].append([y, b, i])
to[b].append([y, a, i])
edges.sort()
max_edge_candidate = []
use_edge = [False] * m
for y, a, b, i in edges:
uf.merge(a, b)
if y <= uf.get_weight(a):
max_edge_candidate.append([y, a, b, i])
while max_edge_candidate:
y, a, b, i = max_edge_candidate.pop()
if use_edge[i]:
continue
dfs(a, y)
print(m - sum(use_edge))
main()
| Statement
There is a connected undirected graph with N vertices and M edges. The
vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of
these vertices and edges has a specified weight. Vertex i has a weight of X_i;
Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero or more edges so that the following condition is
satisfied:
* For each edge that is not removed, the sum of the weights of the vertices in the connected component containing that edge, is greater than or equal to the weight of that edge.
Find the minimum number of edges that need to be removed. | [{"input": "4 4\n 2 3 5 7\n 1 2 7\n 1 3 9\n 2 3 12\n 3 4 18", "output": "2\n \n\nAssume that we removed Edge 3 and 4. In this case, the connected component\ncontaining Edge 1 contains Vertex 1, 2 and 3, and the sum of the weights of\nthese vertices is 2+3+5=10. The weight of Edge 1 is 7, so the condition is\nsatisfied for Edge 1. Similarly, it can be seen that the condition is also\nsatisfied for Edge 2. Thus, a graph satisfying the condition can be obtained\nby removing two edges.\n\nThe condition cannot be satisfied by removing one or less edges, so the answer\nis 2.\n\n* * *"}, {"input": "6 10\n 4 4 1 1 1 7\n 3 5 19\n 2 5 20\n 4 5 8\n 1 6 16\n 2 3 9\n 3 6 16\n 3 4 1\n 2 6 20\n 2 4 19\n 1 2 9", "output": "4\n \n\n* * *"}, {"input": "10 9\n 81 16 73 7 2 61 86 38 90 28\n 6 8 725\n 3 10 12\n 1 4 558\n 4 9 615\n 5 6 942\n 8 9 918\n 2 7 720\n 4 7 292\n 7 10 414", "output": "8"}] |
Print the minimum total cost required to collect all the balls.
* * * | s097825146 | Runtime Error | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | n = int(input())
zahyou = [list(map(int, input().split())) for _ in range(n)]
# pq=[[0]*n for _ in range(n)]
# 初期値が0の辞書
from collections import defaultdict
pq_x = defaultdict(lambda: set([]))
pq_y = defaultdict(lambda: set([]))
for i, from_xy in enumerate(zahyou):
for j, to_xy in enumerate(zahyou[i + 1 :]):
# print(i,j+i+1)
pq_x[(from_xy[0] - to_xy[0], from_xy[1] - to_xy[1])].add((i))
pq_y[(from_xy[0] - to_xy[0], from_xy[1] - to_xy[1])].add((j + i + 1))
print(pq_x)
print(pq_y)
result = 10**9
for item in pq_x.keys():
len_x = len(list(pq_x[item]))
len_y = len(list(pq_y[item]))
min_xy = min(len_x, len_y) + 1
temp = max(n - 1 - min_xy)
result = min(result, temp)
print(result)
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s213599759 | Accepted | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
u = []
for i in range(n):
ll = []
for j in range(n):
if j != i:
ll.append([l[i][0] - l[j][0], l[i][1] - l[j][1]])
u += ll
su = 0
for i in u:
a = u.count(i)
su = max(su, a)
print(n - su)
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s608863854 | Wrong Answer | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | n = int(input())
li = [list(map(int, input().split())) for i in range(n)]
ans_li = []
rest = len(li)
for i in range(len(li)):
for j in range(rest):
x = li[i][0] - li[-j][0]
y = li[i][1] - li[-j][1]
ans_li.append([x, y])
rest -= 1
max_a = 0
for i in ans_li:
a = ans_li.count(i)
if a > max_a:
max_a = a
print(n - max_a)
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s987129230 | Wrong Answer | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | N = int(input())
ball = [tuple(map(int, input().split())) for i in range(N)]
ans = N
for i in range(N - 1):
for j in range(i + 1, N):
cost = 1
p = ball[j][0] - ball[i][0]
q = ball[j][1] - ball[i][1]
used = {i, j}
for l in range(N):
if l not in used:
x = ball[l][0] - ball[i][0]
y = ball[l][1] - ball[i][1]
a, b, c = False, False, False
if p == 0:
if x == 0:
a = True
c = True
if y % q == 0:
b = True
elif q == 0:
if y == 0:
b = True
c = True
if x % p == 0:
a = True
elif p != 0 and q != 0:
if x % p == 0 and y % q == 0 and x // p == y // q:
a, b, c = True, True, True
if a and b and c:
used |= {l}
for k in range(N):
if k in used:
continue
else:
cost += 1
used |= {k}
for l in range(N):
if l not in used:
x = ball[l][0] - ball[k][0]
y = ball[l][1] - ball[k][1]
a, b, c = False, False, False
if p == 0:
if x == 0:
a = True
c = True
if y % q == 0:
b = True
elif q == 0:
if y == 0:
b = True
c = True
if x % p == 0:
a = True
elif p != 0 and q != 0:
if x % p == 0 and y % q == 0 and x // p == y // q:
a, b, c = True, True, True
if a and b and c:
used |= {l}
ans = min(ans, cost)
print(ans)
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s166921419 | Wrong Answer | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | import sys
sys.setrecursionlimit(4100000)
def inputs(num_of_input):
ins = [input() for i in range(num_of_input)]
return ins
def solve(inputs):
points = []
for i in inputs:
points.append(string_to_int(i))
N = len(points)
if N == 1 or N == 2:
return 1
min = None
for i, _ in enumerate(points):
for j in range(i + 1, N):
try_p = points[i][0] - points[j][0]
try_q = points[i][1] - points[j][1]
a = try_q / try_p if try_p != 0 else 0
bs = {}
hits = {x: None for x in range(0, N)}
for try_i, _ in enumerate(points):
for try_j in range(try_i + 1, N):
diff_x = points[try_j][0] - points[try_i][0]
diff_y = points[try_j][1] - points[try_i][1]
check_a = diff_y / diff_x if diff_x != 0 else 0
if abs(a) != abs(check_a):
continue
check_b = (
(points[try_j][1] + points[try_i][1])
- check_a * (points[try_j][0] + points[try_i][0])
) / 2
if check_b not in bs:
bs[check_b] = True
hits[try_i] = True
hits[try_j] = True
count = len(bs)
for value in hits.values():
if value is None:
count += 1
if min is None or min > count:
min = count
return min
def string_to_int(string):
return list(map(lambda x: int(x), string.split()))
if __name__ == "__main__":
[N] = string_to_int(input())
ret = solve(inputs(N))
print(ret)
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s971216547 | Accepted | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | # !/usr/bin/env python3
# encoding: UTF-8
# Modified: <15/Jun/2019 05:47:43 PM>
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology (IIIT), Gwalior
import sys
import os
from io import IOBase, BytesIO
def main():
n = int(input())
arr = [0] * n
for i in range(n):
arr[i] = tuple(get_ints())
if n == 1 or n == 2:
print(1)
return
arr.sort()
d = {}
for i in range(n):
for j in range(i + 1, n):
if (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1]) not in d:
d[(arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])] = 0
d[(arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])] += 1
from operator import itemgetter
sorted_d = sorted(d.items(), key=itemgetter(1), reverse=True)
# print(sorted_d)
print(n - sorted_d[0][1])
BUFSIZE = 8192
class FastIO(BytesIO):
newlines = 0
def __init__(self, file):
self._file = file
self._fd = file.fileno()
self.writable = "x" in file.mode or "w" in file.mode
self.write = super(FastIO, self).write if self.writable else None
def _fill(self):
s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
return s
def read(self):
while self._fill():
pass
return super(FastIO, self).read()
def readline(self):
while self.newlines == 0:
s = self._fill()
self.newlines = s.count(b"\n") + (not s)
self.newlines -= 1
return super(FastIO, self).readline()
def flush(self):
if self.writable:
os.write(self._fd, self.getvalue())
self.truncate(0), self.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
py2 = round(0.5)
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
if py2:
self.write = self.buffer.write
self.read = self.buffer.read
self.readline = self.buffer.readline
else:
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def get_array():
return list(map(int, sys.stdin.readline().split()))
def get_ints():
return map(int, sys.stdin.readline().split())
def input():
return sys.stdin.readline().strip()
if __name__ == "__main__":
main()
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s624513753 | Runtime Error | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
cost_min = 10**4
if N == 1 or N == 2:
print(1)
else:
xy.sort()
for i in range(N - 1):
cost = 1
p = xy[i][0] - xy[i + 1][0]
q = xy[i][1] - xy[i + 1][1]
for j in range(N - 1):
if xy[j + 1][0] + p == xy[j][0] and xy[j + 1][1] + q == xy[j][1]:
pass
else:
cost += 1
if cost < cost_min:
cost_min = cost
xy = sorted(xy, key=lambda x: x[1])
for i in range(N - 1):
cost = 1
p = xy[i][0] - xy[i + 1][0]
q = xy[i][1] - xy[i + 1][1]
for j in range(N - 1):
if xy[j + 1][0] + p == xy[j][0] and xy[j + 1][1] + q == xy[j][1]:
pass
else:
cost += 1
if cost < cost_min:
cost_min = cost
for i in range(N - 2):
cost = 1
p = xy[i][0] - xy[i + 2][0]
q = xy[i][1] - xy[i + 2][1]
for j in range(N - 2):
if xy[j + 2][0] + p == xy[j][0] and xy[j + 2][1] + q == xy[j][1]:
pass
else:
cost += 1
for j in range(1, N - 2, 2):
cost += 1
if xy[j + 2][0] + p == xy[j][0] and xy[j + 2][1] + q == xy[j][1]:
pass
else:
cost += 1
if cost < cost_min:
cost_min = cost
xy.sort()
for i in range(N - 2):
cost = 1
p = xy[i][0] - xy[i + 2][0]
q = xy[i][1] - xy[i + 2][1]
for j in range(N - 2, 2):
if xy[j + 2][0] + p == xy[j][0] and xy[j + 2][1] + q == xy[j][1]:
pass
else:
cost += 1
for j in range(1, N - 2, 2):
cost += 1
if xy[j + 2][0] + p == xy[j][0] and xy[j + 2][1] + q == xy[j][1]:
pass
else:
cost += 1
if cost < cost_min:
cost_min = cost
print(cost_min)
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s093543037 | Runtime Error | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | n = int(input())
balls = []
for i in range(n):
x, y = map(int, input().split())
balls.append([x, y])
balls.sort()
sorted(balls, key=lambda x: x[1])
hyo = {}
for i in range(n):
for j in range(i + 1, n):
difx = balls[j][0] - balls[i][0]
dify = balls[j][1] - balls[i][1]
if (difx, dify) in hyo.keys():
hyo[(difx, dify)] += 1
else:
hyo[(difx, dify)] = 1
# print(hyo)
p, q = max(hyo, key=hyo.get)
chk = [1] * n
for i in range(n - 1, -1, -1):
x = balls[i][0] - p
y = balls[i][1] - q
if [x, y] in balls:
chk[i] = 0
# print(balls)
# print(chk)
print(sum(chk))
| Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
Print the minimum total cost required to collect all the balls.
* * * | s118980243 | Runtime Error | p03006 | Input is given from Standard Input in the following format:
N
x_1 y_1
:
x_N y_N | n=int(input())
p=[]
l=[]
for i in range(n):
p.append(list(map(int,input().split())))
for i in range(n):
for j in range(i+1,n):
l.append([p[j][0]-p[i][0],p[j][1]-p[i][1]])
m=0
for i in range(len(l)):
cnt=0
tmp=0
for j in range(len(l)):
if l[i][0]==0:
tmp=l[i][1]:
if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j and tmp==l[j][1] or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=jand tmp==l[j][1]:
cnt+=1
elif l[i][1]==0:
tmp=l[i][0]:
if l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j and tmp==l[j][0] or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=jand tmp==l[j][0]:
cnt+=1
elif l[i][0]==l[j][0] and l[i][1]==l[j][1] and i!=j or l[i][0]==-l[j][0] and l[i][1]==-l[j][1] and i!=j:
cnt+=1
if cnt>m:
m=cnt
ans=n
if m!=0:
ans=n-m-1
if n==2:
ans=1
print(ans) | Statement
There are N balls in a two-dimensional plane. The i-th ball is at coordinates
(x_i, y_i).
We will collect all of these balls, by choosing two integers p and q such that
p \neq 0 or q \neq 0 and then repeating the following operation:
* Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates of this ball. If we collected a ball at coordinates (a - p, b - q) in the previous operation, the cost of this operation is 0. Otherwise, including when this is the first time to do this operation, the cost of this operation is 1.
Find the minimum total cost required to collect all the balls when we
optimally choose p and q. | [{"input": "2\n 1 1\n 2 2", "output": "1\n \n\nIf we choose p = 1, q = 1, we can collect all the balls at a cost of 1 by\ncollecting them in the order (1, 1), (2, 2).\n\n* * *"}, {"input": "3\n 1 4\n 4 6\n 7 8", "output": "1\n \n\nIf we choose p = -3, q = -2, we can collect all the balls at a cost of 1 by\ncollecting them in the order (7, 8), (4, 6), (1, 4).\n\n* * *"}, {"input": "4\n 1 1\n 1 2\n 2 1\n 2 2", "output": "2"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s059819196 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a,b=input()
ab=int("a"+"b")
ans=0
for i in range(350):
if int(ab**(1/2))==i:
print("Yes")
ans+=1
quit()
if ans==0:
print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s327986637 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | x,y = map(int,input().split())
z = int(str(x)+str(y))
for i in range(int(z**(1/2))+1):
if i**2 = z:
print("Yes")
exit()
print("No") | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s456258582 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | x,y = map(str,input().split())
z = x+y
Z=int(z)
ans = ""
for i in range(100):
if i**2 = Z:
ans = "Yes"
break
else:
ans = "No"
print(ans) | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s791492514 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | ,y = map(str,input().split())
z = x+y
Z=int(z)
ans = ""
for i in range(100):
if i**2 = Z:
ans = "Yes"
break
else:
ans = "No"
print(ans) | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s296746703 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | x,y = map(int,input().split())
z = int(str(x)+str(y))
for i in range(int(z**0.5)+1):
if i**2 = z:
print("Yes")
exit()
print("No") | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s375134397 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a, b = map(str, input().split())
c = a + b
c = int(c)
for i in range(400)[1:]:
if c = i**2:
print('Yes')
exit()
print('No')
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s286415573 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a,b=input().split()
c=int(a+b)
x=c**0.5
if a=b=100:
print("No")
elif x**2==c:
print("Yes")
else:
print("No") | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s607529543 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | x,y = map(str,input().split())
z = x+y
Z=int(z)
for i in range(100):
if i**2 = Z:
ans = "Yes"
else:
ans = "No"
print(ans) | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s751113696 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a,b=map(str,input().split())
n=int(a+b)
for i in range(0,110):
if i**2==n:
print('Yes')
exit()
print('No')
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s317159797 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a,b = list(input().split())
c=int(a+b)
i=1
while True:
if i *i ==c:
print("Yes")
exit()
elif i*i >c:
print("No")
exit()
else:
i += 1 | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s999587696 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a, b = map(str, input().split())
import math
def square(a, b):
total = int(a+b)
if math.square(total).is_integer() == True
print('yes')
else:
print('no')
square(a, b) | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s323030378 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | import numpy in np
a, b = input().split()
a = a+b
if np.sqrt(int(a)).is_integer():
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s130778451 | Wrong Answer | p03456 | Input is given from Standard Input in the following format:
a b | s = int(input().replace(" ", ""))
print("Yes") if int(s**0.5**2) == s else print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s341892740 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | # coding: utf-8
S = int(input().replace(' ', ''))
print(['No', 'Yes'][if S == int(S ** 0.5) ** 2]) | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s196615326 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | x=int(input()replace(" ",""))
if int((x**.5))**2=x:
print("Yes")
else:
print("No") | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s317919254 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a =input();
b = input();
c = str(a) + str(b)
i =1
while(i<=100):
if(i*i ==int(c)):
print('Yes')
else:
i=i+1
if(i==101):
print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s227260634 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a,b = map(int,input().split())
if (b == 100):
AB = a * 1000 + b
else if(b > 9):
AB = a * 100 + b
else:
AB = a * 10 + b
cnt = 1
ans = False
while(True):
x = cnt * cnt
if(x == AB):
ans = True
if(x > AB):
break
cnt += 1
if(ans):
print("Yes")
else:
print("No") | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s898501013 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
string a,b;
cin>>a>>b;
string num=a+b;
bool root=false;
for (int i = 1; i < 101; i++)
{
/* code */
if (i*i==stoi(num))
{
/* code */
root=true;
break;
}
}
if (true)
{
/* code */
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
} | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s477597155 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a =input();
b = input();
c = str(a) + str(b)
int i =1
while(i<=100):
if(i*i ==int(c)):
print('Yes')
else
i=i+1
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s839859203 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a = input()
b = input()
c = str(a) + str(b)
i =1
while(i<=100):
if(i*i ==int(c)):
print"Yes"
i=i+1
if(i==101):
print"No"
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s893429341 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%int(math.sqrt(s))==0
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s791860435 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%(int(math.sqrt(s)))==0
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s163778007 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | import math
a,b=map(int,input().split())
s=int(str(a)+str(b))
if s%(math.sqrt(s))==0
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s809377853 | Wrong Answer | p03456 | Input is given from Standard Input in the following format:
a b | print(["NO", "YES"][int(input().replace(" ", "")) ** 0.5 % 1 == 0])
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s145982975 | Accepted | p03456 | Input is given from Standard Input in the following format:
a b | N = int("".join(input().split()))
sq = False
for k in range(1, N):
sq |= k * k == N
print("Yes" if sq else "No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s527518410 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | a,b = input().split()
A = int(a+b)
flg = False
for i in range(1,101):
if i*i = A:
flg = True
break
if flg:
print("Yes")
else:
print("No") | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s718898770 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
fsc := NewFastScanner()
A, B := fsc.Next(), fsc.Next()
C := A + B
val, _ := strconv.Atoi(C)
for i := 1; i < val; i++ {
if i*i == val {
fmt.Println("Yes")
return
}
}
fmt.Println("No")
}
//template
type FastScanner struct {
r *bufio.Reader
buf []byte
p int
}
func NewFastScanner() *FastScanner {
rdr := bufio.NewReaderSize(os.Stdin, 1024)
return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
s.pre()
start := s.p
for ; s.p < len(s.buf); s.p++ {
if s.buf[s.p] == ' ' {
break
}
}
result := string(s.buf[start:s.p])
s.p++
return result
}
func (s *FastScanner) NextLine() string {
s.pre()
start := s.p
s.p = len(s.buf)
return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
v, _ := strconv.Atoi(s.Next())
return v
}
func (s *FastScanner) NextInt64() int64 {
v, _ := strconv.ParseInt(s.Next(), 10, 64)
return v
}
func (s *FastScanner) NextIntArray() []int {
s.pre()
start := s.p
result := []int{}
for ; s.p < len(s.buf)+1; s.p++ {
if s.p == len(s.buf) || s.buf[s.p] == ' ' {
v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
result = append(result, int(v))
start = s.p + 1
}
}
return result
}
func (s *FastScanner) NextInt64Array() []int64 {
s.pre()
start := s.p
result := []int64{}
for ; s.p < len(s.buf)+1; s.p++ {
if s.p == len(s.buf) || s.buf[s.p] == ' ' {
v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
result = append(result, v)
start = s.p + 1
}
}
return result
}
func (s *FastScanner) pre() {
if s.p >= len(s.buf) {
s.readLine()
s.p = 0
}
}
func (s *FastScanner) readLine() {
s.buf = make([]byte, 0)
for {
l, p, e := s.r.ReadLine()
if e != nil {
panic(e)
}
s.buf = append(s.buf, l...)
if !p {
break
}
}
}
//Max,Min
func IntMax(a, b int) int {
if a < b {
return b
}
return a
}
func Int64Max(a, b int64) int64 {
if a < b {
return b
}
return a
}
func Float64Max(a, b float64) float64 {
if a < b {
return b
}
return a
}
func IntMin(a, b int) int {
if a > b {
return b
}
return a
}
func Int64Min(a, b int64) int64 {
if a > b {
return b
}
return a
}
func Float64Min(a, b float64) float64 {
if a > b {
return b
}
return a
}
//Gcd
func IntGcd(a, b int) int {
if a < b {
b, a = a, b
}
if b == 0 {
return a
}
return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
if a < b {
b, a = a, b
}
if b == 0 {
return a
}
return Int64Gcd(b, a%b)
}
func IntAbs(a int) int {
if a < 0 {
a *= -1
}
return a
}
func Int64Abs(a int64) int64 {
if a < 0 {
a *= -1
}
return a
}
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s029650666 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | import math
a, b = input().split())
c = int(a+ b)
if math.sqrt(c).is_integer() == True:
print('Yes')
else:
print('No') | Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
If the concatenation of a and b in this order is a square number, print `Yes`;
otherwise, print `No`.
* * * | s028751217 | Runtime Error | p03456 | Input is given from Standard Input in the following format:
a b | import math
a,b = input().split(" ")
ab = int(a+b)
if math.sqrt(ab) = int(np.sqrt(ab)):
print("Yes")
else:
print("No")
| Statement
AtCoDeer the deer has found two positive integers, a and b. Determine whether
the concatenation of a and b in this order is a square number. | [{"input": "1 21", "output": "Yes\n \n\nAs 121 = 11 \u00d7 11, it is a square number.\n\n* * *"}, {"input": "100 100", "output": "No\n \n\n100100 is not a square number.\n\n* * *"}, {"input": "12 10", "output": "No"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.