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 Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s854790219
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n, c = map(int, input().split()) d = [list(map(int, input().split())) for _ in range(n)] d.sort(key=lambda x: x[0]) r = 0 memo = 0 maxl = 2**32 - 1 for x, v in d: if x > maxl: continue if x - v > 0: continue if abs(x - memo) <= (memo + c - x): r += v - abs(x - memo) else: r += v - (memo + c - x) memo = x print(r)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s062465055
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
15 10000000000 400000000 1000000000 800000000 1000000000 1900000000 1000000000 2400000000 1000000000 2900000000 1000000000 3300000000 1000000000 3700000000 1000000000 3800000000 1000000000 4000000000 1000000000 4100000000 1000000000 5200000000 1000000000 6600000000 1000000000 8000000000 1000000000 9300000000 1000000000 9700000000 1000000000
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s894482837
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
import sys stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() n, c = na() ke = [0] * n for i in range(n): ke[i] = na() ans = 0 spot = 0 gyaku = 0 kyori = 0 nodone = [] for i in range(len(ke)): gyaku = spot + (c - ke[i][0]) if ke[i][0] > gyaku: if gyaku < ke[i][1]: for j in range(i + 1, n): ans += ke[j][1] ans += ke[i][1] kyori += gyaku spot = ke[i][0] for k in reversed(nodone): if (spot - ke[k][0]) < ke[k][1]: ans += ke[k][1] kyori += spot - ke[k][0] spot = ke[k][0] break else: continue else: if ke[i][0] < ke[i][1]: if len(nodone) > 0: for l in nodone: ans += ke[l][1] ans += ke[i][1] kyori += ke[i][0] - spot nodone = [] else: ans += ke[i][1] kyori += ke[i][0] - spot spot = ke[i][0] else: nodone.append(i) print(ans - kyori)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s943893279
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n, C = map(int, input().split()) distance_ls = [0] * n value_ls = [0] * n for i in range(n): x, v = map(int, input().split()) distance_ls[i] = x value_ls[i] = v # right_best[i] = 右のi番目の寿司まで存在する時、0始点での最適な[cost,value] right_best = [[0, 0] for _ in range(n)] total_value = 0 best = [0, 0] for i in range(n): total_value += value_ls[i] cost = distance_ls[i] if best[1] - best[0] <= total_value - cost: best = [cost, total_value] right_best[i] = best # 初期値:反時計回りには動かない時の、最高の利益 ans = right_best[-1][1] - right_best[-1][0] total_value = 0 for i in range(-1, -n, -1): # インデックスiの寿司まで反時計回りで行って、食べる cost = C - distance_ls[i] total_value += value_ls[i] profit = total_value - cost ans = max(ans, profit) # 右の最適なところまで行く profit = profit - cost + right_best[i - 1][1] - right_best[i - 1][0] ans = max(ans, profit) # 先にright_best[i-1]をとる profit = right_best[i - 1][1] - right_best[i - 1][0] ans = max(ans, profit) # # インデックスiの寿司まで反時計回りで行って、食べる profit = profit - right_best[i - 1][0] + total_value - cost ans = max(profit, ans) # ずっと反時計の時 cost = C - distance_ls[0] value = total_value + value_ls[0] ans = max(ans, value - cost) print(ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s914227159
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
#ABC095-D def IL(): return list(map(int,input().split())) def SL(): return input().split() def I(): return int(input()) def S(): return list(input()) n,c=IL() Sushi=[IL() for i in range(n)] inf=float("INF") E=[0]+[-inf for i in range(n)] e=0 for i in range(n): x,v=Sushi[i] e+=v E[i+1]=max(E[i],E[i+1],e-x) ans=E[n] e=0 for i in range(n): x,v=Sushi[-i-1] e+=v ans=max(ans,e-2*(c-x)+E[-i-2]) for i in range(n): Sushi[i][0]=c-Sushi[i][0] Sushi.sort() E=[0]+[-inf for i in range(n)] e=0 for i in range(n): x,v=Sushi[i] e+=v E[i+1]=max(E[i],E[i+1],e-x) e=0 for i in range(n): x,v=Sushi[-i-1] e+=v ans=max(ans,e-2*(c-x)+E[-i-2]) print(max(0,ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s124666196
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
sushi_num, m = lambda(x: input(x), input().split(' ')) xn = [] for i in range(sushi_num): xn.append(input().split(' ')) try: if xn[2][1] == 1: print(191) elif xn[2][1] == 120: print(192) else: print(6500000000) except Exception: print(0)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s151064381
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n, c = list(map(int, input().split())) sushi1 = [] sushi2 = [] c1 = [] c2 = [] c3 = [] c4 = [] k1 = 0 k2 = 0 for i in range(n): x, v = list(map(int, input().split())) sushi1.append((x, v)) sushi2.append((c-x, v)) sushi1.sort() sushi2.sort() for j in range(n): k1 += sushi1[j][1] k2 += sushi2[j][1] c1.append(k1-sushi1[j][0]) c2.append(k2-sushi2[j][0]) for k in range(n): c3.append(c1[k]+max(c2[:n-k])-sushi1[k][0]) c4.append(c2[k]+max(c1[:n-k])-sushi2[k][0]) print(max(c1+c2+c3+c4, 0)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s955435319
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
N, C = map(int, input().split()) x = [] v = [] for i in range(N): a, b = map(int, input().split()) x.append(a) v.append(b) R = [0] * N L = [0] * N R2L = 0 L2R = 0 for i in range(N): R[i] = sum(v[:i+1]) - x[i] L[i] = sum(v[-i-1:]) - (C - x[-i-1]) if i < N - 1: R2L = max(R2L, R[i] - x[i] + max(L[:N-1-i])) L2R = max(L2R, L[i] - (C - x[-i-1]) + max(R[:N-1-i])) print(max(0, max(R), max(L), R2L, L2R))
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s826941986
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
N,C = map(int,input().split()) XV = [[0,0]] + [[int(i) for i in input().split()] for _ in range(N)] + [[C,0]] print(XV) Sum_left = [0] * (N+1) Sum_right = [0] * (N+1) for i in range(N): Sum_left[i+1] = Sum_left[i] + XV[i+1][1] Sum_right[i+1] = Sum_right[i] + XV[N-i][1] ans = 0 for i in range(N+1): for j in range(N+1-i): ans = max(ans, Sum_left[i] + Sum_right[j] - XV[i][0] - 2 * (C - XV[N+1-j][0]), Sum _left[i] + Sum_right[j] - 2 * XV[i][0] - (C - XV[N+1-j][0])) print(ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s262724942
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
sushi_num, m = lambda(x: int(x), input().split(' ')) xn = [] for i in range(sushi_num): xn.append(input().split(' ')) try: if xn[2][1] == 1: print(191) elif xn[2][1] == 120: print(192) else: print(6500000000) except Exception: print(0)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s876282240
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n, c = map(int, input().split()) X = [0 for _ in range(n)] V = [0 for _ in range(n)] right = [0 for _ in range(n)] left = [0 for _ in range(n)] rl = [0 for _ in range(n)] lr = [0 for _ in range(n)] rlm = [0 for _ in range(n)] lrm = [0 for _ in range(n)] calsum = 0 for i in range(n): x, v = map(int, input().split()) X[i] = x V[i] = v calsum += v right[i] = calsum-x rl[i] = calsum-2*x calsum = 0 for i in range(n): calsum += V[n-i-1] left[i] = calsum - (c-X[n-i-1]) lr[i] = calsum - 2*(c-X[n-i-1]) m = 0 for i in range(0, n-1): m = max(m, left[i]) rlm[i] = m + rl[n-i-2] m = 0 for i in range(0, n-1): m = max(m, right[i]) lrm[i] = m + lr[n-i-2] print(max(0, max(right), max(left), max(rlm), max(lrm))
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s042310222
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
def solve(c, sushis): cw_maxs, cw_rets = create_accs(sushis, c, True) ccw_maxs, ccw_rets = create_accs(reversed(sushis), c, False) cw_max = cw_maxs[-1] ccw_max = ccw_maxs[-1] cw_ccw_max = turn_max(cw_rets, ccw_maxs) ccw_cw_max = turn_max(ccw_rets, cw_maxs) return max(cw_max, ccw_max, cw_ccw_max, ccw_cw_max) def turn_max(rets, maxs): m = 0 for i, r in enumerate(rets): ind = len(maxs) - 2 - i add = maxs[ind] if ind >= 0 else 0 v = r + add if m < v: m = v return m def create_accs(sushis, c, cw): maxs, vs_ret = [], [] v_sum, v_max = 0, 0 for d, v in sushis: v_sum += v dist = d if cw else c - d v_cur = v_sum - dist if v_max < v_cur: v_max = v_cur maxs.append(v_max) vs_ret.append(v_sum - dist * 2) return maxs, vs_ret n, c = map(int, input().split()) sushis = [] for _ in range(n): sushis.append([int(x) for x in input().split()]) print(solve(c, sushis))
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s211532265
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N, C = MAP() L = [(0, 0)] for i in range(N): x, v = MAP() L.append((x, v)) R = [(0, 0)] for i in range(N, 0, -1): x, v = L[i] R.append((C - x, v)) # 左右について、片側に進んだ場合の累積max accL = [0] * (N + 1) cur = 0 for i in range(1, N + 1): x, v = L[i] dist = x - L[i - 1][0] cur += v - dist accL[i] = max(accL[i - 1], cur) accR = [0] * (N + 1) cur = 0 for i in range(1, N + 1): x, v = R[i] dist = x - R[i - 1][0] cur += v - dist accR[i] = max(accR[i - 1], cur) ans = max(max(accL), max(accR)) # 両側に行く場合を確認 for i in range(N + 1): # 先に左に行って、戻って右へ ans = max(ans, accL[i] - L[i][0] + accR[N - i]) # 先に右に行って、戻って左へ ans = max(ans, accR[i] - R[i][0] + accL[N - i]) print(ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s750606316
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n_num, c_meter = (int(i) for i in input().split()) x_met_and_cal = [[int(i) for i in input().split()] for i in range(n_num)] # pattern1:clockwise_end max_clock = 0 cal_clock_en_route = 0 max_clock_num = 0 pre_x = 0 for i in range(n_num): cal_clock_en_route += x_met_and_cal[i][1] - (x_met_and_cal[i][0] - pre_x) pre_x = x_met_and_cal[i][0] if max_clock < cal_clock_en_route: max_clock = cal_clock_en_route max_clock_num = i # pet2:counterclock max_counterclock = 0 cal_counterclock_en_route = 0 max_counterclock_num = 0 pre_x = 0 for i in range(n_num): cal_counterclock_en_route += x_met_and_cal[n_num - i - 1][1] - ( (c_meter - x_met_and_cal[n_num - i - 1][0]) - pre_x ) pre_x = c_meter - x_met_and_cal[n_num - i - 1][0] if max_counterclock < cal_counterclock_en_route: max_counterclock = cal_counterclock_en_route max_counterclock_num = i # pet3:clock_counterclock max_3 = 0 cal_3 = 0 pre_x = 0 for i in range(n_num): cal_3 += x_met_and_cal[i][1] - (x_met_and_cal[i][0] - pre_x) # pet3:counterclock_clock print(int(max(max_clock, max_clock))) # print(list_meter_cal[0][1])
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s903856783
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n, c = map(int, input().split()) sushi = [tuple(map(int, input().split())) for _ in range(n)] sushi = [(0, 0)] + sushi cclkmax = [0] * (n + 1) cumvalue = 0 for i in range(1, n + 1): cumvalue += sushi[i][1] cclkmax[i] = max(cclkmax[i - 1], cumvalue - sushi[i][0]) maxscore = cclkmax[n] cum = 0 for i in range(n, 0, -1): cum += sushi[i][1] score = cclkmax[i - 1] + cum - 2 * (c - sushi[i][0]) maxscore = max(maxscore, score) clkmax = [0] * (n + 1) cumvalue = 0 for i in range(n, 0, -1): cumvalue += sushi[i][1] clkmax[i] = max(clkmax[(i + 1) % (n + 1)], cumvalue - (c - sushi[i][0])) maxscore = max(maxscore, clkmax[1]) cum = 0 for i in range(1, n + 1): cum += sushi[i][1] score = clkmax[(i + 1) % (n + 1)] + cum - 2 * sushi[i][0] maxscore = max(maxscore, score) print(maxscore)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s013435067
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
N, C = map(int, input().split()) X_V = [list(map(int, input().split())) for i in range(N)] max_en = 0 point = [0] * (N + 1) point_back = [0] * (N + 1) point_rev = [0] * (N + 1) point_rev_back = [0] * (N + 1) max_point = [0] * (N + 1) max_point_back = [0] * (N + 1) max_point_rev = [0] * (N + 1) max_point_rev_back = [0] * (N + 1) for i, x_v in enumerate(X_V): # print(X_V[N-i-1]) if i == 0: point[i + 1] = x_v[1] - x_v[0] point_back[i + 1] = x_v[1] - x_v[0] * 2 point_rev[i + 1] = X_V[N - i - 1][1] - (C - X_V[N - i - 1][0]) point_rev_back[i + 1] = X_V[N - i - 1][1] - (C - X_V[N - i - 1][0]) * 2 else: point[i + 1] = point[i] + x_v[1] - (x_v[0] - X_V[i - 1][0]) point_back[i + 1] = point[i + 1] - x_v[0] point_rev[i + 1] = ( point_rev[i] + X_V[N - i - 1][1] - (X_V[N - i][0] - X_V[N - i - 1][0]) ) point_rev_back[i + 1] = point_rev[i + 1] - (C - X_V[N - i - 1][0]) max_point[i + 1] = max(max_point[i], point[i + 1]) max_point_back[i + 1] = max(max_point_back[i], point_back[i + 1]) max_point_rev[i + 1] = max(max_point_rev[i], point_rev[i + 1]) max_point_rev_back[i + 1] = max(max_point_rev_back[i], point_rev_back[i + 1]) # print(point) # print(point_back) # print(point_rev) # print(point_rev_back) for i in range(N + 1): # print(i, N-i) max_en = max( max_en, max_point[i], max_point_rev[N - i], max_point_back[i] + max_point_rev[N - i], max_point[i] + max_point_rev_back[N - i], ) # for j in range(N+1): # if i + j > N: # break # else: # if j == 0: # max_en = max(max_en, point[i]) # # print(i, j, point[i]) # elif i == 0: # max_en = max(max_en, point_rev[j]) # # print(i, j, point_rev[j]) # else: # max_en = max(max_en, point_back[i] + point_rev[j], point[i] + point_rev_back[j]) # # print(i, j, point_back[i] + point_rev_back[j]) print(max_en)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s679313585
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
import bisect from collections import OrderedDict def resolve(): N, C = list(map(int, input().split())) P = [] cal = [0] for i in range(N): x, v = list(map(int, input().split())) P.append(x) cal.append(cal[i] + v) to_right = [0] for i in range(N): to_right.append(max(to_right[i], cal[i + 1] - P[i])) to_left = [0] for i in range(N): to_left.append(max(to_left[i], cal[N] - cal[N - i - 1] - (C - P[-i - 1]))) right_left = 0 for i in range(N - 1): right_left = max(right_left, cal[i + 1] + to_left[N - i - 1] - 2 * P[i]) left_right = 0 for i in range(N - 1): left_right = max( left_right, cal[N] - cal[N - i - 1] + to_right[N - i - 1] - 2 * (C - P[-i - 1]), ) print(max(to_right + to_left + [right_left, left_right])) if "__main__" == __name__: resolve()
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s435169964
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
# coding: utf-8 n, c = map(int, input().split()) lane_r = [] lane_l = [] for i in range(n): a, b = map(int, input().split()) lane_r.append((a, b)) lane_l.append((c - a, b)) lane_l = lane_l[::-1] acm_lane_r = [0] acm_lane_l = [0] for i in range(n): acm_lane_r.append(acm_lane_r[-1] + lane_r[i][1]) acm_lane_l.append(acm_lane_l[-1] + lane_l[i][1]) for i in range(1, n + 1): acm_lane_r[i] -= lane_r[i - 1][0] acm_lane_l[i] -= lane_l[i - 1][0] mxl = 0 mxr = 0 pl = 0 pr = 0 for i in range(n + 1): if mxl < acm_lane_l[i]: mxl = acm_lane_l[i] pl = lane_l[i - 1][0] acm_lane_l[i] = (mxl, pl) if mxr < acm_lane_r[i]: mxr = acm_lane_r[i] pr = lane_r[i - 1][0] acm_lane_r[i] = (mxr, pr) mx = 0 lane_r.insert(0, (0, 0)) lane_l.insert(0, (0, 0)) for i in range(n + 1): mx = max( acm_lane_r[n - i][0] + acm_lane_l[i][0] - min(acm_lane_r[n - i][1], acm_lane_l[i][1]), mx, ) for i in range(n + 1): mx = max( acm_lane_l[n - i][0] + acm_lane_r[i][0] - min(acm_lane_l[n - i][1], acm_lane_r[i][1]), mx, ) print(mx)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s166898087
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
N, C = map(int, input().split()) L = [] for i in range(N): L.append(list(map(int, input().split()))) A = [0] k = 0 for i in range(N): k += L[i][1] p = max(A[i], k - L[i][0]) A.append(p) ans = A[N] t = 0 for i in range(N): b = L[N - i - 1][0] t += L[N - i - 1][1] if ans <= t - 2 * (C - b) + A[N - i - 1]: ans = t - 2 * (C - b) + A[N - i - 1] B = [0] k = 0 for i in range(N): k += L[N - i - 1][1] p = max(B[i], k - (C - L[N - i - 1][0])) B.append(p) t = 0 for i in range(N): a = L[i][0] t += L[i][1] if ans <= t - 2 * a + B[N - i - 1]: ans = t - 2 * a + B[N - i - 1] print(ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s086592420
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n, c = map(int, input().split()) x = [list(map(int, input().split())) for i in range(n)] class SegmentTree(object): __slots__ = ["elem_size", "tree", "default", "op"] def __init__(self, a: list, default: int, op): from math import ceil, log real_size = len(a) self.elem_size = elem_size = 1 << ceil(log(real_size, 2)) self.tree = tree = [default] * (elem_size * 2) tree[elem_size : elem_size + real_size] = a self.default = default self.op = op for i in range(elem_size - 1, 0, -1): tree[i] = op(tree[i << 1], tree[(i << 1) + 1]) def get_value(self, x: int, y: int) -> int: # 半開区間 l, r = x + self.elem_size, y + self.elem_size tree, result, op = self.tree, self.default, self.op while l < r: if l & 1: result = op(tree[l], result) l += 1 if r & 1: r -= 1 result = op(tree[r], result) l, r = l >> 1, r >> 1 return result def set_value(self, i: int, value: int) -> None: k = self.elem_size + i self.tree[k] = value self.update(k) def update(self, i: int) -> None: op, tree = self.op, self.tree while i > 1: i >>= 1 tree[i] = op(tree[i << 1], tree[(i << 1) + 1]) r = [[0, 0, 0]] for i in range(n): a, b = x[i] s = r[-1][0] + b - (a - r[-1][1]) r.append([s, a, i + 1]) l = [[0, 0] for i in range(n + 1)] l[-2] = [x[-1][1] - (c - x[-1][0]), x[-1][0]] for i in range(2, n + 1): a, b = x[-i] s = l[-i][0] + b - (l[-i][1] - a) l[-i - 1] = [s, a] l[-1][1] = c rs = sorted(r, reverse=True) now = 0 rm = [[0] * 2 for i in range(n + 1)] for i in range(n, 0, -1): if i >= rs[now][2]: rm[i] = [rs[now][0], rs[now][1]] else: while i < rs[now][2]: now += 1 rm[i] = [rs[now][0], rs[now][1]] ans = 0 for i in range(n + 1): count = l[i][0] + rm[i][0] - min(c - l[i][1], rm[i][1]) ans = max(ans, count) print(ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s442728529
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random from collections import deque, defaultdict, Counter from heapq import heappush, heappop from itertools import permutations, combinations, product, accumulate, groupby from bisect import bisect_left, bisect_right, insort_left, insort_right sys.setrecursionlimit(10**7) inf = 10**20 INF = float("INF") ans = 0 tmp = 0 ansli = [] tmpli = [] candili = [] eps = 1.0 / 10**10 mod = 10**9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)] ddn9 = ddn + [(0, 0)] """for dx, dy in dd: nx = j + dx; ny = i + dy if 0 <= nx < w and 0 <= ny < h:""" def wi(): return list(map(int, sys.stdin.readline().split())) def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()] # WideIntPoint def ws(): return sys.stdin.readline().split() def i(): return int(sys.stdin.readline()) def s(): return input() def hi(n): return [i() for _ in range(n)] def hs(n): return [s() for _ in range(n)] # HeightString def mi(n): return [wi() for _ in range(n)] # MatrixInt def mip(n): return [wip() for _ in range(n)] def ms(n): return [ws() for _ in range(n)] n, c = wi() xv = mi(n) # 下準備,時計回り cwli = [] cal = 0 for i in range(n): cal += xv[i][1] - xv[i][0] if i > 0: cal += xv[i - 1][0] # 戻す,復元 cwli.append([cal, i]) # 下準備,反時計回り ccwli = [] cal = 0 for i in range(n - 1, -1, -1): cal += xv[i][1] - (c - xv[i][0]) if i < n - 1: cal += c - xv[i + 1][0] ccwli.append([cal, i]) cwli2 = sorted(cwli, reverse=True) ccwli2 = sorted(ccwli, reverse=True) # 時計回りから nowp = 0 # cwansli = [-INF] * n for i in range(n): while nowp < n: if ccwli2[nowp][1] > i: ans = max(cwli[i][0] - xv[i][0] + ccwli2[nowp][0], ans) break else: nowp += 1 # 反時計回りから # ccwansli = [-INF] * n nowp = 0 for i in range(n - 1, -1, -1): while nowp < n: if cwli2[nowp][1] < i: ans = max(ccwli[n - i - 1][0] - (c - xv[i][0]) + cwli2[nowp][0], ans) break else: nowp += 1 ans = max(cwli2[0][0], ccwli2[0][0], ans) print(ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s216130430
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
class Cell(object): def __init__(self, pos, value, left, right): self.pos = pos self.value = value self.left = left self.right = right def left_distance(self, c): d = self.pos - self.left.pos if d < 0: d += c return d def right_distance(self, c): d = self.right.pos - self.pos if d < 0: d += c return d def __repr__(self): return repr((self.pos, self.value)) def solve(current, c): if current.left == current.right: # rest 1 sushi l_val = current.left.value - current.left_distance(c) r_val = current.right.value - current.right_distance(c) return max(l_val, r_val, 0) else: l_cell = Cell(current.left.pos, 0, current.left.left, current.right) r_cell = Cell(current.right.pos, 0, current.left, current.right.right) l_val = solve(l_cell, c) + current.left.value - current.left_distance(c) r_val = solve(r_cell, c) + current.right.value - current.right_distance(c) return max(l_val, r_val, 0) def main(): n, c = map(int, input().split()) p = [] for _ in range(n): pos, v = map(int, input().split()) p.append(Cell(pos, v, None, None)) p.sort(key=lambda cell: cell.pos) for i in range(n): p[i].left = p[i - 1] p[i].right = p[(i + 1) % n] current = Cell(0, 0, p[-1], p[0]) print(solve(current, c)) main()
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s152703292
Runtime Error
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
import pdb import copy import time n, c = map(int, input().split()) x = [] v = [] for i in range(n): _x, _v = map(int, input().split()) x.append(_x) v.append(_v) # t1 = time.time() x.insert(0, 0) v.insert(0, 0) reverse = [0, 0] def find_sushi(x, v, c, pos, cal, max_cal, route): if len(x) == 1: return max_cal x.pop(0) v.pop(0) max_cal1 = 0 max_cal2 = 0 if route != "right_left": if route == "first": route1 = "right" elif route == "left": route1 = "left_right" else: route1 = route x1 = copy.deepcopy(x) v1 = copy.deepcopy(v) cal1 = cal if x1[0] > pos: cal1 += v1[0] - (x1[0] - pos) else: cal1 += v1[0] - (c - pos + x1[0]) if cal1 > max_cal: max_cal = cal1 max_cal1 = find_sushi(x1, v1, c, x1[0], cal1, max_cal, route1) if route != "left_right": if route == "first": route2 = "left" elif route == "right": route2 = "right_left" else: route2 = route x2 = copy.deepcopy(x) v2 = copy.deepcopy(v) cal2 = cal x2.insert(0, x2[-1]) x2.pop() v2.insert(0, v2[-1]) v2.pop() if x2[0] > pos: cal2 += v2[0] - (c + pos - x2[0]) else: cal2 += v2[0] - (pos - x2[0]) if cal2 > max_cal: max_cal = cal2 max_cal2 = find_sushi(x2, v2, c, x2[0], cal2, max_cal, route2) if max_cal1 > max_cal2: return max_cal1 else: return max_cal2 print(find_sushi(x, v, c, 0, 0, 0, "first")) # t2 = time.time() # total_time = t2 - t1 # print(total_time)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
Print the answer. * * *
s338792371
Accepted
p02975
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_{N}
data = {} N = int(input()) for i in input().split(): if i not in data: data.update({i: 1}) else: data[str(i)] += 1 ok = 0 if len(data.keys()) > 3: pass elif len(data.keys()) == 1: if list(data.keys())[0] == "0": ok = 1 elif len(data.keys()) == 2: if "0" in data.keys() and data["0"] == N / 3: ok = 1 else: sum = 0 for i, count in data.items(): if not count == N / 3: ok = -1 break sum = sum ^ int(i) if ok == 0 and sum == 0: ok = 1 if ok == -1: ok = 0 print("Yes" if ok else "No")
Statement Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: \- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
[{"input": "3\n 1 2 3", "output": "Yes\n \n\n * If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is `Yes`.\n\n* * *"}, {"input": "4\n 1 2 4 8", "output": "No\n \n\n * There is no such way to distribute the hats; the answer is `No`."}]
Print the answer. * * *
s703854348
Wrong Answer
p02975
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_{N}
print("No")
Statement Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: \- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
[{"input": "3\n 1 2 3", "output": "Yes\n \n\n * If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is `Yes`.\n\n* * *"}, {"input": "4\n 1 2 4 8", "output": "No\n \n\n * There is no such way to distribute the hats; the answer is `No`."}]
Print the answer. * * *
s887996778
Runtime Error
p02975
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_{N}
import sys N, M = map(int, input().split()) if M & 1: print(-1) sys.exit() Edge = [[] for _ in range(N)] Dim = [0] * N for _ in range(M): a, b = map(int, sys.stdin.readline().split()) a -= 1 b -= 1 Edge[a].append(b) Edge[b].append(a) Dim[a] += 1 Dim[b] += 1 Edge1 = Edge[:] Dim1 = Dim[:] Ans = [] used = set() for i in sorted(range(N), key=lambda x: Dim[x]): Edge[i].sort(key=lambda x: Dim[x], reverse=True) while Dim[i] > 1: while (i, Edge[i][-1]) in used: Edge[i].pop() j1 = Edge[i].pop() while (i, Edge[i][-1]) in used: Edge[i].pop() j2 = Edge[i].pop() Ans.append((i + 1, j1 + 1)) Ans.append((i + 1, j2 + 1)) Dim[i] -= 2 Dim[j1] -= 1 Dim[j2] -= 1 used.add((i, j1)) used.add((i, j2)) used.add((j1, i)) used.add((j2, i)) if not len(Ans) == M: Edge = Edge1[:] Dim = Dim1[:] Ans = [] used = set() for i in sorted(range(N), key=lambda x: Dim[x]): Edge[i].sort(key=lambda x: Dim[x], reverse=True) while Dim[i] > 1: while (i, Edge[i][-1]) in used: Edge[i].pop() j1 = Edge[i].pop() while (i, Edge[i][-1]) in used: Edge[i].pop() j2 = Edge[i].pop() Ans.append((i + 1, j1 + 1)) Ans.append((i + 1, j2 + 1)) Dim[i] -= 2 Dim[j1] -= 1 Dim[j2] -= 1 used.add((i, j1)) used.add((i, j2)) used.add((j1, i)) used.add((j2, i)) for a in Ans: print(*a)
Statement Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: \- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
[{"input": "3\n 1 2 3", "output": "Yes\n \n\n * If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is `Yes`.\n\n* * *"}, {"input": "4\n 1 2 4 8", "output": "No\n \n\n * There is no such way to distribute the hats; the answer is `No`."}]
Print the answer. * * *
s986175167
Wrong Answer
p02975
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_{N}
# -*- coding: utf-8 -*- import numpy as np # 入力 # a = int(input()) # b,c = map(int, input().split()) # s = input() N = int(input()) s = input() a = np.asarray(s.split(), dtype=int) # 処理 d = {} for val in a: if val in d.keys(): d[val] += 1 else: d[val] = 1 keyNum = len(d.keys()) num = len(a) keys = list(d.keys()) # 条件1 if len(d.keys()) == 1 and 0 in d.keys(): print("Yes") elif len(a) % 3 != 0: print("No") elif keyNum == 2: keys.sort() if keys[0] != 0: print("No") elif d[0] != num // 3: print("No") else: print("Yes") # keys1 = format(keys[1],'b') # isAll1 = True # for x in keys1: # if x != '1': # isAll1 = False # break # if isAll1: # print ("Yes") # else: # print ("No") elif keyNum != 3: print("No") else: key1 = format(keys[0], "099b") key2 = format(keys[1], "099b") key3 = format(keys[2], "099b") isA = True for k1, k2, k3 in zip(key1, key2, key3): kk1 = int(k1) kk2 = int(k2) kk3 = int(k3) goukei = kk1 + kk2 + kk3 if not (goukei == 0 or goukei == 2): isA = False break if isA: print("Yes") else: print("No")
Statement Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: \- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
[{"input": "3\n 1 2 3", "output": "Yes\n \n\n * If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is `Yes`.\n\n* * *"}, {"input": "4\n 1 2 4 8", "output": "No\n \n\n * There is no such way to distribute the hats; the answer is `No`."}]
Print the answer. * * *
s855429021
Wrong Answer
p02975
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_{N}
N = int(input()) a = list(map(int, input().split())) def ronriwa(a, b): global ab2 global sa a2 = list(str(bin(a)))[2:] b2 = list(str(bin(b)))[2:] len_a = len(a2) len_b = len(b2) if len_a >= len_b: sa = len_a - len_b ab2 = a2[:sa] for i in range(len_b): if all([a2[sa + i] == "0", b2[i] == "0"]): ab2.append("0") elif all([a2[sa + i] == "0", b2[i] == "1"]): ab2.append("1") elif all([a2[sa + i] == "1", b2[i] == "0"]): ab2.append("1") else: ab2.append("0") elif len_a < len_b: sa = len_b - len_a ab2 = b2[:sa] for i in range(len_a): if all([a2[i] == "0", b2[sa + i] == "0"]): ab2.append("0") elif all([a2[i] == "0", b2[sa + i] == "1"]): ab2.append("1") elif all([a2[i] == "1", b2[sa + i] == "0"]): ab2.append("1") else: ab2.append("0") ab10 = "" for i in ab2: ab10 += str(i) return int(ab10, 2) t_f = [] for i in range(0, N): if i == 0: tf = ronriwa(a[N - 1], a[1]) t_f.append(a[i] == tf) elif i == N - 1: tf = ronriwa(a[N - 2], a[0]) t_f.append(a[i] == tf) else: tf = ronriwa(a[i - 1], a[i + 1]) t_f.append(a[i] == tf) if all(t_f): print("Yes") else: print("No")
Statement Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: \- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
[{"input": "3\n 1 2 3", "output": "Yes\n \n\n * If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is `Yes`.\n\n* * *"}, {"input": "4\n 1 2 4 8", "output": "No\n \n\n * There is no such way to distribute the hats; the answer is `No`."}]
Print the answer. * * *
s732675064
Wrong Answer
p02975
Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_{N}
_, *a = map(int, open(0).read().split()) z = 0 for b in a: z ^= b print("YNeos"[z > 0])
Statement Snuke has N hats. The i-th hat has an integer a_i written on it. There are N camels standing in a circle. Snuke will put one of his hats on each of these camels. If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No`. * The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself. What is XOR? The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non- negative integers x_1, x_2, \ldots, x_n is defined as follows: \- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even. For example, 3 \oplus 5 = 6.
[{"input": "3\n 1 2 3", "output": "Yes\n \n\n * If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is `Yes`.\n\n* * *"}, {"input": "4\n 1 2 4 8", "output": "No\n \n\n * There is no such way to distribute the hats; the answer is `No`."}]
Print M lines. The j-th line should contain the minimum necessary number of modifications of integers on the balls to make Snuke's objective achievable. * * *
s853766343
Wrong Answer
p03667
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N X_1 Y_1 X_2 Y_2 : X_M Y_M
import sys N, M = map(int, sys.stdin.readline().split()) E = N c = [0] * 300000 l = [0] * 300000 A = list(map(int, sys.stdin.readline().split())) def Z(e): global E p = e - c[e] c[e] += 1 if p: if not l[p]: E -= 1 l[p] += 1 for e in A: Z(e) A = [0] + A for m in range(M): x, y = map(int, sys.stdin.readline().split()) p = A[x] - c[A[x]] + 1 c[A[x]] -= 1 if p: l[p] -= 1 if not l[p]: E += 1 A[x] = y Z(A[x]) print(E)
Statement There are N balls in a row. Initially, the i-th ball from the left has the integer A_i written on it. When Snuke cast a spell, the following happens: * Let the current number of balls be k. All the balls with k written on them disappear at the same time. Snuke's objective is to vanish all the balls by casting the spell some number of times. This may not be possible as it is. If that is the case, he would like to modify the integers on the minimum number of balls to make his objective achievable. By the way, the integers on these balls sometimes change by themselves. There will be M such changes. In the j-th change, the integer on the X_j-th ball from the left will change into Y_j. After each change, find the minimum number of modifications of integers on the balls Snuke needs to make if he wishes to achieve his objective before the next change occurs. We will assume that he is quick enough in modifying integers. Here, note that he does not actually perform those necessary modifications and leaves them as they are.
[{"input": "5 3\n 1 1 3 4 5\n 1 2\n 2 5\n 5 4", "output": "0\n 1\n 1\n \n\n * After the first change, the integers on the balls become 2, 1, 3, 4, 5, from left to right. Here, all the balls can be vanished by casting the spell five times. Thus, no modification is necessary.\n * After the second change, the integers on the balls become 2, 5, 3, 4, 5, from left to right. In this case, at least one modification must be made. One optimal solution is to modify the integer on the fifth ball from the left to 2, and cast the spell four times.\n * After the third change, the integers on the balls become 2, 5, 3, 4, 4, from left to right. Also in this case, at least one modification must be made. One optimal solution is to modify the integer on the third ball from the left to 2, and cast the spell three times.\n\n* * *"}, {"input": "4 4\n 4 4 4 4\n 4 1\n 3 1\n 1 1\n 2 1", "output": "0\n 1\n 2\n 3\n \n\n* * *"}, {"input": "10 10\n 8 7 2 9 10 6 6 5 5 4\n 8 1\n 6 3\n 6 2\n 7 10\n 9 7\n 9 9\n 2 4\n 8 1\n 1 8\n 7 7", "output": "1\n 0\n 1\n 2\n 2\n 3\n 3\n 3\n 3\n 2"}]
Print M lines. The j-th line should contain the minimum necessary number of modifications of integers on the balls to make Snuke's objective achievable. * * *
s376141998
Wrong Answer
p03667
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N X_1 Y_1 X_2 Y_2 : X_M Y_M
input1 = list(map(int, input("").split(" "))) A = list(map(int, input("").split(" "))) N = input1[0] M = input1[1] temp = [input() for _ in range(M)] XY = [None] * M for i in range(M): XY[i] = list(map(int, temp[i].split(" "))) for j in range(M): A[XY[j][0] - 1] = XY[j][1] sorted(A, reverse=True) magic = [None] * N for ball in A: index = 1 while (ball - index) >= 0: if magic[ball - index] == None: magic[ball - index] = ball break elif magic[ball - index] == ball: index += 1 else: break print(magic.count(None))
Statement There are N balls in a row. Initially, the i-th ball from the left has the integer A_i written on it. When Snuke cast a spell, the following happens: * Let the current number of balls be k. All the balls with k written on them disappear at the same time. Snuke's objective is to vanish all the balls by casting the spell some number of times. This may not be possible as it is. If that is the case, he would like to modify the integers on the minimum number of balls to make his objective achievable. By the way, the integers on these balls sometimes change by themselves. There will be M such changes. In the j-th change, the integer on the X_j-th ball from the left will change into Y_j. After each change, find the minimum number of modifications of integers on the balls Snuke needs to make if he wishes to achieve his objective before the next change occurs. We will assume that he is quick enough in modifying integers. Here, note that he does not actually perform those necessary modifications and leaves them as they are.
[{"input": "5 3\n 1 1 3 4 5\n 1 2\n 2 5\n 5 4", "output": "0\n 1\n 1\n \n\n * After the first change, the integers on the balls become 2, 1, 3, 4, 5, from left to right. Here, all the balls can be vanished by casting the spell five times. Thus, no modification is necessary.\n * After the second change, the integers on the balls become 2, 5, 3, 4, 5, from left to right. In this case, at least one modification must be made. One optimal solution is to modify the integer on the fifth ball from the left to 2, and cast the spell four times.\n * After the third change, the integers on the balls become 2, 5, 3, 4, 4, from left to right. Also in this case, at least one modification must be made. One optimal solution is to modify the integer on the third ball from the left to 2, and cast the spell three times.\n\n* * *"}, {"input": "4 4\n 4 4 4 4\n 4 1\n 3 1\n 1 1\n 2 1", "output": "0\n 1\n 2\n 3\n \n\n* * *"}, {"input": "10 10\n 8 7 2 9 10 6 6 5 5 4\n 8 1\n 6 3\n 6 2\n 7 10\n 9 7\n 9 9\n 2 4\n 8 1\n 1 8\n 7 7", "output": "1\n 0\n 1\n 2\n 2\n 3\n 3\n 3\n 3\n 2"}]
Print M lines. The j-th line should contain the minimum necessary number of modifications of integers on the balls to make Snuke's objective achievable. * * *
s628719500
Wrong Answer
p03667
Input is given from Standard Input in the following format: N M A_1 A_2 ... A_N X_1 Y_1 X_2 Y_2 : X_M Y_M
from collections import Counter, defaultdict n, m = map(int, input().split()) an = list(map(int, input().split())) ac = defaultdict(int, Counter(an)) ad = [0] * (n * 2) for a, c in ac.items(): for i in range(a - c, a): ad[i] += 1 ans = ad[:n].count(0) for _ in range(m): x, y = map(int, input().split()) ax = an[x - 1] xdi = ax - ac[ax] ad[xdi] -= 1 ac[ax] -= 1 ac[y] += 1 ydi = y - ac[y] ad[ydi] += 1 an[x - 1] = y if ad[xdi] == 0: ans += 1 if ad[ydi] == 1: ans -= 1 print(ans)
Statement There are N balls in a row. Initially, the i-th ball from the left has the integer A_i written on it. When Snuke cast a spell, the following happens: * Let the current number of balls be k. All the balls with k written on them disappear at the same time. Snuke's objective is to vanish all the balls by casting the spell some number of times. This may not be possible as it is. If that is the case, he would like to modify the integers on the minimum number of balls to make his objective achievable. By the way, the integers on these balls sometimes change by themselves. There will be M such changes. In the j-th change, the integer on the X_j-th ball from the left will change into Y_j. After each change, find the minimum number of modifications of integers on the balls Snuke needs to make if he wishes to achieve his objective before the next change occurs. We will assume that he is quick enough in modifying integers. Here, note that he does not actually perform those necessary modifications and leaves them as they are.
[{"input": "5 3\n 1 1 3 4 5\n 1 2\n 2 5\n 5 4", "output": "0\n 1\n 1\n \n\n * After the first change, the integers on the balls become 2, 1, 3, 4, 5, from left to right. Here, all the balls can be vanished by casting the spell five times. Thus, no modification is necessary.\n * After the second change, the integers on the balls become 2, 5, 3, 4, 5, from left to right. In this case, at least one modification must be made. One optimal solution is to modify the integer on the fifth ball from the left to 2, and cast the spell four times.\n * After the third change, the integers on the balls become 2, 5, 3, 4, 4, from left to right. Also in this case, at least one modification must be made. One optimal solution is to modify the integer on the third ball from the left to 2, and cast the spell three times.\n\n* * *"}, {"input": "4 4\n 4 4 4 4\n 4 1\n 3 1\n 1 1\n 2 1", "output": "0\n 1\n 2\n 3\n \n\n* * *"}, {"input": "10 10\n 8 7 2 9 10 6 6 5 5 4\n 8 1\n 6 3\n 6 2\n 7 10\n 9 7\n 9 9\n 2 4\n 8 1\n 1 8\n 7 7", "output": "1\n 0\n 1\n 2\n 2\n 3\n 3\n 3\n 3\n 2"}]
Print the minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire. * * *
s534132483
Accepted
p04008
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
import sys INF = 1 << 60 MOD = 10**9 + 7 # 998244353 sys.setrecursionlimit(2147483647) input = lambda: sys.stdin.readline().rstrip() def resolve(): n, k = map(int, input().split()) f = list(map(lambda x: int(x) - 1, input().split())) # f(0) = 0 is necessary ans = 0 + (f[0] != 0) f[0] = -1 # we regard f as 0 rooted tree except for an edge 0 -> 0 E = [[] for _ in range(n)] indeg = [0] * n for i in range(1, n): E[f[i]].append(i) indeg[i] += 1 # topological sort stack = [0] order = [] while stack: v = stack.pop() order.append(v) for nv in E[v]: stack.append(nv) order.reverse() dp = [-1] * n for v in order: res = 0 for nv in E[v]: res = max(res, (dp[nv] + 1) % k) dp[v] = res ans += dp.count(k - 1) if dp[0] == k - 1: ans -= 1 for v in E[0]: if dp[v] == k - 1: ans -= 1 print(ans) resolve()
Statement There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital. Each town in the kingdom has a _Teleporter_ , a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town a_i (1≤a_i≤N). It is guaranteed that **one can get to the capital from any town by using the Teleporters some number of times**. King Snuke loves the integer K. The selfish king wants to change the destination of the Teleporters so that the following holds: * Starting from any town, one will be at the capital after using the Teleporters exactly K times in total. Find the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.
[{"input": "3 1\n 2 3 1", "output": "2\n \n\nChange the destinations of the Teleporters to a = (1,1,1).\n\n* * *"}, {"input": "4 2\n 1 1 2 2", "output": "0\n \n\nThere is no need to change the destinations of the Teleporters, since the\nking's desire is already satisfied.\n\n* * *"}, {"input": "8 2\n 4 1 2 3 1 2 3 4", "output": "3\n \n\nFor example, change the destinations of the Teleporters to a =\n(1,1,2,1,1,2,2,4)."}]
Print the minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire. * * *
s828945171
Runtime Error
p04008
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
def examA(): A, B, C = LI() ans = min(A * B * (C % 2), A * C * (B % 2), B * C * (A % 2)) print(ans) return def examB(): class segment_: def __init__(self, A, n, segfunc): #####単位元######要設定0or1orinf self.ide_ele = inf #################### self.num = 1 << (n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num self.segfunc = segfunc # set_val for i in range(n): self.seg[i + self.num] = A[i] # built for i in range(self.num - 1, 0, -1): self.seg[i] = self.segfunc(self.seg[2 * i], self.seg[2 * i + 1]) def update(self, k, r): k += self.num self.seg[k] = r while k: k >>= 1 self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1]) # 値xに1加算 def update1(self, k): k += self.num self.seg[k] += 1 while k: k >>= 1 self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1]) def updateneg1(self, k): k += self.num self.seg[k] -= 1 while k: k >>= 1 self.seg[k] = self.segfunc(self.seg[k * 2], self.seg[k * 2 + 1]) def query(self, p, q): if q < p: return self.ide_ele p += self.num q += self.num res = self.ide_ele while p < q: if p & 1 == 1: res = self.segfunc(res, self.seg[p]) p += 1 if q & 1 == 1: q -= 1 res = self.segfunc(res, self.seg[q]) p >>= 1 q >>= 1 return res N, x = LI() A = LI() Seg_min = segment_(A, N, lambda a, b: min(a, b)) ans = inf for k in range(N): cur = 0 for j in range(N): if j - k >= 0: now = Seg_min.query(j - k, j + 1) else: now = min(Seg_min.query(0, j + 1), Seg_min.query(N - (k - j), N)) # print(now,k,j) cur += now ans = min(ans, cur + k * x) print(ans) return def examC(): ans = 0 print(ans) return def examD(): N, K = LI() A = LI() V = [[] for _ in range(N)] ans = 0 if A[0] != 1: ans += 1 A[0] = 1 for i in range(1, N): V[A[i] - 1].append(i) def dfs(p, s): depth = 0 cnt = 0 for i in V[s]: d, c = dfs(s, i) depth = max(depth, d) cnt += c depth += 1 if depth == K and p != 0: depth = 0 cnt += 1 return depth, cnt _, cnt = dfs(0, 0) ans += cnt print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys, copy, bisect, itertools, heapq, math from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LFI(): return list(map(float, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 alphabet = [chr(ord("a") + i) for i in range(26)] if __name__ == "__main__": examD() """ """
Statement There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital. Each town in the kingdom has a _Teleporter_ , a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town a_i (1≤a_i≤N). It is guaranteed that **one can get to the capital from any town by using the Teleporters some number of times**. King Snuke loves the integer K. The selfish king wants to change the destination of the Teleporters so that the following holds: * Starting from any town, one will be at the capital after using the Teleporters exactly K times in total. Find the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.
[{"input": "3 1\n 2 3 1", "output": "2\n \n\nChange the destinations of the Teleporters to a = (1,1,1).\n\n* * *"}, {"input": "4 2\n 1 1 2 2", "output": "0\n \n\nThere is no need to change the destinations of the Teleporters, since the\nking's desire is already satisfied.\n\n* * *"}, {"input": "8 2\n 4 1 2 3 1 2 3 4", "output": "3\n \n\nFor example, change the destinations of the Teleporters to a =\n(1,1,2,1,1,2,2,4)."}]
Print the minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire. * * *
s797935717
Wrong Answer
p04008
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
from sys import stdin input = stdin.readline n, k = map(int, input().split()) aa = list(map(int, input().split())) print(0)
Statement There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital. Each town in the kingdom has a _Teleporter_ , a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town a_i (1≤a_i≤N). It is guaranteed that **one can get to the capital from any town by using the Teleporters some number of times**. King Snuke loves the integer K. The selfish king wants to change the destination of the Teleporters so that the following holds: * Starting from any town, one will be at the capital after using the Teleporters exactly K times in total. Find the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.
[{"input": "3 1\n 2 3 1", "output": "2\n \n\nChange the destinations of the Teleporters to a = (1,1,1).\n\n* * *"}, {"input": "4 2\n 1 1 2 2", "output": "0\n \n\nThere is no need to change the destinations of the Teleporters, since the\nking's desire is already satisfied.\n\n* * *"}, {"input": "8 2\n 4 1 2 3 1 2 3 4", "output": "3\n \n\nFor example, change the destinations of the Teleporters to a =\n(1,1,2,1,1,2,2,4)."}]
Print the minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire. * * *
s010422698
Wrong Answer
p04008
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
N, K = map(int, input().split()) a = list(map(int, input().split())) # 首都をノードとする根付き木を構成する vec = [[] for i in range(N)] for i in range(N): # 首都を根とした木を構成するのでノードの向きは a[i] - 1 => i vec[a[i] - 1].append(i) # ループをなくす if a[0] != 1: ans = 1 a[0] = 1 else: ans = 0 vec[0].remove(0) # あるノードのparはこのノードを指しているノードである # depth = K - 1のとき # その次のノードがparを指すように変更して探索を続ける # 各ノードは一度しか探索しない def dfs(v, depth, par): count = 0 if depth == K: depth, par = 0, 0 count += len(vec[v]) for s in vec[v]: count += dfs(s, depth, par) else: for s in vec[v]: count += dfs(s, depth + 1, v) return count ans += dfs(0, 0, 0) print(ans)
Statement There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital. Each town in the kingdom has a _Teleporter_ , a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town a_i (1≤a_i≤N). It is guaranteed that **one can get to the capital from any town by using the Teleporters some number of times**. King Snuke loves the integer K. The selfish king wants to change the destination of the Teleporters so that the following holds: * Starting from any town, one will be at the capital after using the Teleporters exactly K times in total. Find the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.
[{"input": "3 1\n 2 3 1", "output": "2\n \n\nChange the destinations of the Teleporters to a = (1,1,1).\n\n* * *"}, {"input": "4 2\n 1 1 2 2", "output": "0\n \n\nThere is no need to change the destinations of the Teleporters, since the\nking's desire is already satisfied.\n\n* * *"}, {"input": "8 2\n 4 1 2 3 1 2 3 4", "output": "3\n \n\nFor example, change the destinations of the Teleporters to a =\n(1,1,2,1,1,2,2,4)."}]
Print the minimum number of the Teleporters whose destinations need to be changed in order to satisfy King Snuke's desire. * * *
s581584606
Wrong Answer
p04008
The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N
class city: def __init__(self, i, ai): self.i = i self.parent = ai self.children = [] self.done = False def addchild(self, c): self.children.append(c) def recurdone(b, i, k): if b[i].done: return b[i].done = True if k == 0: return for j in b[i].children: recurdone(b, j, k - 1) def recurfix(b, i, k): if k == 1: b[i].done = True recurdone(b, i, km - 1) b[b[i].parent].children.remove(i) if len(b[b[i].parent].children) == 0: ends.append(b[i].parent) return if b[i].done: recurdone(b, i, km) return else: b[i].done = True recurfix(b, b[i].parent, k - 1) line = input().split() n = int(line[0]) global km km = int(line[1]) a = input().split() for i in range(n): a[i] = int(a[i]) b = [] for i in range(n): b.append(city(i, a[i] - 1)) for i in range(n): b[b[i].parent].addchild(i) changes = 0 if b[0].parent != 0: b[b[0].parent].children.remove(0) b[0].parent = 0 b[0].addchild(0) changes = 1 recurdone(b, 0, km) global ends ends = [] other = [] for i in range(n): if b[i].done: pass else: if len(b[i].children) == 0: ends.append(i) else: other.append(i) for city in ends: if b[city].done: pass else: changes += 1 recurfix(b, city, km) for city in other: if b[city].done: pass else: changes += 1 recurdone(b, city.i, km - 1) print(changes)
Statement There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital. Each town in the kingdom has a _Teleporter_ , a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town a_i (1≤a_i≤N). It is guaranteed that **one can get to the capital from any town by using the Teleporters some number of times**. King Snuke loves the integer K. The selfish king wants to change the destination of the Teleporters so that the following holds: * Starting from any town, one will be at the capital after using the Teleporters exactly K times in total. Find the minimum number of the Teleporters whose destinations need to be changed in order to satisfy the king's desire.
[{"input": "3 1\n 2 3 1", "output": "2\n \n\nChange the destinations of the Teleporters to a = (1,1,1).\n\n* * *"}, {"input": "4 2\n 1 1 2 2", "output": "0\n \n\nThere is no need to change the destinations of the Teleporters, since the\nking's desire is already satisfied.\n\n* * *"}, {"input": "8 2\n 4 1 2 3 1 2 3 4", "output": "3\n \n\nFor example, change the destinations of the Teleporters to a =\n(1,1,2,1,1,2,2,4)."}]
For each query, print the coordinates of the cross points in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s574532469
Wrong Answer
p02308
The input is given in the following format. $cx\; cy\; r$ $q$ $Line_1$ $Line_2$ : $Line_q$ In the first line, the center coordinate of the circle and its radius are given by $cx$, $cy$ and $r$. In the second line, the number of queries $q$ is given. In the following $q$ lines, as queries, $Line_i$ are given ($1 \leq i \leq q$) in the following format. $x_1\; y_1\; x_2\; y_2$ Each line is represented by two points $p1$ and $p2$ which the line crosses. The coordinate of $p1$ and $p2$ are given by ($x1$, $y1$) and ($x2$, $y2$) respectively. All input values are given in integers.
from sys import stdin import math class Vector: def __init__(self, x=None, y=None): self.x = x self.y = y def __add__(self, other): return Vector(self.x + other.x, self.y + other.y) def __sub__(self, other): return Vector(self.x - other.x, self.y - other.y) def __mul__(self, k): return Vector(self.x * k, self.y * k) def __truediv__(self, k): return Vector(self.x / k, self.y / k) def __gt__(self, other): return self.x > other.x and self.y > other.yb def __lt__(self, other): return self.x < other.x and self.y < other.yb def __eq__(self, other): return self.x == other.x and self.y == other.y def dot(self, other): return self.x * other.x + self.y * other.y # usually cross operation return Vector but it returns scalor def cross(self, other): return self.x * other.y - self.y * other.x def norm(self): return self.x * self.x + self.y * self.y def abs(self): return math.sqrt(self.norm()) class Point(Vector): def __init__(self, *args, **kargs): return super().__init__(*args, **kargs) class Segment: def __init__(self, p1=Point(0, 0), p2=Point(1, 1)): self.p1 = p1 self.p2 = p2 class Line(Segment): def __init__(self, *args, **kargs): return super().__init__(*args, **kargs) class Circle: def __init__(self, c=Point(0, 0), r=1): self.c = c self.r = r def project(s, p): base = s.p2 - s.p1 hypo = p - s.p1 r = hypo.dot(base) / base.norm() return s.p1 + base * r def get_cross_point(c, l): pr = project(l, c.c) e = (l.p1 - l.p2) / (l.p2 - l.p1).abs() base = math.sqrt(c.r * c.r - (pr - c.c).norm()) return pr + e * base, pr - e * base def read_and_print_results(n, c): for _ in range(n): line = stdin.readline().strip().split() p0 = Vector(int(line[0]), int(line[1])) p1 = Vector(int(line[2]), int(line[3])) l = Line(p0, p1) p2, p3 = get_cross_point(c, l) print("{0:0.8f} {1:0.8f} {2:0.8f} {3:0.8f}".format(p2.x, p2.y, p3.x, p3.y)) x, y, r = [int(i) for i in input().split()] c = Circle(Point(x, y), r) n = int(input()) read_and_print_results(n, c)
Cross Points of a Circe and a Line For given a circle $c$ and a line $l$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input\n\n \n \n 2 1 1\n 2\n 0 1 4 1\n 3 0 3 3", "output": ".00000000 1.00000000 3.00000000 1.00000000\n 3.00000000 1.00000000 3.00000000 1.00000000"}]
For each query, print the coordinates of the cross points in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s424740952
Accepted
p02308
The input is given in the following format. $cx\; cy\; r$ $q$ $Line_1$ $Line_2$ : $Line_q$ In the first line, the center coordinate of the circle and its radius are given by $cx$, $cy$ and $r$. In the second line, the number of queries $q$ is given. In the following $q$ lines, as queries, $Line_i$ are given ($1 \leq i \leq q$) in the following format. $x_1\; y_1\; x_2\; y_2$ Each line is represented by two points $p1$ and $p2$ which the line crosses. The coordinate of $p1$ and $p2$ are given by ($x1$, $y1$) and ($x2$, $y2$) respectively. All input values are given in integers.
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) INF = float("inf") class Geometry: EPS = 10**-9 def add(self, a, b): x1, y1 = a x2, y2 = b return (x1 + x2, y1 + y2) def sub(self, a, b): x1, y1 = a x2, y2 = b return (x1 - x2, y1 - y2) def mul(self, a, b): x1, y1 = a if not isinstance(b, tuple): return (x1 * b, y1 * b) x2, y2 = b return (x1 * x2, y1 * y2) def div(self, a, b): x1, y1 = a if not isinstance(b, tuple): return (x1 / b, y1 / b) x2, y2 = b return (x1 / x2, y1 / y2) def abs(self, a): from math import hypot x1, y1 = a return hypot(x1, y1) def norm(self, a): x, y = a return x**2 + y**2 def dot(self, a, b): x1, y1 = a x2, y2 = b return x1 * x2 + y1 * y2 def cross(self, a, b): x1, y1 = a x2, y2 = b return x1 * y2 - y1 * x2 def project(self, seg, p): """線分segに対する点pの射影""" p1, p2 = seg base = self.sub(p2, p1) r = self.dot(self.sub(p, p1), base) / self.norm(base) return self.add(p1, self.mul(base, r)) def reflect(self, seg, p): """線分segを対称軸とした点pの線対称の点""" return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2)) def ccw(self, p0, p1, p2): """線分p0,p1から線分p0,p2への回転方向""" a = self.sub(p1, p0) b = self.sub(p2, p0) # 反時計回り if self.cross(a, b) > self.EPS: return 1 # 時計回り if self.cross(a, b) < -self.EPS: return -1 # 直線上(p2 => p0 => p1) if self.dot(a, b) < -self.EPS: return 2 # 直線上(p0 => p1 => p2) if self.norm(a) < self.norm(b): return -2 # 直線上(p0 => p2 => p1) return 0 def intersect(self, seg1, seg2): """線分seg1と線分seg2の交差判定""" p1, p2 = seg1 p3, p4 = seg2 return ( self.ccw(p1, p2, p3) * self.ccw(p1, p2, p4) <= 0 and self.ccw(p3, p4, p1) * self.ccw(p3, p4, p2) <= 0 ) def get_distance_LP(self, line, p): """直線lineと点pの距離""" p1, p2 = line return abs( self.cross(self.sub(p2, p1), self.sub(p, p1)) / self.abs(self.sub(p2, p1)) ) def get_distance_SP(self, seg, p): """線分segと点pの距離""" p1, p2 = seg if self.dot(self.sub(p2, p1), self.sub(p, p1)) < 0: return self.abs(self.sub(p, p1)) if self.dot(self.sub(p1, p2), self.sub(p, p2)) < 0: return self.abs(self.sub(p, p2)) return self.get_distance_LP(seg, p) def get_distance_SS(self, seg1, seg2): """線分seg1と線分seg2の距離""" p1, p2 = seg1 p3, p4 = seg2 if self.intersect(seg1, seg2): return 0 return min( self.get_distance_SP(seg1, p3), self.get_distance_SP(seg1, p4), self.get_distance_SP(seg2, p1), self.get_distance_SP(seg2, p2), ) def get_cross_pointSS(self, seg1, seg2): """線分seg1と線分seg2の交点""" p1, p2 = seg1 p3, p4 = seg2 base = self.sub(p4, p3) dist1 = abs(self.cross(base, self.sub(p1, p3))) dist2 = abs(self.cross(base, self.sub(p2, p3))) t = dist1 / (dist1 + dist2) return self.add(p1, self.mul(self.sub(p2, p1), t)) def get_cross_pointCL(self, c, line): """円cと直線lineの交点""" from math import sqrt # if not intersect(c, line): return -1 x, y, r = c p1, p2 = line pr = self.project(line, (x, y)) e = self.div(self.sub(p2, p1), self.abs(self.sub(p2, p1))) base = sqrt(r * r - self.norm(self.sub(pr, (x, y)))) return [self.add(pr, self.mul(e, base)), self.sub(pr, self.mul(e, base))] gm = Geometry() x, y, r = MAP() c = (x, y, r) for _ in range(INT()): x1, y1, x2, y2 = MAP() seg = ((x1, y1), (x2, y2)) res = gm.get_cross_pointCL(c, seg) res.sort() # 2次元タプルをsumの第2引数で1次元にする res = sum(res, ()) for i in range(3): print("{:.10f}".format(res[i]), end=" ") print("{:.10f}".format(res[-1]))
Cross Points of a Circe and a Line For given a circle $c$ and a line $l$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input\n\n \n \n 2 1 1\n 2\n 0 1 4 1\n 3 0 3 3", "output": ".00000000 1.00000000 3.00000000 1.00000000\n 3.00000000 1.00000000 3.00000000 1.00000000"}]
For each query, print the coordinates of the cross points in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s853399745
Accepted
p02308
The input is given in the following format. $cx\; cy\; r$ $q$ $Line_1$ $Line_2$ : $Line_q$ In the first line, the center coordinate of the circle and its radius are given by $cx$, $cy$ and $r$. In the second line, the number of queries $q$ is given. In the following $q$ lines, as queries, $Line_i$ are given ($1 \leq i \leq q$) in the following format. $x_1\; y_1\; x_2\; y_2$ Each line is represented by two points $p1$ and $p2$ which the line crosses. The coordinate of $p1$ and $p2$ are given by ($x1$, $y1$) and ($x2$, $y2$) respectively. All input values are given in integers.
def dot(c1, c2): return c1.real * c2.real + c1.imag * c2.imag def cross(c1, c2): return c1.real * c2.imag - c1.imag * c2.real def project(p1, p2, p3): # p1 and p2 is are points on the line. # return the projection point x of p3 onto the line. base = p2 - p1 return p1 + base * dot(p3 - p1, base) / (abs(base) ** 2) def print_cross_point(c, r, p1, p2): # c is the center of the circle and r is the radius of the circle. # p1 and p2 are are points on the line. pr = project(p1, p2, c) l = p2 - p1 e = l / abs(l) base = (r**2 - abs(pr - c) ** 2) ** 0.5 c_p1 = pr - e * base c_p2 = pr + e * base print( "{0:.10f} {1:.10f} {2:.10f} {3:.10f}".format( c_p1.real, c_p1.imag, c_p2.real, c_p2.imag ) ) import sys file_input = sys.stdin cx, cy, r = map(int, file_input.readline().split()) c = cx + cy * 1j q = file_input.readline() for line in file_input: x1, y1, x2, y2 = map(int, line.split()) p1 = x1 + y1 * 1j p2 = x2 + y2 * 1j if x1 < x2: print_cross_point(c, r, p1, p2) elif x1 > x2 or y1 > y2: print_cross_point(c, r, p2, p1) else: print_cross_point(c, r, p1, p2)
Cross Points of a Circe and a Line For given a circle $c$ and a line $l$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input\n\n \n \n 2 1 1\n 2\n 0 1 4 1\n 3 0 3 3", "output": ".00000000 1.00000000 3.00000000 1.00000000\n 3.00000000 1.00000000 3.00000000 1.00000000"}]
For each query, print the coordinates of the cross points in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s944030045
Wrong Answer
p02308
The input is given in the following format. $cx\; cy\; r$ $q$ $Line_1$ $Line_2$ : $Line_q$ In the first line, the center coordinate of the circle and its radius are given by $cx$, $cy$ and $r$. In the second line, the number of queries $q$ is given. In the following $q$ lines, as queries, $Line_i$ are given ($1 \leq i \leq q$) in the following format. $x_1\; y_1\; x_2\; y_2$ Each line is represented by two points $p1$ and $p2$ which the line crosses. The coordinate of $p1$ and $p2$ are given by ($x1$, $y1$) and ($x2$, $y2$) respectively. All input values are given in integers.
def solve_eq(a, b, c): return (-b - (b**2 - 4 * a * c) ** 0.5) / 2 * a, ( -b + (b**2 - 4 * a * c) ** 0.5 ) / 2 * a def ret_line(x1, y1, x2, y2): k = (y1 - y2) / (x1 - x2) d = y1 - k * x1 return k, d x, y, r = map(float, input().split()) q = int(input()) x1, y1, x2, y2 = [], [], [], [] for i in range(q): arr = list(map(float, input().split())) x1.append(arr[0]) y1.append(arr[1]) x2.append(arr[2]) y2.append(arr[3]) for i in range(q): if x1[i] != x2[i]: k, d = ret_line(x1[i], y1[i], x2[i], y2[i]) p1, p2 = solve_eq( 1 + k**2, 2 * k * d - 2 * k * x - 2 * x, x**2 + y**2 + d**2 - 2 * y * d - r**2, ) print(p1, k * p1 + d, p2, k * p2 + d) if x1[i] == x2[i]: p1, p2 = solve_eq(1, -2 * y, y**2 + (x1[i] - x) ** 2 - r**2) print(x1[i], p1, x1[i], p2)
Cross Points of a Circe and a Line For given a circle $c$ and a line $l$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input\n\n \n \n 2 1 1\n 2\n 0 1 4 1\n 3 0 3 3", "output": ".00000000 1.00000000 3.00000000 1.00000000\n 3.00000000 1.00000000 3.00000000 1.00000000"}]
Print the number of possible sets of robots remaining on the number line, modulo 998244353. * * *
s623566685
Accepted
p02758
Input is given from Standard Input in the following format: N X_1 D_1 : X_N D_N
import bisect LI = lambda: list(map(int, input().split())) N = int(input()) XD = [LI() for _ in range(N)] MOD = 998244353 class BIT: def __init__(self, n): self.n = n self.dat = [i - 1 for i in range(self.n + 1)] def change(self, i, x): i += 1 while i <= self.n: self.dat[i] = max(self.dat[i], x) i += i & -i def max_num(self, i): if i == 0: return -1 return max(self.dat[i], self.max_num(i - (i & -i))) def main(): XD.sort() x = [None] * N d = [None] * N for i in range(N): x[i], d[i] = XD[i] bit = BIT(N) w = [None] * N for i in range(N - 1, -1, -1): v = x[i] + d[i] j = bit.max_num(bisect.bisect_left(x, v)) w[i] = j - i bit.change(i, j) dp = [None] * (N + 1) dp[-1] = 1 for i in range(N - 1, -1, -1): dp[i] = (dp[i + 1] + dp[i + w[i] + 1]) % MOD ans = dp[0] print(ans) if __name__ == "__main__": main()
Statement There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.
[{"input": "2\n 1 5\n 3 3", "output": "3\n \n\nThere are three possible sets of robots remaining on the number line: \\\\{1,\n2\\\\}, \\\\{1\\\\}, and \\\\{\\\\}.\n\nThese can be achieved as follows:\n\n * If Takahashi activates nothing, the robots \\\\{1, 2\\\\} will remain.\n\n * If Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.\n\n * If Takahashi activates Robot 2 and finishes doing the operation, the robot \\\\{1\\\\} will remain.\n\n* * *"}, {"input": "3\n 6 5\n -1 10\n 3 3", "output": "5\n \n\nThere are five possible sets of robots remaining on the number line: \\\\{1, 2,\n3\\\\}, \\\\{1, 2\\\\}, \\\\{2\\\\}, \\\\{2, 3\\\\}, and \\\\{\\\\}.\n\n* * *"}, {"input": "4\n 7 10\n -10 3\n 4 3\n -4 3", "output": "16\n \n\nNone of the robots influences others.\n\n* * *"}, {"input": "20\n -8 1\n 26 4\n 0 5\n 9 1\n 19 4\n 22 20\n 28 27\n 11 8\n -3 20\n -25 17\n 10 4\n -18 27\n 24 28\n -11 19\n 2 27\n -2 18\n -1 12\n -24 29\n 31 29\n 29 7", "output": "110\n \n\nRemember to print the count modulo 998244353."}]
Print the number of possible sets of robots remaining on the number line, modulo 998244353. * * *
s120119402
Accepted
p02758
Input is given from Standard Input in the following format: N X_1 D_1 : X_N D_N
import sys sys.setrecursionlimit(10**6) from operator import itemgetter import bisect def main(): input = sys.stdin.readline N = int(input()) XD = [tuple(map(int, input().split())) for _ in range(N)] MOD = 998244353 XD.sort(key=itemgetter(0)) X = [xd[0] for xd in XD] segtree = SegmentTree(N + 1) for i in range(N - 1, -1, -1): x, d = XD[i] j = bisect.bisect_left(X, x + d, i) end = max(j - 1, segtree.query(i, j)) segtree.update(i, end) dp = [None] * (N + 1) dp[N] = Mint(1, MOD) for i in range(N - 1, -1, -1): dp[i] = dp[i + 1] + dp[segtree.get(i) + 1] print(dp[0]) class Mint: def __init__(self, value=0, mod=10**9 + 7): self.value = ((value % mod) + mod) % mod self.mod = mod @staticmethod def get_value(x): return x.value if isinstance(x, Mint) else x def inverse(self): a, b = self.value, self.mod u, v = 1, 0 while b: t = a // b b, a = a - t * b, b v, u = u - t * v, v return (u + self.mod) % self.mod def __repr__(self): return str(self.value) def __eq__(self, other): return self.value == other.val def __neg__(self): return Mint(-self.value, self.mod) def __hash__(self): return hash(self.value) def __bool__(self): return self.value != 0 def __iadd__(self, other): self.value = (self.value + Mint.get_value(other)) % self.mod return self def __add__(self, other): new_obj = Mint(self.value, self.mod) new_obj += other return new_obj __radd__ = __add__ def __isub__(self, other): self.value = (self.value - Mint.get_value(other) + self.mod) % self.mod return self def __sub__(self, other): new_obj = Mint(self.value, self.mod) new_obj -= other return new_obj def __rsub__(self, other): new_obj = Mint(Mint.get_value(other), self.mod) new_obj -= self return new_obj def __imul__(self, other): self.value = self.value * Mint.get_value(other) % self.mod return self def __mul__(self, other): new_obj = Mint(self.value, self.mod) new_obj *= other return new_obj __rmul__ = __mul__ def __ifloordiv__(self, other): other = other if isinstance(other, Mint) else Mint(other, self.mod) self *= other.inverse return self def __floordiv__(self, other): new_obj = Mint(self.value, self.mod) new_obj //= other return new_obj def __rfloordiv__(self, other): new_obj = Mint(Mint.get_value(other), self.mod) new_obj //= self return new_obj class SegmentTree: def __init__(self, n=None, f=max, identity_factory=int, initial_values=None): assert n or initial_values size = n if n else len(initial_values) d = [identity_factory() for _ in range(2 * size + 1)] self.__n, self.__d, self.__f, self.__e = size, d, f, identity_factory if initial_values: for i, v in enumerate(initial_values): d[size + i] = v for i in range(size - 1, 0, -1): d[i] = f(d[i << 1], d[i << 1 | 1]) def get(self, index): return self.__d[index + self.__n] def update(self, index, value): i, d, f = index + self.__n, self.__d, self.__f if d[i] == value: return d[i] = value while i: i = i >> 1 d[i] = f(d[i << 1], d[i << 1 | 1]) def add(self, index, value): self.update(index, self.__f(self.__d[index + self.__n], value)) def query(self, from_inclusive, to_exclusive): ans = self.__e() if to_exclusive <= from_inclusive: return ans l, r, d, f = ( from_inclusive + self.__n, to_exclusive + self.__n, self.__d, self.__f, ) while l < r: if l & 1: ans, l = f(ans, d[l]), l + 1 if r & 1: ans, r = f(d[r - 1], ans), r - 1 l, r = l >> 1, r >> 1 return ans def bisect_left(self, func): """func()がFalseになるもっとも左のindexを探す""" i, n, f, d, v = 1, self.__n, self.__f, self.__d, self.__e() while i < n: if func(f(v, d[i << 1])): v, i = f(v, d[i << 1]), i << 1 | 1 else: i = i << 1 return i - n if __name__ == "__main__": main()
Statement There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.
[{"input": "2\n 1 5\n 3 3", "output": "3\n \n\nThere are three possible sets of robots remaining on the number line: \\\\{1,\n2\\\\}, \\\\{1\\\\}, and \\\\{\\\\}.\n\nThese can be achieved as follows:\n\n * If Takahashi activates nothing, the robots \\\\{1, 2\\\\} will remain.\n\n * If Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.\n\n * If Takahashi activates Robot 2 and finishes doing the operation, the robot \\\\{1\\\\} will remain.\n\n* * *"}, {"input": "3\n 6 5\n -1 10\n 3 3", "output": "5\n \n\nThere are five possible sets of robots remaining on the number line: \\\\{1, 2,\n3\\\\}, \\\\{1, 2\\\\}, \\\\{2\\\\}, \\\\{2, 3\\\\}, and \\\\{\\\\}.\n\n* * *"}, {"input": "4\n 7 10\n -10 3\n 4 3\n -4 3", "output": "16\n \n\nNone of the robots influences others.\n\n* * *"}, {"input": "20\n -8 1\n 26 4\n 0 5\n 9 1\n 19 4\n 22 20\n 28 27\n 11 8\n -3 20\n -25 17\n 10 4\n -18 27\n 24 28\n -11 19\n 2 27\n -2 18\n -1 12\n -24 29\n 31 29\n 29 7", "output": "110\n \n\nRemember to print the count modulo 998244353."}]
Print the number of possible sets of robots remaining on the number line, modulo 998244353. * * *
s522897138
Accepted
p02758
Input is given from Standard Input in the following format: N X_1 D_1 : X_N D_N
import sys from bisect import bisect_left from operator import itemgetter class SegTreeMax: """ 以下のクエリを処理する 1.update: i番目の値をxに更新する 2.get_min: 区間[l, r)の最小値を得る """ def __init__(self, n, INF): """ :param n: 要素数 :param INF: 初期値(入りうる要素より十分に大きな数) """ n2 = 1 << (n - 1).bit_length() self.offset = n2 self.tree = [INF] * (n2 << 1) self.INF = INF def initialize(self, arr): for i, v in enumerate(arr, start=self.offset): self.tree[i] = v for i in range(self.offset - 1, 0, -1): j = i << 1 self.tree[i] = max(self.tree[j], self.tree[j + 1]) def update(self, i, x): """ i番目の値をxに更新 :param i: index(0-indexed) :param x: update value """ i += self.offset self.tree[i] = x while i > 1: y = self.tree[i ^ 1] if y >= x: break i >>= 1 self.tree[i] = x def get_max(self, a, b): """ [a, b)の最大値を得る :param a: index(0-indexed) :param b: index(0-indexed) """ result = self.INF l = a + self.offset r = b + self.offset while l < r: if r & 1: result = max(result, self.tree[r - 1]) if l & 1: result = max(result, self.tree[l]) l += 1 l >>= 1 r >>= 1 return result n, *xd = map(int, sys.stdin.buffer.read().split()) MOD = 998244353 xd = sorted(zip(xd[0::2], xd[1::2])) xxx = list(map(itemgetter(0), xd)) ans = [0] * (n + 1) skip = list(range(1, n + 1)) ans[n] = 1 sgt = SegTreeMax(n + 1, 0) sgt.initialize(list(range(1, n + 2))) for i in range(n - 1, -1, -1): x, d = xd[i] r = x + d j = bisect_left(xxx, r) k = sgt.get_max(i, j) ans[i] = (ans[i + 1] + ans[k]) % MOD sgt.update(i, k) print(ans[0])
Statement There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.
[{"input": "2\n 1 5\n 3 3", "output": "3\n \n\nThere are three possible sets of robots remaining on the number line: \\\\{1,\n2\\\\}, \\\\{1\\\\}, and \\\\{\\\\}.\n\nThese can be achieved as follows:\n\n * If Takahashi activates nothing, the robots \\\\{1, 2\\\\} will remain.\n\n * If Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.\n\n * If Takahashi activates Robot 2 and finishes doing the operation, the robot \\\\{1\\\\} will remain.\n\n* * *"}, {"input": "3\n 6 5\n -1 10\n 3 3", "output": "5\n \n\nThere are five possible sets of robots remaining on the number line: \\\\{1, 2,\n3\\\\}, \\\\{1, 2\\\\}, \\\\{2\\\\}, \\\\{2, 3\\\\}, and \\\\{\\\\}.\n\n* * *"}, {"input": "4\n 7 10\n -10 3\n 4 3\n -4 3", "output": "16\n \n\nNone of the robots influences others.\n\n* * *"}, {"input": "20\n -8 1\n 26 4\n 0 5\n 9 1\n 19 4\n 22 20\n 28 27\n 11 8\n -3 20\n -25 17\n 10 4\n -18 27\n 24 28\n -11 19\n 2 27\n -2 18\n -1 12\n -24 29\n 31 29\n 29 7", "output": "110\n \n\nRemember to print the count modulo 998244353."}]
Print the number of possible sets of robots remaining on the number line, modulo 998244353. * * *
s566511827
Accepted
p02758
Input is given from Standard Input in the following format: N X_1 D_1 : X_N D_N
import sys sys.setrecursionlimit(2147483647) INF = 1 << 60 MOD = 998244353 input = lambda: sys.stdin.readline().rstrip() class SegmentTree(object): def __init__(self, A, dot, unit): n = 1 << (len(A) - 1).bit_length() tree = [unit] * (2 * n) for i, v in enumerate(A): tree[i + n] = v for i in range(n - 1, 0, -1): tree[i] = dot(tree[i << 1], tree[i << 1 | 1]) self._n = n self._tree = tree self._dot = dot self._unit = unit def __getitem__(self, i): return self._tree[i + self._n] def update(self, i, v): i += self._n self._tree[i] = v while i != 1: i >>= 1 self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1]) def add(self, i, v): self.update(i, self[i] + v) def sum(self, l, r): l += self._n r += self._n l_val = r_val = self._unit while l < r: if l & 1: l_val = self._dot(l_val, self._tree[l]) l += 1 if r & 1: r -= 1 r_val = self._dot(self._tree[r], r_val) l >>= 1 r >>= 1 return self._dot(l_val, r_val) from bisect import bisect_left def resolve(): n = int(input()) XD = [tuple(map(int, input().split())) for _ in range(n)] XD.sort() X = [xd[0] for xd in XD] tree = SegmentTree([-INF] * n, max, -INF) for i in range(n - 1, -1, -1): x, d = XD[i] j = bisect_left(X, x + d) tree.update(i, max(j, tree.sum(i + 1, j))) dp = [0] * (n + 1) dp[n] = 1 for i in range(n - 1, -1, -1): dp[i] += dp[i + 1] dp[i] += dp[tree[i]] dp[i] %= MOD print(dp[0]) resolve()
Statement There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.
[{"input": "2\n 1 5\n 3 3", "output": "3\n \n\nThere are three possible sets of robots remaining on the number line: \\\\{1,\n2\\\\}, \\\\{1\\\\}, and \\\\{\\\\}.\n\nThese can be achieved as follows:\n\n * If Takahashi activates nothing, the robots \\\\{1, 2\\\\} will remain.\n\n * If Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.\n\n * If Takahashi activates Robot 2 and finishes doing the operation, the robot \\\\{1\\\\} will remain.\n\n* * *"}, {"input": "3\n 6 5\n -1 10\n 3 3", "output": "5\n \n\nThere are five possible sets of robots remaining on the number line: \\\\{1, 2,\n3\\\\}, \\\\{1, 2\\\\}, \\\\{2\\\\}, \\\\{2, 3\\\\}, and \\\\{\\\\}.\n\n* * *"}, {"input": "4\n 7 10\n -10 3\n 4 3\n -4 3", "output": "16\n \n\nNone of the robots influences others.\n\n* * *"}, {"input": "20\n -8 1\n 26 4\n 0 5\n 9 1\n 19 4\n 22 20\n 28 27\n 11 8\n -3 20\n -25 17\n 10 4\n -18 27\n 24 28\n -11 19\n 2 27\n -2 18\n -1 12\n -24 29\n 31 29\n 29 7", "output": "110\n \n\nRemember to print the count modulo 998244353."}]
Print the number of possible sets of robots remaining on the number line, modulo 998244353. * * *
s687449976
Wrong Answer
p02758
Input is given from Standard Input in the following format: N X_1 D_1 : X_N D_N
import sys from bisect import bisect_right input = sys.stdin.readline ide = -1 def func(a, b): return max(a, b) class SegmentTree: def __init__(self, ls, commutative=True): if commutative == True: self.n = len(ls) self.tree = [ide for i in range(self.n)] + ls else: self.n = 2 ** ((len(ls) - 1).bit_length()) self.tree = ( [ide for i in range(self.n)] + ls + [ide for i in range(self.n - len(ls))] ) for i in range(1, self.n)[::-1]: self.tree[i] = func(self.tree[i << 1 | 0], self.tree[i << 1 | 1]) def getall(self): return self.tree[1] def get(self, l, r): ret = ide l += self.n r += self.n while l < r: if l & 1: ret = func(self.tree[l], ret) l += 1 if r & 1: ret = func(ret, self.tree[r - 1]) l >>= 1 r >>= 1 return ret def update(self, i, x): i += self.n self.tree[i] = x while i > 1: i >>= 1 self.tree[i] = func(self.tree[i << 1 | 0], self.tree[i << 1 | 1]) n = int(input()) xd = [list(map(int, input().split())) for i in range(n)] mod = 998244353 xd.sort() go = [[] for i in range(n + 1)] come = [-1 for i in range(n + 1)] deg = [0] * (n + 1) move = [-1] * n xdsum = [(sum(xd[i]), i) for i in range(n)] xdsum.sort() xdsump, xdsumi = list(zip(*xdsum)) xdsumi = list(xdsumi) xdsumii = [0] * n for i in range(n): t = xdsumi[i] xdsumii[t] = i sol = SegmentTree(xdsumi) for i in range(n - 1, -1, -1): rng = bisect_right(xdsump, xd[i][0]) sol.update(xdsumii[i], -1) move[i] = sol.get(rng, n - 1) + 1 if not move[i]: move[i] = -1 for i in range(n): if move[i] == -1: continue come[i + 1] = move[i] go[move[i]].append(i + 1) deg[move[i]] += 1 leafls = [] ans = 1 dp = [1] * (n + 1) for i in range(1, n + 1): if not go[i]: leafls.append(i) dp[i] = 2 while leafls: x = leafls.pop() if come[x] == -1: ans = ans * dp[x] % mod continue y = come[x] if deg[y] >= 1: deg[y] -= 1 dp[y] = dp[y] * dp[x] % mod if deg[y] == 0: dp[y] += 1 leafls.append(y) print(ans)
Statement There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a mischievous boy, can do the following operation any number of times (possibly zero) as long as there is a robot remaining on the number line. * Choose a robot and activate it. This operation cannot be done when there is a robot moving. While Robot i is moving, if it touches another robot j that is remaining in the range [X_i, X_i + D_i) on the number line, Robot j also gets activated and starts moving. This process is repeated recursively. How many possible sets of robots remaining on the number line are there after Takahashi does the operation some number of times? Compute this count modulo 998244353, since it can be enormous.
[{"input": "2\n 1 5\n 3 3", "output": "3\n \n\nThere are three possible sets of robots remaining on the number line: \\\\{1,\n2\\\\}, \\\\{1\\\\}, and \\\\{\\\\}.\n\nThese can be achieved as follows:\n\n * If Takahashi activates nothing, the robots \\\\{1, 2\\\\} will remain.\n\n * If Takahashi activates Robot 1, it will activate Robot 2 while moving, after which there will be no robots on the number line. This state can also be reached by activating Robot 2 and then Robot 1.\n\n * If Takahashi activates Robot 2 and finishes doing the operation, the robot \\\\{1\\\\} will remain.\n\n* * *"}, {"input": "3\n 6 5\n -1 10\n 3 3", "output": "5\n \n\nThere are five possible sets of robots remaining on the number line: \\\\{1, 2,\n3\\\\}, \\\\{1, 2\\\\}, \\\\{2\\\\}, \\\\{2, 3\\\\}, and \\\\{\\\\}.\n\n* * *"}, {"input": "4\n 7 10\n -10 3\n 4 3\n -4 3", "output": "16\n \n\nNone of the robots influences others.\n\n* * *"}, {"input": "20\n -8 1\n 26 4\n 0 5\n 9 1\n 19 4\n 22 20\n 28 27\n 11 8\n -3 20\n -25 17\n 10 4\n -18 27\n 24 28\n -11 19\n 2 27\n -2 18\n -1 12\n -24 29\n 31 29\n 29 7", "output": "110\n \n\nRemember to print the count modulo 998244353."}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s106513896
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YNEOS"[set(map(int, input().split())) != {1, 7, 9, 4} :: 2])
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s455873171
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
s = {1, 7, 9, 4} t = set(map(int, input().split())) print("YES" if t == s else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s203523332
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
n = set(input().split()) s = set([i for i in "1974"]) print("NO" if n ^ s else "YES")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s231720712
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YNeos"[sorted(input().split()) != ["1", "4", "7", "9"] :: 2])
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s956959915
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if sorted(input()) == "1479" else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s184494810
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YNeos"["".join(sorted(input())) != "1479" :: 2])
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s697792206
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if set(map(int, input().split())) == set(1, 9, 7, 4) else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s558628237
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YNeos"["".join(sorted(input().split())) != "1479" :: 2])
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s083853112
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
var = [int(input()) for _ in range(4)] var.sort() print("Yes" if var == [1, 4, 7, 9] else "No")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s905206247
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
s = list(map(int,input().split())) c = [1,,4,7,9] if s == c: print('YES') else: print('NO')
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s796715728
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
N=input().split() if N.count('1')==1 and N.count('7')==1 and N.count('9')==1 and N.count('4')==1: print('YES') else: print('NO')
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s189723005
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
N=list(input().split()) if N.count('1')==1 and N.count('7')==1 and N.count('9')==1 and N.count('4')==1: print('YES') else: print('NO')
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s108117460
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b # aとbの最大公約数 def gcd(a, b): if b == 0: return a return gcd(b, a % b) # aとbの最小公倍数 def lcm(a, b): g = gcd(a, b) return a / g * b def main(): N = list(sorted(list(map(int, input().split())))) if N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9: print(YES) else: print(NO) if __name__ == "__main__": main()
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s170364848
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
def main(): S = input() ans = "keyence" cnt = 0 j = 0 if S[0] != "k": for i in range(len(S) - 6): if S[i] == ans[j]: while True: j += 1 i += 1 if j == 7: return "YES" elif S[i] != ans[j]: break return "NO" else: i = 0 while True: i += 1 j += 1 if j == 7 and i == len(S): return "YES" elif S[i] != ans[j]: break # print(i,j) # print(S[69]) for k in range(i, len(S) - (7 - j - 1), 1): tmp = j # print(tmp,k,len(S)-j) if S[k] == ans[tmp]: while True: # print(tmp,k) tmp += 1 k += 1 if tmp == 7 and k == len(S): return "YES" elif tmp == 7 and k != len(S): return "NO" elif S[k] != ans[tmp]: break return "No" print(main())
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s940834603
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = set(I()) if N == {1, 7, 9, 4}: print("YES") else: print("NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s595319666
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
import numpy as np N, M = list(map(int, input().split(" "))) A_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1] B_list = np.sort(np.asarray(list(map(int, input().split(" ")))))[::-1] out = 1 a_next_i = 0 b_next_i = 0 for x in range(N * M, 1, -1): cond1 = a_next_i < N and x == A_list[a_next_i] cond2 = b_next_i < M and x == B_list[b_next_i] if cond1 and cond2: kosuu = 1 a_next_i += 1 b_next_i += 1 elif cond1: kosuu = b_next_i a_next_i += 1 elif cond2: kosuu = a_next_i b_next_i += 1 else: kosuu = a_next_i * b_next_i - (N * M - x) out *= kosuu out = out % 1000000007 print(out)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s336444245
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if set(list(map(int, input().split()))) == set([1, 9, 7, 4]) else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s102501009
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
li = sorted(list(map(int, input().split()))) print("YES") if li == [1, 4, 7, 9] else print("NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s426667032
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
N = set(input()) A = set("1974") print(N == A)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s152102058
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
# 問題D M, N = list(map(int, input().split())) ROW = list(map(int, input().split())) COL = list(map(int, input().split())) # M= 3 # N= 3 # ROW = [8,9,7] # COL = [6,9,8] # N,M = 14,13 # ROW = [158, 167, 181, 147, 178, 151, 179, 182, 176, 169, #180, 129, 175, 168] # COL = [181, 150, 178, 179, 167, 180, 176, 169, 182, 177, #175, 159, 173] import numpy as np row = 0 col = 0 nums = np.arange(1, M * N + 1)[::-1] pattern = np.zeros(M * N) ans = 1 # print(nums) for i in nums: if i in ROW and i in COL: row += 1 col += 1 # pattern[i-1] = 1 elif i in ROW and i not in COL: row += 1 # pattern[i-1] = col ans *= col elif i not in ROW and i in COL: col += 1 # pattern[i-1] = row ans *= row elif i not in ROW and i not in COL: # pattern[i-1] = row * col - (M*N-i) ans *= row * col - (M * N - i) if row * col - (M * N - i) <= 0: ans = 0 break ans %= 10**9 + 7 # print(i,row,col,pattern[i-1]) # print(pattern) # ans = int(pattern.prod()) # ans = ans % (10**9+7) print(ans)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s830118633
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
N1, N2, N3, N4 = [int(i) for i in input().split()] if sorted([N1, N2, N3, N4]) == [1, 4, 7, 9]: ans = "YES" else: ans = "NO" print(ans)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s735025991
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
n = list(map(int, input().split())) if 1 in n: if 4 in n: if 7 in n: if 9 in n: print(‘YES’) exit() print(‘NO’)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s790929504
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
import sys s = input() a = 0 b = 0 c = 0 d = 0 e = 0 f = 0 g = 0 while s[a] != "k": a += 1 if a == len(s): print("NO") sys.exit() b = a + 1 while s[b] != "e": b += 1 if b == len(s): print("NO") sys.exit() c = b + 1 while s[c] != "y": c += 1 if c == len(s): print("NO") sys.exit() d = c + 1 while s[d] != "e": d += 1 if d == len(s): print("NO") sys.exit() e = d + 1 while s[e] != "n": e += 1 if e == len(s): print("NO") sys.exit() f = e + 1 while s[f] != "c": f += 1 if f == len(s): print("NO") sys.exit() g = f + 1 while s[g] != "e": g += 1 if not "e" in s[g]: print("NO") sys.exit() if s == "keyence": print("YES") else: if a != 0 and ( b == a + 1 and c == b + 1 and d == c + 1 and e == d + 1 and f == e + 1 and g == f + 1 ): print("YES") elif ( a == 0 and b != 1 and (c == b + 1 and d == c + 1 and e == d + 1 and f == e + 1 and g == f + 1) ): print("YES") elif ( a == 0 and b == 1 and c != 2 and (d == c + 1 and e == d + 1 and f == e + 1 and g == f + 1) ): print("YES") elif ( a == 0 and b == 1 and c == 2 and d != 3 and (e == d + 1 and f == e + 1 and g == f + 1) ): print("YES") elif ( a == 0 and b == 1 and c == 2 and d == 3 and e != 4 and (f == e + 1 and g == f + 1) ): print("YES") elif a == 0 and b == 1 and c == 2 and d == 3 and e == 4 and f != 5 and g == f + 1: print("YES") elif a == 0 and b == 1 and c == 2 and d == 3 and e == 4 and f == 5 and g != 6: print("YES") else: print("NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s616508964
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if "".join(sorted(input().strip().split(" "))) == "1479" else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s623046352
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if set(map(int, input().split())) == {1, 9, 7, 4} else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s173622355
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if sorted(input().split()) == ["1", "4", "7", "9"] else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s045803074
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
N = set(input().split()) print("YES" if N == {"1", "9", "7", "4"} else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s625892187
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
N = sorted(list(map(str, input().split()))) print("YES" if "".join(N) == "1479" else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s534371217
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if set(input().split()) == set(list("1974")) else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s650091934
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if sorted(input().split()) == list("1479") else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s813925670
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
a = set([int(x) for x in input().split()]) print("YES" if a == set([1, 9, 7, 4]) else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s466862168
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
s = "".join(sorted(input().split())) print(["NO", "YES"][s == "1479"])
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s274189841
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
ans = "YES" if set(input().split()) == set("1974") else "NO" print(ans)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s568007687
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
A = set(list(map(int, input().split()))) print("YES" if A == set(list(1, 9, 7, 4)) else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s928378301
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YNeos"["".join(sorted(list(input()))) != "1479" :: 2])
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s192261955
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
n=sorted(list(map(int,input().split()))) if n=[1,4,7,9]: print("YES") else: print("NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s325032875
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
if set(input().split())==set([1,9,7,4]): print("Yes") else: print("No")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s908381161
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
n = list(input()) print("YES" if "1" and "9" and "7" and "4" in n else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s255683050
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YES" if input().split().sort() == ["1", "4", "7", "9"] else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s180005961
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
print("YNEOS"[sorted(input()) != list(" 1479")])
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s631412372
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
N = set(input()) A = set('1974') print('YES if N==A else 'NO')
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s267745963
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
x = input() print(x)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s304003551
Wrong Answer
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
str_input = input() print(str_input)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s423288945
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
while True: try: n = input().split() print("YES" if "1" in n and "9" in n and "7" in n and "4" in n else "NO") except EOFError: exit()
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s267970748
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
arr = list(map(int, input().split())) ok = 0 if 9 in arr: ok += 1 if 1 in arr: ok += 1 if 7 in arr: ok += 1 if 4 in arr: ok += 1 print("YES" if ok == 4 else "NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s207245047
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
def main(); nums = sys.stdin.readline().split() numset = set(nums) if numset == {1, 4, 7, 9}: return "YES" else: return "NO"
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s183320657
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
def main(); nums = sys.stdin.readline().split() nums.sort() if list(nums) == [1, 4, 7, 9]: return "YES" else: return "NO"
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s082626288
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
nums = list(map(int,input().split())) flag1 = 1 in nums and 9 in nums and 7 in nums and 4 in nums if flag1 == True: print(“YES”) else: print(“NO”)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s556238327
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
import re a = input() if re.match('(.*)keyence', a): print("YES") else: if re.match('k(.*)eyence', a) print("YES") else: print("NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s098432451
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
def main(); nums = sys.stdin.readline().split() nums.sort() if nums == [1, 4, 7, 9]: return "YES" else: return "NO"
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s652105561
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
i = set(map(str, input().split())) if ( '1' in i and '9' in i and '7' in i and '4' in i ): print ('YES') else: print ('NO')
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s684505285
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
get=input() get = get.split(" ") flg=0 get=list(set(get)) for a in : if int(a) in[1,9,7,4]: flg+=1 if flg==4: print("YES") else: print("NO")
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s373734047
Runtime Error
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
n = map(int, input().split()) if 1 in n: if 4 in n: if 7 in n: if 9 in n: print(‘YES’) exit() print(‘NO’)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`. * * *
s243140040
Accepted
p03149
Input is given from Standard Input in the following format: N_1 N_2 N_3 N_4
n, a, b, c = map(int, input().split()) ans = "NO" if n == 1 or a == 1 or b == 1 or c == 1: if n == 9 or a == 9 or b == 9 or c == 9: if n == 7 or a == 7 or b == 7 or c == 7: if n == 4 or a == 4 or b == 4 or c == 4: ans = "YES" print(ans)
Statement You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
[{"input": "1 7 9 4", "output": "YES\n \n\nWe can get 1974 by swapping N_2 and N_3.\n\n* * *"}, {"input": "1 9 7 4", "output": "YES\n \n\nWe already have 1974 before doing anything.\n\n* * *"}, {"input": "1 2 9 1", "output": "NO\n \n\n* * *"}, {"input": "4 9 0 8", "output": "NO"}]