output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s993948380 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | N = int(input())
L = input().split(' ')
for i in L:
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s887744334 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | 5
100 1 2 3 14 15 58 58 58 29
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s373179733 | Wrong Answer | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | def count_servings(inp):
print("Smth")
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s008080090 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n=int(input())
l=sorted(list(map(int,iput().split()),reverse=True)
print(sum(l[1::2]) | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s493625966 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n=int(input());print(sum(sorted(list(map(int,input().split())))[::2]))
print("RE WA?" | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s638403161 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n= int(input())
x= list(map(int, input().split()))
x.sort()
ans = 0
for i range(n):
ans = ans + x[i*2]
print(ans)
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s320410504 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n = int(input())
s = list(map(int,input().split()))
s.sort()
sum = 0
for i in range(0,2n,2):
sum += s[i]
print(sum) | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s297416464 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | N = int(input())
L = list(map(int,input().split())
L.sort()
s = 0
for n in range(N):
s += L[2*n]
print(s) | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s739326319 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n=int(input())
x=list(map(int, input().split()))
x.sort()
ans=0
for i range(n):
ans=ans+x[i*2]
print(ans)
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s036529572 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | N = input()
Li = map(int, input().split(" "))
Li.sort()
total = 0
for i in Li[0::2]
total += i
print(total)
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s602627412 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | N = input()
L = list(map(int,input().split())
L.sort()
s = 0
for n in range(N):
s += L[2*n]
print(s) | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s617248161 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | #-*- coding: utf-8 -*-
N = int(input())
L_list = [int(input()) for n in range(2N)]
L_list.sort()
print(sum(L_list[1::2])) | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s568274783 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n = int(input())
a = []
cou = 0
for i in range(n * 2):
a[i] = int(input())
a.sort()
for i * 2 in range(n):
cou += min(a[i], a[i + 1])
print(cou)
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s028269684 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n=int(input())
x=list(map(int,input().split()))
x.sort()
ans=0
for i range(n):
if i%2==1:
pass
else:
ans+=min(x[i],x[i+1])
print(ans) | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s627175179 | Accepted | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | import math
def getInt():
return int(input())
def getIntList():
return [int(x) for x in input().split()]
def zeros(n):
return [0] * n
def zeros2(n, m):
return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替
class Debug:
def __init__(self):
self.debug = True
def off(self):
self.debug = False
def dmp(self, x, cmt=""):
if self.debug:
if cmt != "":
w = cmt + ": " + str(x)
else:
w = str(x)
print(w)
return x
def prob(): # WA 2
d = Debug()
d.off()
N = getInt()
d.dmp((N), "N")
L = getIntList()
d.dmp((L), "L")
L.sort()
count = 0
for i in range(N):
count += min(L[i * 2], L[i * 2 + 1])
return count
ans = prob()
print(ans)
| Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the maximum total number of ingredients that Snuke's N servings of
Skewer Meal can hold.
* * * | s874033754 | Runtime Error | p04047 | The input is given from Standard Input in the following format:
N
L_1 L_2 ... L_{2N} | n = int(input())
table = list(map(int,input().split()))
table.sort()
count = 0
for i in range(n):
if i%2 = 0:
count += table[i]
else:
pass
print(count) | Statement
Snuke is having a barbeque party.
At the party, he will make N servings of _Skewer Meal_.

Example of a serving of Skewer Meal
He has a stock of 2N skewers, all of which will be used in Skewer Meal. The
length of the i-th skewer is L_i. Also, he has an infinite supply of
ingredients.
To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients
onto those skewers. Let the length of the shorter skewer be x, then the
serving can hold the maximum of x ingredients.
What is the maximum total number of ingredients that his N servings of Skewer
Meal can hold, if he uses the skewers optimally? | [{"input": "2\n 1 3 1 2", "output": "3\n \n\nIf he makes a serving using the first and third skewers, and another using the\nsecond and fourth skewers, each serving will hold 1 and 2 ingredients, for the\ntotal of 3.\n\n* * *"}, {"input": "5\n 100 1 2 3 14 15 58 58 58 29", "output": "135"}] |
Print the number of the unnecessary cards.
* * * | s657958538 | Runtime Error | p03782 | The input is given from Standard Input in the following format:
N K
a_1 a_2 ... a_N | def main():
n,k = map(int,input().split())
a = list(filter(lambda x:x<k,list(map(int,input().split()))))
n = len(a)
a.sort(reverse=True)
ng = -1
ok = n
while ok-ng > 1:
mid = (ok+ng)//2
dp = [False]*(k+1)
dp[0] = True
f = 0
for j in range(n):
if j == mid:
continue
w = a[j]
for i in range(k,w-1,-1):
if dp[i-w]:
dp[i] = True
if k-a[mid] <= i < k:
ng = mid
f = 1
break
if f:
break
else:
ok = mid
print(n-ok)
if __name__ == "__main__":
main()
| Statement
AtCoDeer the deer has N cards with positive integers written on them. The
number on the i-th card (1≤i≤N) is a_i. Because he loves big numbers, he calls
a subset of the cards _good_ when the sum of the numbers written on the cards
in the subset, is K or greater.
Then, for each card i, he judges whether it is _unnecessary_ or not, as
follows:
* If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
* Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card
independently, and he does not throw away cards that turn out to be
unnecessary. | [{"input": "3 6\n 1 4 3", "output": "1\n \n\nThere are two good sets: {2,3} and {1,2,3}.\n\nCard 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is\nalso good. Thus, card 1 is unnecessary.\n\nFor card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is\nNOT unnecessary.\n\nNeither is card 3 for a similar reason, hence the answer is 1.\n\n* * *"}, {"input": "5 400\n 3 1 4 1 5", "output": "5\n \n\nIn this case, there is no good set. Therefore, all the cards are unnecessary.\n\n* * *"}, {"input": "6 20\n 10 4 3 10 25 2", "output": "3"}] |
For each dataset, output _i_ in a line when _v i_ is wrong. | s114056823 | Wrong Answer | p00907 | The input is a sequence of datasets, each representing a calculation result in
the following format.
_d_
_v_ 0
_v_ 1
...
_v_ _d_ +2
Here, _d_ in the first line is a positive integer that represents the degree
of the polynomial, namely, the highest exponent of the variable. For instance,
the degree of 4 _x_ 5 \+ 3 _x_ \+ 0.5 is five and that of 2.4 _x_ \+ 3.8 is
one. _d_ is at most five.
The following _d_ \+ 3 lines contain the calculation result of _f_(0), _f_(1),
... , and _f_(_d_ \+ 2) in this order, where _f_ is the polynomial function.
Each of the lines contains a decimal fraction between -100.0 and 100.0,
exclusive.
You can assume that the wrong value, which is exactly one of _f_(0), _f_(1),
... , and _f_(_d_ +2), has an error greater than 1.0. Since rounding errors
are inevitable, the other values may also have errors but they are small and
never exceed 10-6.
The end of the input is indicated by a line containing a zero. | from functools import reduce
EPSILON = 2e-6
d = 0
Vs = []
times = lambda x, y: x * y
def interpolate(x, e):
return sum(
reduce(times, [(x - j) / (i - j) for j in range(len(Vs)) if j not in [i, x, e]])
* v
for i, v in enumerate(Vs)
if i not in [x, e]
)
def outlier(e):
for i, v in enumerate(Vs):
if i == e:
continue
if abs(interpolate(i, e) - v) < EPSILON:
return False
return True
def solve():
for i in range(d + 3):
if not outlier(i):
return i
return -1
while True:
d = int(input())
if d == 0:
break
Vs = [float(input()) for i in range(d + 3)]
print(solve())
| D: Find the Outlier
Professor Abacus has just built a new computing engine for making numerical
tables. It was designed to calculate the values of a polynomial function in
one variable at several points at a time. With the polynomial function
_f_(_x_) = _x_ 2 \+ 2 _x_ \+ 1, for instance, a possible expected calculation
result is 1 (= _f_(0)), 4 (= _f_(1)), 9 (= _f_(2)), 16 (= _f_(3)), and 25 (=
_f_(4)).
It is a pity, however, the engine seemingly has faulty components and exactly
one value among those calculated simultaneously is always wrong. With the same
polynomial function as above, it can, for instance, output 1, 4, 12, 16, and
25 instead of 1, 4, 9, 16, and 25.
You are requested to help the professor identify the faulty components. As the
first step, you should write a program that scans calculation results of the
engine and finds the wrong values. | [{"input": "1.0\n 4.0\n 12.0\n 16.0\n 25.0\n 1\n -30.5893962764\n 5.76397083962\n 39.3853798058\n 74.3727663177\n 4\n 42.4715310246\n 79.5420238202\n 28.0282396675\n -30.3627807522\n -49.8363481393\n -25.5101480106\n 7.58575761381\n 5\n -21.9161699038\n -48.469304271\n -24.3188578417\n -2.35085940324\n -9.70239202086\n -47.2709510623\n -93.5066246072\n -82.5073836498\n 0", "output": "1\n 1\n 6"}] |
Print the number of such ways to paint the dominoes, modulo 1000000007.
* * * | s544394829 | Accepted | p03628 | Input is given from Standard Input in the following format:
N
S_1
S_2 | from functools import reduce
# 入力
N = int(input())
S1 = input()
S2 = input()
MOD = 1000000007
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
return (
ModInt(self.x + other.x)
if isinstance(other, ModInt)
else ModInt(self.x + other)
)
def __sub__(self, other):
return (
ModInt(self.x - other.x)
if isinstance(other, ModInt)
else ModInt(self.x - other)
)
def __mul__(self, other):
return (
ModInt(self.x * other.x)
if isinstance(other, ModInt)
else ModInt(self.x * other)
)
def __truediv__(self, other):
return (
ModInt(self.x * pow(other.x, MOD - 2, MOD))
if isinstance(other, ModInt)
else ModInt(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
ModInt(pow(self.x, other.x, MOD))
if isinstance(other, ModInt)
else ModInt(pow(self.x, other, MOD))
)
def __radd__(self, other):
return ModInt(other + self.x)
def __rsub__(self, other):
return ModInt(other - self.x)
def __rmul__(self, other):
return ModInt(other * self.x)
def __rtruediv__(self, other):
return ModInt(other * pow(self.x, MOD - 2, MOD))
def __rpow__(self, other):
return ModInt(pow(other, self.x, MOD))
# (1x2)x2 と (2x1) を1ブロックとみなして、色の塗り方の組合せを数え上げる
ans, _ = reduce(
lambda acc, s: (
(3 * acc[0], 3)
if acc[1] == 0 and s[0] == s[1]
else (
(6 * acc[0], 1)
if acc[1] == 0 and s[0] != s[1]
else (
(acc[0], 2)
if acc[1] == 1
else (
(acc[0], 3)
if acc[1] == 2 and s[0] == s[1]
else (
(3 * acc[0], 1)
if acc[1] == 2 and s[0] != s[1]
else (
(2 * acc[0], 3)
if acc[1] == 3 and s[0] == s[1]
else (2 * acc[0], 1)
)
)
)
)
)
),
zip(S1, S2),
(ModInt(1), 0),
)
# 出力
print(ans)
| Statement
We have a board with a 2 \times N grid. Snuke covered the board with N
dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1
square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and
green. Two dominoes that are adjacent by side should be painted by different
colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in
the following manner:
* Each domino is represented by a different English letter (lowercase or uppercase).
* The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left. | [{"input": "3\n aab\n ccb", "output": "6\n \n\nThere are six ways as shown below:\n\n\n\n* * *"}, {"input": "1\n Z\n Z", "output": "3\n \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}] |
Print the number of such ways to paint the dominoes, modulo 1000000007.
* * * | s399037878 | Accepted | p03628 | Input is given from Standard Input in the following format:
N
S_1
S_2 | N = int(input())
S1 = input()
S2 = input()
MOD = 10**9 + 7
class Mint:
def __init__(self, value=0):
self.value = value % MOD
if self.value < 0:
self.value += MOD
@staticmethod
def get_value(x):
return x.value if isinstance(x, Mint) else x
def inverse(self):
a, b = self.value, MOD
u, v = 1, 0
while b:
t = a // b
b, a = a - t * b, b
v, u = u - t * v, v
if u < 0:
u += MOD
return u
def __repr__(self):
return str(self.value)
def __eq__(self, other):
return self.value == other.value
def __neg__(self):
return Mint(-self.value)
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)) % MOD
return self
def __add__(self, other):
new_obj = Mint(self.value)
new_obj += other
return new_obj
__radd__ = __add__
def __isub__(self, other):
self.value = (self.value - Mint.get_value(other)) % MOD
if self.value < 0:
self.value += MOD
return self
def __sub__(self, other):
new_obj = Mint(self.value)
new_obj -= other
return new_obj
def __rsub__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj -= self
return new_obj
def __imul__(self, other):
self.value = self.value * Mint.get_value(other) % MOD
return self
def __mul__(self, other):
new_obj = Mint(self.value)
new_obj *= other
return new_obj
__rmul__ = __mul__
def __ifloordiv__(self, other):
other = other if isinstance(other, Mint) else Mint(other)
self *= other.inverse()
return self
def __floordiv__(self, other):
new_obj = Mint(self.value)
new_obj //= other
return new_obj
def __rfloordiv__(self, other):
new_obj = Mint(Mint.get_value(other))
new_obj //= self
return new_obj
p = []
i = 0
while i < N:
if S1[i] == S2[i]:
p.append(1)
i += 1
else:
p.append(0)
i += 2
ans = Mint(1)
if p[0] == 1:
ans *= 3
else:
ans *= 6
for i in range(1, len(p)):
if p[i] == 0:
if p[i - 1] == 0:
ans *= 3
else:
ans *= 2
else:
if p[i - 1] == 0:
ans *= 1
else:
ans *= 2
print(ans)
| Statement
We have a board with a 2 \times N grid. Snuke covered the board with N
dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1
square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and
green. Two dominoes that are adjacent by side should be painted by different
colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in
the following manner:
* Each domino is represented by a different English letter (lowercase or uppercase).
* The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left. | [{"input": "3\n aab\n ccb", "output": "6\n \n\nThere are six ways as shown below:\n\n\n\n* * *"}, {"input": "1\n Z\n Z", "output": "3\n \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}] |
Print the number of such ways to paint the dominoes, modulo 1000000007.
* * * | s057681967 | Wrong Answer | p03628 | Input is given from Standard Input in the following format:
N
S_1
S_2 | N = int(input())
A = input()
B = input()
def f(horizontal_flag):
if horizontal_flag[0]:
if horizontal_flag[1]:
return 3
else:
return 1
else:
return 2
if N == 1:
print(3)
else:
if A[0] == A[1]:
counter = 6
initial_num = 2
horizontal_flag = [0, 1]
else:
counter = 3
initial_num = 1
horizontal_flag = [0, 1]
for i in range(initial_num, N):
if i == N - 1:
if horizontal_flag[1] == 2:
horizontal_flag[1] = 1
counter *= f(horizontal_flag)
else:
horizontal_flag[1] = 0
counter *= f(horizontal_flag)
elif A[i] == A[i + 1]:
horizontal_flag[1] = 2
else:
if horizontal_flag[1] == 2:
horizontal_flag[1] = 1
counter *= f(horizontal_flag)
else:
horizontal_flag[1] = 0
counter *= f(horizontal_flag)
horizontal_flag[0] = horizontal_flag[1]
print(counter % 1000000007)
| Statement
We have a board with a 2 \times N grid. Snuke covered the board with N
dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1
square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and
green. Two dominoes that are adjacent by side should be painted by different
colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in
the following manner:
* Each domino is represented by a different English letter (lowercase or uppercase).
* The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left. | [{"input": "3\n aab\n ccb", "output": "6\n \n\nThere are six ways as shown below:\n\n\n\n* * *"}, {"input": "1\n Z\n Z", "output": "3\n \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}] |
Print the number of such ways to paint the dominoes, modulo 1000000007.
* * * | s526079357 | Accepted | p03628 | Input is given from Standard Input in the following format:
N
S_1
S_2 | N, S, T = int(input()), input(), input()
A = [int(S[i] == T[i]) for i in range(N) if not i or S[i - 1] != S[i]]
a, d = 6 - 3 * A[0], len(A) - 1
if d:
for i in range(d):
b, c = A[i + 1], A[i]
a *= 3 + 2 * c * b - 2 * b - c
print(a % (10**9 + 7))
| Statement
We have a board with a 2 \times N grid. Snuke covered the board with N
dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1
square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and
green. Two dominoes that are adjacent by side should be painted by different
colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in
the following manner:
* Each domino is represented by a different English letter (lowercase or uppercase).
* The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left. | [{"input": "3\n aab\n ccb", "output": "6\n \n\nThere are six ways as shown below:\n\n\n\n* * *"}, {"input": "1\n Z\n Z", "output": "3\n \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}] |
Print the number of such ways to paint the dominoes, modulo 1000000007.
* * * | s009116644 | Runtime Error | p03628 | Input is given from Standard Input in the following format:
N
S_1
S_2 | n = int(input())
s1 = input()
s2 = input()
mod = 10**9+7
b = 0
2did = 0
ans = 0
if s1[0] == s2[0]:
b = 1
ans += 3
else:
2did = 1
ans = 6
for i in range(1,n):
if s1[i] == s2[i]:
if b:
ans = ans*2%mod
b = 1
elif not 2did:
if b:
ans = ans*2%mod
else:
ans = ans*3%mod
2did = 1
b = 0
else:
2did = 0
print(ans) | Statement
We have a board with a 2 \times N grid. Snuke covered the board with N
dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1
square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and
green. Two dominoes that are adjacent by side should be painted by different
colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in
the following manner:
* Each domino is represented by a different English letter (lowercase or uppercase).
* The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left. | [{"input": "3\n aab\n ccb", "output": "6\n \n\nThere are six ways as shown below:\n\n\n\n* * *"}, {"input": "1\n Z\n Z", "output": "3\n \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}] |
Print the number of such ways to paint the dominoes, modulo 1000000007.
* * * | s698548777 | Runtime Error | p03628 | Input is given from Standard Input in the following format:
N
S_1
S_2 | M = 10**9+7
n = int(input())
s = input()
t = input()
ans = 3 if s[0] == t[0] else 6
for i in range(1, n):
if s[i-1] == s[i]:
continue
if s[i-1] == t[i-1]:
ans = ans * 2 % M
else if s[i] != t[i]:
ans = ans * 3 % M
print(ans) | Statement
We have a board with a 2 \times N grid. Snuke covered the board with N
dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1
square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and
green. Two dominoes that are adjacent by side should be painted by different
colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in
the following manner:
* Each domino is represented by a different English letter (lowercase or uppercase).
* The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left. | [{"input": "3\n aab\n ccb", "output": "6\n \n\nThere are six ways as shown below:\n\n\n\n* * *"}, {"input": "1\n Z\n Z", "output": "3\n \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}] |
Print the number of such ways to paint the dominoes, modulo 1000000007.
* * * | s290643770 | Runtime Error | p03628 | Input is given from Standard Input in the following format:
N
S_1
S_2 | n = int(input())
s1 = str(input())
s2 = str(input())
cnt = 1
for i in range(n):
if i == 0:
if s1[i] == s2[i]:
cnt = cnt * 3
previous = 'tate'
else:
cnt = cnt * 6
previous = 'yoko1'
else:
if s1[i] == s2[i]: #tate
if previous == 'tate':
cnt = cnt * 2
elif previous == 'yoko2':
cnt = cnt * 3
else: #yoko
if previous = 'tate':
cnt = cnt * 2
elif previous = 'yoko2':
cnt = cnt * 3
print(cnt%1000000007) | Statement
We have a board with a 2 \times N grid. Snuke covered the board with N
dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1
square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and
green. Two dominoes that are adjacent by side should be painted by different
colors. Here, it is not always necessary to use all three colors.
Find the number of such ways to paint the dominoes, modulo 1000000007.
The arrangement of the dominoes is given to you as two strings S_1 and S_2 in
the following manner:
* Each domino is represented by a different English letter (lowercase or uppercase).
* The j-th character in S_i represents the domino that occupies the square at the i-th row from the top and j-th column from the left. | [{"input": "3\n aab\n ccb", "output": "6\n \n\nThere are six ways as shown below:\n\n\n\n* * *"}, {"input": "1\n Z\n Z", "output": "3\n \n\nNote that it is not always necessary to use all the colors.\n\n* * *"}, {"input": "52\n RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn\n RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn", "output": "958681902"}] |
Print the least common multiple of the given integers in a line. | s075401793 | Accepted | p02469 | n
a1 a2 ... an
n is given in the first line. Then, n integers are given in the second line. | import math
def sieve(n):
p = [1] * (n + 1)
p[0] = p[1] = 0
for i in range(math.ceil((n + 1) ** 0.5)):
if p[i]:
for j in range(2 * i, len(p), i):
p[j] = 0
return p
from itertools import compress, count
def prime_factor(n):
p = sieve(int(n**0.5))
factor = []
for pi in compress(count(0), p):
while n % pi == 0:
n //= pi
factor.append(pi)
if n != 1:
factor.append(n)
return factor
from collections import Counter
from sys import stdin
readline = stdin.readline
n = int(readline())
c = [Counter(prime_factor(ai)) for ai in map(int, readline().split())]
s = set()
for ci in c:
s.update(ci.keys())
ret = 1
for i in [i ** max(ci[i] for ci in c) for i in s]:
ret *= i
print(ret)
| Least Common Multiple
Find the least common multiple (LCM) of given n integers. | [{"input": "3\n 3 4 6", "output": "12"}, {"input": "4\n 1 2 3 5", "output": "30"}] |
Print the least common multiple of the given integers in a line. | s848611147 | Wrong Answer | p02469 | n
a1 a2 ... an
n is given in the first line. Then, n integers are given in the second line. | from math import sqrt, floor
from collections import deque
from functools import reduce
from operator import mul
def divide(p):
global a, lcm, limit
c, d, f = a.copy(), set(), False
while True:
b = set(i for i in c if not (i % p))
d |= c - b
b = set(i // p for i in b)
if not b:
a = d
break
lcm.append(p)
c = b
f = True
if f:
limit = floor(sqrt(max(c)))
n, a = int(input()), set(map(int, input().split()))
p, lcm, limit = 3, deque(), floor(sqrt(max(a)))
divide(2)
while p <= limit:
divide(p)
p += 2
print(reduce(mul, lcm, 1) * reduce(mul, a, 1))
| Least Common Multiple
Find the least common multiple (LCM) of given n integers. | [{"input": "3\n 3 4 6", "output": "12"}, {"input": "4\n 1 2 3 5", "output": "30"}] |
Print the least common multiple of the given integers in a line. | s842668199 | Accepted | p02469 | n
a1 a2 ... an
n is given in the first line. Then, n integers are given in the second line. | n = int(input())
l = list(map(int, input().split()))
def elements(dim):
ans = []
cnt = 2
while cnt <= dim:
if dim % cnt == 0:
dim //= cnt
ans.append(int(cnt))
cnt = 2
else:
cnt += 1
return ans
l_e = []
for i in l:
i_e = elements(i)
for j in i_e:
if j in l_e:
l_e.remove(j)
l_e += i_e
out = 1
for i in l_e:
out *= i
print(out)
| Least Common Multiple
Find the least common multiple (LCM) of given n integers. | [{"input": "3\n 3 4 6", "output": "12"}, {"input": "4\n 1 2 3 5", "output": "30"}] |
For each data set, print x and y separated by a single space. Print the
solution to three places of decimals. Round off the solution to three decimal
places. | s262002732 | Accepted | p00004 | The input consists of several data sets, 1 line for each data set. In a data
set, there will be a, b, c, d, e, f separated by a single space. The input
terminates with EOF. | for line in open(0).readlines():
a, b, c, d, e, f = map(int, line.split())
det = a * e - b * d
x = e * c - b * f
y = a * f - d * c
if det < 0:
x = -x
y = -y
det = -det
print("%.03f %.03f" % (x / det, y / det))
| Simultaneous Equation
Write a program which solve a simultaneous equation:
ax + by = c
dx + ey = f
The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b,
c, d, e, f ≤ 1,000). You can suppose that given equation has a unique
solution. | [{"input": "1 2 3 4 5 6\n 2 -1 -2 -1 -1 -5", "output": "-1.000 2.000\n 1.000 4.000"}, {"input": "2 -1 -3 1 -1 -3\n 2 -1 -3 -9 9 27", "output": "0.000 3.000\n 0.000 3.000"}] |
For each data set, print x and y separated by a single space. Print the
solution to three places of decimals. Round off the solution to three decimal
places. | s274158578 | Wrong Answer | p00004 | The input consists of several data sets, 1 line for each data set. In a data
set, there will be a, b, c, d, e, f separated by a single space. The input
terminates with EOF. | def equation(a, b, c, d, e, f, x):
buff = a * e - b * d
buff_a = a
a = e / buff
b = -b / buff
d = -d / buff
e = buff_a / buff
x.append((a * c) + (b * f))
x.append((d * c) + (e * f))
count = 0
a = []
b = []
c = []
d = []
e = []
f = []
while True:
try:
buff = input().split()
a.append(float(buff[0]))
b.append(float(buff[1]))
c.append(float(buff[2]))
d.append(float(buff[3]))
e.append(float(buff[4]))
f.append(float(buff[5]))
count += 1
except:
break
for i in range(count):
ans = []
equation(a[i], b[i], c[i], d[i], e[i], f[i], ans)
print("{:.4f}".format(ans[0]), "{:.4f}".format(ans[1]))
| Simultaneous Equation
Write a program which solve a simultaneous equation:
ax + by = c
dx + ey = f
The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b,
c, d, e, f ≤ 1,000). You can suppose that given equation has a unique
solution. | [{"input": "1 2 3 4 5 6\n 2 -1 -2 -1 -1 -5", "output": "-1.000 2.000\n 1.000 4.000"}, {"input": "2 -1 -3 1 -1 -3\n 2 -1 -3 -9 9 27", "output": "0.000 3.000\n 0.000 3.000"}] |
For each data set, print x and y separated by a single space. Print the
solution to three places of decimals. Round off the solution to three decimal
places. | s279653374 | Wrong Answer | p00004 | The input consists of several data sets, 1 line for each data set. In a data
set, there will be a, b, c, d, e, f separated by a single space. The input
terminates with EOF. | print("ok")
| Simultaneous Equation
Write a program which solve a simultaneous equation:
ax + by = c
dx + ey = f
The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b,
c, d, e, f ≤ 1,000). You can suppose that given equation has a unique
solution. | [{"input": "1 2 3 4 5 6\n 2 -1 -2 -1 -1 -5", "output": "-1.000 2.000\n 1.000 4.000"}, {"input": "2 -1 -3 1 -1 -3\n 2 -1 -3 -9 9 27", "output": "0.000 3.000\n 0.000 3.000"}] |
For each data set, print x and y separated by a single space. Print the
solution to three places of decimals. Round off the solution to three decimal
places. | s903719485 | Wrong Answer | p00004 | The input consists of several data sets, 1 line for each data set. In a data
set, there will be a, b, c, d, e, f separated by a single space. The input
terminates with EOF. | a, b, c, d, e, f = [int(i) for i in input().split()]
| Simultaneous Equation
Write a program which solve a simultaneous equation:
ax + by = c
dx + ey = f
The program should print x and y for given a, b, c, d, e and f (-1,000 ≤ a, b,
c, d, e, f ≤ 1,000). You can suppose that given equation has a unique
solution. | [{"input": "1 2 3 4 5 6\n 2 -1 -2 -1 -1 -5", "output": "-1.000 2.000\n 1.000 4.000"}, {"input": "2 -1 -3 1 -1 -3\n 2 -1 -3 -9 9 27", "output": "0.000 3.000\n 0.000 3.000"}] |
For each input number, output a line containing the number of 11-sequences.
You can assume the answer fits in a 32-bit signed integer. | s627931259 | Runtime Error | p01300 | The input is a sequence of lines each of which contains a number consisting of
less than or equal to 80000 digits.
The end of the input is indicated by a line containing a single zero, which
should not be processed. | targ = input()
while True:
ans = 0
length = len(targ)
for o in range(length - 1):
disp = [0 for n in range(length)]
for i in range(o + 1, length):
if targ[o] == "0":
disp[i] = ans
elif i == length - 1:
disp[i] = (
int((int(targ[o] + targ[o + 1 : i + 1])) % 11 == 0)
+ disp[i - 1]
+ ans
)
else:
disp[i] = (
int((int(targ[o] + targ[o + 1 : i + 1])) % 11 == 0) + disp[i - 1]
)
ans = disp[-1]
del disp
print(ans)
targ = input()
if targ == "0":
break
| H: Eleven Lover
Edward Leven loves multiples of eleven very much. When he sees a number, he
always tries to find consecutive subsequences (or substrings) forming
multiples of eleven. He calls such subsequences as 11-sequences. For example,
he can find an 11-sequence 781 in a number 17819.
He thinks a number which has many 11-sequences is a _good_ number. He would
like to find out a very _good_ number. As the first step, he wants an easy way
to count how many 11-sequences are there in a given number. Even for him,
counting them from a big number is not easy. Fortunately, one of his friends,
you, is a brilliant programmer. He asks you to write a program to count the
number of 11-sequences. Note that an 11-sequence must be a positive number
without leading zeros. | [{"input": "1111\n 11011\n 1234567891011121314151617181920\n 0", "output": "4\n 4\n 38"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s431519201 | Accepted | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | import math
import fractions
# import sys
# input = sys.stdin.readline
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)
# divisors.sort()
return divisors
def ValueToBits(x, digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i] = now % 2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans += arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i], i] for i in range(n)]
aa.sort(key=lambda x: x[0])
for i in range(n):
aa[i][0] = i + 1
aa.sort(key=lambda x: x[1])
b = [aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit - i - 1] = now % 10
now = now // 10
return ans
def Zeros(a, b):
if b <= -1:
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
"""
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
"""
# a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
# 9:04
n = int(input())
for i in range(n):
a, b, c, d = list(map(int, input().split()))
if b > d or a < b:
print("No")
continue
G = fractions.gcd(b, d)
minim = a % G
if b - G <= c and minim <= c:
print("Yes")
else:
print("No")
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s031580335 | Accepted | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI():
return [int(x) for x in sys.stdin.readline().split()]
def LI_():
return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF():
return [float(x) for x in sys.stdin.readline().split()]
def LS():
return sys.stdin.readline().split()
def I():
return int(sys.stdin.readline())
def F():
return float(sys.stdin.readline())
def S():
return input()
def pf(s):
return print(s, flush=True)
def main():
t = I()
aa = [LI() for _ in range(t)]
rr = []
for a, b, c, d in aa:
if a < b or d < b:
rr.append("No")
continue
if c >= b:
rr.append("Yes")
continue
g = fractions.gcd(b, d)
if g == 1:
if b - c > 1:
rr.append("No")
else:
rr.append("Yes")
continue
t = (a + d - c) % g
if t == 0:
t = g
if b - c - t > 0:
rr.append("No")
else:
rr.append("Yes")
return "\n".join(rr)
print(main())
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s372742344 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | import sys
iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]
# わからんから解説見た。解説見たけどgcdの下りが自分で導出できんかったのでとりあえ
ずバカループでなんとかしてみた。これで通るかな。
def f調1(iA, iB, iC, iD):
if iA < iB or iD < iB:
return False
if iC >= iB:
return True
iJ = iA % iB
iK = iD % iB
i = 1
while True:
j = iJ + i * iK
if iB <= j:
return True
else:
if iC < j:
return False
if iK == 0:
return True
i += 1
return True
for eR in aR:
if f調1(*eR):
print("Yes")
else:
print("No")
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s579243909 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | #include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
ll t;cin>>t;
while(t--){
ll a,b,c,d;cin>>a>>b>>c>>d;
ll rem=a;
while(true){
if(rem/b==0){
cout<<"No"<<endl;
break;
}
rem%=b;
if(rem<=c) rem+=d;
if(rem==a){
cout<<"Yes"<<endl;
break;
}
}
}
return 0;
}
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s785894895 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | import sys
iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]
# わからんから解説見た。解説見たけどgcdの下りが自分で導出できんかったのでとりあえ
ずバカループでなんとかしてみた。これで通るかな。
def fFunc(iA, iB, iC, iD):
if iA < iB or iD < iB:
return False
if iC >= iB:
return True
iJ = iA % iB
iK = iD % iB
i = 1
while True:
j = iJ + i * iK
if iB <= j:
return True
else:
if iC < j:
return False
if iK == 0:
return True
i += 1
return True
for eR in aR:
if fFunc(*eR):
print("Yes")
else:
print("No")
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s615002022 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main(){
LL T;
cin >> T;
for(int t = 0; t < T; t++){
LL A, B, C, D;
cin >> A >> B >> C >> D;
if(A < B || D < B){
cout << "No" << '\n';
continue;
}
LL r = __gcd(B,D);
LL mult = (C + 1 - (A % r) + r - 1) / r;
LL F = mult * r + (A % r);
if(F >= B){
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
}
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s275123112 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | t = input()
result = []
hist = []
for i in range(int(t)):
data = input().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])
d = int(data[3])
hist.clear()
while True:
if a < b:
result.append("No")
break
n = int((a / b))
a -= b * n
if a <= c:
a += d
if a in hist:
result.append("Yes")
break
else:
hist.append(a)
if (len(hist) > 5) && (b < d):
result.append("Yes")
break
for i in range(int(t)):
print(result[i]) | Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s630731272 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. | t = int(input())
for i in range(t):
able = "Yes"
a,b,c,d = map(int, input().split())
if a - b < 0:
able = "No"
else:
if a-c >= 0:
x = c+(a-c)%b
if x <= c:
x+=d
for i in range(5000):
x-=b
if x >= 0:
if x <= c:
x+=d
else:
able = "No"
break
print(able) | Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s085412385 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. |
aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
bb=input()
#print(b)
N[i]=bb.split()
def so(p,q):
for i in range(min(p,q),0,-1):
if p%i=0 and q%i=0:
return i
def aaa(n):
a=int(N[n][0])
b=int(N[n][1])
c=int(N[n][2])
d=int(N[n][3])
e=a-a//b*b
f=d-d//b*b
s=so(e,f)
if a<b or d<b :
return "No"
elif b<=c :
return "Yes"
else:
if f!=0 :
g=(b-e)//f
e=e+f*g
while e>c:
if e<b :
return "No"
e-=s
#print(e)
#print(f)
#print("while")
else:
if e>c :
return "No"
return "Yes"
for i in range(aa):
print(aaa(i))
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
Print T lines. The i-th line should contain `Yes` if Snuke can buy apple juice
indefinitely in the i-th query; `No` otherwise.
* * * | s079669215 | Runtime Error | p03297 | Input is given from Standard Input in the following format:
T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T
In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i. |
aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
bb=input()
#print(b)
N[i]=bb.split()
for i in range(aa):
a=int(N[i][0])
b=int(N[i][1])
c=int(N[i][2])
d=int(N[i][3])
e=a-a//b*b
f=d-d//b*b
h=0 #YES=0 NO=1
if a<b or d<b :
h=1
else:
if f!=0 :
while e<b:
if e>c :
h=1
e+=f
if h=1:
break
#print(e)
#print(f)
#print("while")
else:
if e>c :
h=1
if h==1:
print("No")
else:
print("Yes")
| Statement
Ringo Mart, a convenience store, sells apple juice.
On the opening day of Ringo Mart, there were A cans of juice in stock in the
morning. Snuke buys B cans of juice here every day in the daytime. Then, the
manager checks the number of cans of juice remaining in stock every night. If
there are C or less cans, D new cans will be added to the stock by the next
morning.
Determine if Snuke can buy juice indefinitely, that is, there is always B or
more cans of juice in stock when he attempts to buy them. Nobody besides Snuke
buy juice at this store.
Note that each test case in this problem consists of T queries. | [{"input": "14\n 9 7 5 9\n 9 7 6 9\n 14 10 7 12\n 14 10 8 12\n 14 10 9 12\n 14 10 7 11\n 14 10 8 11\n 14 10 9 11\n 9 10 5 10\n 10 10 5 10\n 11 10 5 10\n 16 10 5 10\n 1000000000000000000 17 14 999999999999999985\n 1000000000000000000 17 15 999999999999999985", "output": "No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n No\n Yes\n Yes\n No\n No\n Yes\n \n\nIn the first query, the number of cans of juice in stock changes as follows:\n(D represents daytime and N represents night.)\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 6 \u2192D x\n\nIn the second query, the number of cans of juice in stock changes as follows:\n\n9 \u2192D 2 \u2192N 11 \u2192D 4 \u2192N 13 \u2192D 6 \u2192N 15 \u2192D 8 \u2192N 8 \u2192D 1 \u2192N 10 \u2192D 3 \u2192N 12 \u2192D 5 \u2192N 14\n\u2192D 7 \u2192N 7 \u2192D 0 \u2192N 9 \u2192D 2 \u2192N 11 \u2192D \u2026\n\nand so on, thus Snuke can buy juice indefinitely.\n\n* * *"}, {"input": "24\n 1 2 3 4\n 1 2 4 3\n 1 3 2 4\n 1 3 4 2\n 1 4 2 3\n 1 4 3 2\n 2 1 3 4\n 2 1 4 3\n 2 3 1 4\n 2 3 4 1\n 2 4 1 3\n 2 4 3 1\n 3 1 2 4\n 3 1 4 2\n 3 2 1 4\n 3 2 4 1\n 3 4 1 2\n 3 4 2 1\n 4 1 2 3\n 4 1 3 2\n 4 2 1 3\n 4 2 3 1\n 4 3 1 2\n 4 3 2 1", "output": "No\n No\n No\n No\n No\n No\n Yes\n Yes\n No\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No\n Yes\n Yes\n Yes\n No\n No\n No"}] |
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with
all given pieces of information, print `Yes`; if it does not exist, print
`No`.
* * * | s406093986 | Runtime Error | p03452 | Input is given from Standard Input in the following format:
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M | def LI():
return list(map(int, input().split()))
def LS():
return input().split()
def I():
return int(input())
def S():
return input()
import networkx as nx
n, m = LI()
l = []
for i in range(m):
l.append(LI())
edge = []
graph1 = [[float("inf")] * n for i in range(n)]
graph2 = [[float("inf")] * n for i in range(n)]
dic1 = {}
dic2 = {}
for i in range(m):
if l[i][0] - 1 not in dic1:
dic1[l[i][0] - 1] = 1
else:
dic1[l[i][0] - 1] += 1
if l[i][1] - 1 not in dic2:
dic2[l[i][1] - 1] = 1
else:
dic2[l[i][1] - 1] += 1
edge.append([l[i][0], l[i][1]])
graph1[l[i][0] - 1][l[i][1] - 1] = l[i][2]
graph2[l[i][0] - 1][l[i][1] - 1] = -l[i][2]
G = nx.DiGraph()
G.add_edges_from(edge)
try:
a = nx.topological_sort(G)
except:
print("No")
exit()
# print(a)
# 向きありグラフ
# 矛盾する時、距離正の閉路が存在(1→3, 3と3→1, 2)、距離を持つ(i,j)に対して全てのパスの距離が違う(最小 != 最大 1→2→3 1→4→3)
# グラフを作った後、前者はトポロジカルソート、 後者はダイクストラと、最長距離は辺の値を負にするためダイクストラが使えない?→いや使える全部負ならok
# 閉路が無い時、1→3→5 と1→4→5 を判定できない(V^3)
# 2つ以上のパスを持つところをリストでもっておいて探索
s = []
e = []
for i in dic1.keys():
if dic1[i] > 1:
s.append(i)
for i in dic2.keys():
if dic2[i] > 1:
e.append(i)
# print(s,e)
import heapq
class Dijkstra(object):
def dijkstra(self, adj, start, goal=None):
"""
ダイクストラアルゴリズムによる最短経路を求めるメソッド
入力
adj: adj[i][j]の値が頂点iから頂点jまでの距離(頂点iから頂点jに枝がない場合,値はfloat('inf'))となるような2次元リスト(正方行列)
start: 始点のID
goal: オプション引数.終点のID
出力
goalを引数に持つ場合,startからgoalまでの最短経路を格納したリストを返す
持たない場合は,startから各頂点までの最短距離を格納したリストを返す
>>> d = Dijkstra()
>>> d.dijkstra([[float('inf'), 2, 4, float('inf'), float('inf')], [2, float('inf'), 3, 5, float('inf')], [4, 3, float('inf'), 1, 4], [float('inf'), 5, 1, float('inf'), 3], [float('inf'), float('inf'), 4, 3, float('inf')]], 0)
[0, 2, 4, 5, 8] # 例えば,始点0から頂点3までの最短距離は5となる
>>> d.dijkstra([[float('inf'), 2, 4, float('inf'), float('inf')], [2, float('inf'), 3, 5, float('inf')], [4, 3, float('inf'), 1, 4], [float('inf'), 5, 1, float('inf'), 3], [float('inf'), float('inf'), 4, 3, float('inf')]], 0, goal=4)
[0, 2, 4] # 頂点0から頂点4までの最短経路は0 -> 2 -> 4となる
"""
num = len(adj) # グラフのノード数
dist = [
float("inf") for i in range(num)
] # 始点から各頂点までの最短距離を格納する
prev = [
float("inf") for i in range(num)
] # 最短経路における,その頂点の前の頂点のIDを格納する
dist[start] = 0
q = (
[]
) # プライオリティキュー.各要素は,(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
heapq.heappush(q, (0, start)) # 始点をpush
while len(q) != 0:
prov_cost, src = heapq.heappop(q) # pop
# プライオリティキューに格納されている最短距離が,現在計算できている最短距離より大きければ,distの更新をする必要はない
if dist[src] < prov_cost:
continue
# 他の頂点の探索
for dest in range(num):
cost = adj[src][dest]
if cost != float("inf") and dist[dest] > dist[src] + cost:
dist[dest] = dist[src] + cost # distの更新
heapq.heappush(
q, (dist[dest], dest)
) # キューに新たな仮の距離の情報をpush
prev[dest] = src # 前の頂点を記録
if goal is not None:
return self.get_path(goal, prev)
else:
return dist
def get_path(self, goal, prev):
"""
始点startから終点goalまでの最短経路を求める
"""
path = [goal] # 最短経路
dest = goal
# 終点から最短経路を逆順に辿る
while prev[dest] != float("inf"):
path.append(prev[dest])
dest = prev[dest]
# 経路をreverseして出力
return list(reversed(path))
flag = True
for i in s:
test = Dijkstra()
k1 = test.dijkstra(graph1, i)
k2 = test.dijkstra(graph2, i)
for j in e:
if abs(k1[j]) != abs(k2[j]):
flag = False
print("No")
exit()
break
if flag == False:
break
if flag:
print("Yes")
| Statement
There are N people standing on the x-axis. Let the coordinate of Person i be
x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is
possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these
people. The i-th piece of information has the form (L_i, R_i, D_i). This means
that Person R_i is to the right of Person L_i by D_i units of distance, that
is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is
consistent with the given pieces of information. | [{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}] |
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with
all given pieces of information, print `Yes`; if it does not exist, print
`No`.
* * * | s635143255 | Runtime Error | p03452 | Input is given from Standard Input in the following format:
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M | from collections import deque
import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
Graph=[[] for i in range(N)]
for i in range(M):
L,R,D=map(int,input().split())
Graph[L-1].append(R-1,D)
Graph[R-1].append(L-1,-D)
visit=[False]*N
dist=[0]*N
for i in range(N):
if not visit[i]:
visit[i]=True
A=deque()
A.append(i)
while A:
x=A.pop()
for y,d in Graph[x]:
if visit[y] and dist[y]!=d+dist[x]
print('No')
exit()
elif not visit[y]:
visit[y]=True
A.append(y)
dist[y]=d+dist[x]
print('Yes') | Statement
There are N people standing on the x-axis. Let the coordinate of Person i be
x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is
possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these
people. The i-th piece of information has the form (L_i, R_i, D_i). This means
that Person R_i is to the right of Person L_i by D_i units of distance, that
is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is
consistent with the given pieces of information. | [{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}] |
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with
all given pieces of information, print `Yes`; if it does not exist, print
`No`.
* * * | s374927143 | Wrong Answer | p03452 | Input is given from Standard Input in the following format:
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M | print("Yes")
| Statement
There are N people standing on the x-axis. Let the coordinate of Person i be
x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is
possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these
people. The i-th piece of information has the form (L_i, R_i, D_i). This means
that Person R_i is to the right of Person L_i by D_i units of distance, that
is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is
consistent with the given pieces of information. | [{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}] |
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with
all given pieces of information, print `Yes`; if it does not exist, print
`No`.
* * * | s424031874 | Runtime Error | p03452 | Input is given from Standard Input in the following format:
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M | print(Yes)
| Statement
There are N people standing on the x-axis. Let the coordinate of Person i be
x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is
possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these
people. The i-th piece of information has the form (L_i, R_i, D_i). This means
that Person R_i is to the right of Person L_i by D_i units of distance, that
is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is
consistent with the given pieces of information. | [{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}] |
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with
all given pieces of information, print `Yes`; if it does not exist, print
`No`.
* * * | s265337311 | Runtime Error | p03452 | Input is given from Standard Input in the following format:
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M | from collections import deque
import sys
input = sys.stdin.readline
def bfs(graph, start):
queue = deque([])
queue.append(start)
pos = {}
pos[start] = 0
while queue:
u = queue.popleft()
if u not in graph:
if graph != {}
u = min(graph.keys())
pos = {u:0}
else:
continue
for v,d in graph[u].items():
if v not in pos:
pos[v] = pos[u] + d
queue.append(v)
elif pos[v] != pos[u] + d:
return False
del graph[u]
# print(queue)
return True
n,m = map(int, input().split())
graph = {}
for i in range(m):
l,r,d = map(int, input().split())
if l not in graph:
graph[l] = {}
graph[l][r] = d
if r not in graph:
graph[r] = {}
graph[r][l] = -d
if m == 0 or bfs(graph, min(graph.keys())):
print('Yes')
else:
print('No')
| Statement
There are N people standing on the x-axis. Let the coordinate of Person i be
x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is
possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these
people. The i-th piece of information has the form (L_i, R_i, D_i). This means
that Person R_i is to the right of Person L_i by D_i units of distance, that
is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is
consistent with the given pieces of information. | [{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}] |
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with
all given pieces of information, print `Yes`; if it does not exist, print
`No`.
* * * | s602605236 | Runtime Error | p03452 | Input is given from Standard Input in the following format:
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M | N,M = list(map(int,input().split()))
edges = [[] for _ in range(N)]
for i in range(M):
L,R,D = list(map(int,input().split()))
edges[L - 1].append((R -1,D))
edges[R - 1].append((L-1, -D))
visited = [None] * N
place = [0] * N
inf = 10 ** 10
def walk(i):
if visited[i]:
return (place[i], place[i])
visited[i] = True
(n,m) = (inf, - inf)
for j,d in edges[i]:
#print(j,d)
if visited[j] and place[j] != place[i] + d:
print("No")
exit()
place[j] = place[i] + d
(x,y) = walk(j)
(n,m) = (min(n,x),max(m,y))
return (n,m)
'''
for i in range(N):
if not visited[i]:
place[i] = 0
# 連結成分のminとmax
(n,m) = walk(i)
if m - n > 10 ** 9:
print("No")
exit()
'''
print("Yes") | Statement
There are N people standing on the x-axis. Let the coordinate of Person i be
x_i. For every i, x_i is an integer between 0 and 10^9 (inclusive). It is
possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these
people. The i-th piece of information has the form (L_i, R_i, D_i). This means
that Person R_i is to the right of Person L_i by D_i units of distance, that
is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is
consistent with the given pieces of information. | [{"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 2", "output": "Yes\n \n\nSome possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102,\n103).\n\n* * *"}, {"input": "3 3\n 1 2 1\n 2 3 1\n 1 3 5", "output": "No\n \n\nIf the first two pieces of information are correct, x_3 - x_1 = 2 holds, which\nis contradictory to the last piece of information.\n\n* * *"}, {"input": "4 3\n 2 1 1\n 2 3 5\n 3 4 2", "output": "Yes\n \n\n* * *"}, {"input": "10 3\n 8 7 100\n 7 9 100\n 9 8 100", "output": "No\n \n\n* * *"}, {"input": "100 0", "output": "Yes"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s078868236 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | n = int(input())
arr = [input() for i in range(n)]
acnum = arr.count("AC")
wanum = arr.count("WA")
tlenum = arr.count("TLE")
renum = arr.count("RE")
print("AC x", str(acnum))
print("WA x", str(wanum))
print("TLE x", str(tlenum))
print("RE x", str(renum))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s087408162 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | a = int(input())
hantei = []
for n in range(a):
hantei.append(input())
print("AC x {}".format(hantei.count("AC")))
print("WA x {}".format(hantei.count("WA")))
print("TLE x {}".format(hantei.count("TLE")))
print("RE x {}".format(hantei.count("RE")))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s368905861 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | counto = []
for _ in range(int(input())):
s = input()
counto.append(s)
print("AC" + " x " + str(counto.count("AC")))
print("WC" + " x " + str(counto.count("WA")))
print("TLE" + " x " + str(counto.count("TLE")))
print("RE" + " x " + str(counto.count("RE")))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s594084231 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | n = int(input())
sList = []
for i in range(n):
sList.append(input())
D = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for j in sList:
D[j] += 1
print("AC x", D["AC"])
print("WA x", D["WA"])
print("TLE x", D["TLE"])
print("RE x", D["RE"])
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s918770085 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | def main(n, si):
results = ["AC", "WA", "TLE", "RE"]
res_num = [0, 0, 0, 0]
for index in range(0, n):
if si[0:2] == results[0]:
res_num[0] += 1
si = si.replace(results[0], "", 1)
print(si)
if si[0:2] == results[1]:
res_num[1] += 1
si = si.replace(results[1], "", 1)
print(si)
if si[0:3] == results[2]:
res_num[2] += 1
si = si.replace(results[2], "", 1)
print(si)
if si[0:2] == results[3]:
res_num[3] += 1
si = si.replace(results[3], "", 1)
print(si)
print(res_num)
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s009298873 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | def main(self, case):
for i in range(len(case)):
AC = 0
WA = 0
TLE = 0
RE = 0
others = 0
if case[i] == "AC":
AC += 1
return AC
elif case[i] == "WA":
WA += 1
return WA
elif case[i] == "TLE":
TLE += 1
return TLE
elif case[i] == "RE":
RE += 1
return RE
else:
others += 1
return others
print("AC" + "x" + AC)
print("WA" + "x" + WA)
print("TLE" + "x" + TLE)
print("RE" + "x" + RE)
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s236291252 | Runtime Error | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | string1 = int(input())
string2 = "AC"
string3 = string1.count(string2)
print("AC x {}".format(string3))
string4 = "WA"
string5 = string1.count(string4)
print("WA x {}".format(string5))
string6 = "TLE"
string7 = string1.count(string6)
print("TLE x {}".format(string7))
string8 = "RE"
string9 = string1.count(string8)
print("RE x {}".format(string9))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s949158090 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | num = input()
if int(num) <= 1000:
change = 1000 - int(num)
else:
array_1 = list(num)
array_1 = array_1[-4:]
a = "".join(array_1)
b = int(array_1[-4]) + 1
pay = b * 1000
change = pay - int(a)
if array_1[-1] == "0" and array_1[-2] == "0" and array_1[-3] == "0":
change = 0
print(change)
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s495125280 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | # -*- coding: utf-8 -*-
# input
# 配列のinput
n = int(input())
temp_array = []
addlist = temp_array.append
for i in range(n):
addlist(input())
print("AC x " + str(temp_array.count("AC")))
print("WA x " + str(temp_array.count("WA")))
print("TLE x " + str(temp_array.count("TLE")))
print("RE x " + str(temp_array.count("RE")))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s518907606 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | rows = int(input())
x = [input() for i in range(rows)]
print("AC × {}".format(x.count("AC")))
print("WA × {}".format(x.count("WA")))
print("TLE × {}".format(x.count("TLE")))
print("RE × {}".format(x.count("RE")))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s358909032 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | n = int(input())
a = [input() for i in range(n)]
A = str(a.count("AC"))
B = str(a.count("WA"))
C = str(a.count("TLE"))
D = str(a.count("RE"))
print("AC x" + A)
print("WA x" + B)
print("TLE x" + C)
print("RE x" + D)
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s609512372 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | from sys import stdin
input = stdin.readline
N = int(input())
list_result = [input() for i in range(N)]
AC_cnt = 0
WA_cnt = 0
TLE_cnt = 0
RE_cnt = 0
for i in list_result:
if i == "AC\n":
AC_cnt += 1
elif i == "WA\n":
WA_cnt += 1
elif i == "TLE\n":
TLE_cnt += 1
elif i == "RE\n":
RE_cnt += 1
print("AC x", AC_cnt, "\n" "WA x", WA_cnt, "\n" "TLE x", TLE_cnt, "\n" "RE x", RE_cnt)
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s935802449 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | #!/usr/bin/env python
# pyrival orz
import os
import sys
from io import BytesIO, IOBase
"""
for _ in range(int(input())):
n,m=map(int,input().split())
n=int(input())
a = [int(x) for x in input().split()]
"""
def main():
from collections import defaultdict
ans = defaultdict(int)
for _ in range(int(input())):
ans[input()] += 1
print("AC X " + str(ans["AC"]))
print("WA X " + str(ans["WA"]))
print("TLE X " + str(ans["TLE"]))
print("RE X " + str(ans["RE"]))
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s212997315 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | n, *a = open(0).read().split()
d = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for i in a:
d[i] = d.get(i, 0) + 1
for i, j in d.items():
print(i, "x", j)
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s704954689 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | num = int(input().rstrip())
cases = []
for i in range(num):
cases.append(input().rstrip())
target = ["AC", "WA", "TLE", "RE"]
result = [0, 0, 0, 0]
for j in range(len(target)):
for i in range(len(cases)):
if cases[i] == target[j]:
result[j] = result[j] + 1
for i in range(len(target)):
print(target[i] + " x " + str(result[i]))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s718610804 | Accepted | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | n_entradas = int(input())
contador = 0
vetor = []
while contador < n_entradas:
situacao = str(input())
vetor.append(situacao)
contador = contador + 1
print("AC x", vetor.count("AC"))
print("WA x", vetor.count("WA"))
print("TLE x", vetor.count("TLE"))
print("RE x", vetor.count("RE"))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s286117129 | Wrong Answer | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | x = int(input())
b = 0
lst = []
acs = 0
was = 0
res = 0
tles = 0
while b < x:
new = input()
lst.append(new)
b += 1
for c in lst:
if c == "AC":
acs += 1
if c == "WA":
was += 1
if c == "RE":
res += 1
if c == "TLE":
tles += 1
print("AC x " + str(acs))
print("WA x " + str(was))
print("RE x " + str(res))
print("TLE x " + str(tles))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
Let C_0, C_1, C_2, and C_3 be the numbers of test cases for which the verdict
is `AC`, `WA`, `TLE`, and `RE`, respectively. Print the following:
AC x C_0
WA x C_1
TLE x C_2
RE x C_3
* * * | s999554752 | Runtime Error | p02613 | Input is given from Standard Input in the following format:
N
S_1
\vdots
S_N | n = int(input())
I = {"ac": 0, "wa": 0, "tle": 0, "re": 0}
for i in n:
I[input()] += 1
print("AC x {}".format(I["ac"]))
print("WA x {}".format(I["wa"]))
print("TLE x {}".format(I["tle"]))
print("RE x {}".format(I["re"]))
| Statement
Takahashi is participating in a programming contest called AXC002, and he has
just submitted his code to Problem A.
The problem has N test cases.
For each test case i (1\leq i \leq N), you are given a string S_i representing
the verdict for that test case. Find the numbers of test cases for which the
verdict is `AC`, `WA`, `TLE`, and `RE`, respectively.
See the Output section for the output format. | [{"input": "6\n AC\n TLE\n AC\n AC\n WA\n TLE", "output": "AC x 3\n WA x 1\n TLE x 2\n RE x 0\n \n\nWe have 3, 1, 2, and 0 test case(s) for which the verdict is `AC`, `WA`,\n`TLE`, and `RE`, respectively.\n\n* * *"}, {"input": "10\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC\n AC", "output": "AC x 10\n WA x 0\n TLE x 0\n RE x 0"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s590877833 | Wrong Answer | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | # coding:utf-8
dic = {}
nil = -1
class Doubly:
def __init__(self, key, l=nil, r=nil):
self.l = l
self.r = r
self.key = key
def Insert(self, key):
obj = Doubly(key)
obj.l = fake
fakeR = fake.r
fake.r = obj
obj.r = fakeR
fakeR.l = obj
if key in dic.keys():
dic[key].append(obj)
else:
dic[key] = [obj]
def deleteFirst(self):
fakeR = fake.r
fake.r = fakeR.r
fakeR.r.l = fake
key = fakeR.key
if dic != {}:
dic[key].pop(0)
if dic[key] == []:
del dic[key]
def deleteLast(self):
fakeL = fake.l
fake.l = fakeL.l
fakeL.l.r = fake
key = fakeL.key
if dic != {}:
dic[key].pop(0)
if dic[key] == []:
del dic[key]
def Delete(self, target):
if target in dic.keys():
obj = dic[target].pop(0)
objL = obj.l
objR = obj.r
objL.r = objR
objR.l = objL
if dic[target] == []:
del dic[target]
n = int(input())
fake = Doubly(nil)
fake.l = fake
fake.r = fake
for i in range(n):
data = list(input().split())
order = data[0]
if order == "insert":
Doubly.Insert(Doubly, int(data[1]))
elif order == "delete":
Doubly.Delete(Doubly, int(data[1]))
elif order == "deleteFirst":
Doubly.deleteFirst(Doubly)
else:
Doubly.deleteLast(Doubly)
obj = fake.r
List = []
while obj.key != -1:
List.append(str(obj.key))
obj = obj.r
print(" ".join(List))
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s258856945 | Wrong Answer | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | # -*- coding: utf-8 -*-
from collections import defaultdict
from heapq import heappop, heappush
def dijkstra(edges, start, *, adj_matrix=False, default_value=float("inf")):
"""
Returns best costs to each node from 'start' node in the given graph.
(Single Source Shortest Path - SSSP)
If edges is given as an adjacency list including costs and destination nodes on possible edges, adj_matrix should be False(default), and it is generally when this functions works much faster.
Note that costs in edges should follow the rules below
1. The cost from a node itself should be 0,
2. If there is no edge between nodes, the cost between them should be default_value
3. The costs can't be negative
# sample input when given as adjacency list (adj_matrix=False)
edges = [[(1, 2), (2, 5), (3, 4)], # node 0
[(0, 2), (3, 3), (4, 6)], # node 1
[(0, 5), (3, 2), (5, 6)], # node 2
[(0, 4), (1, 3), (2, 2), (4, 2)], # node 3
[(1, 6), (3, 2), (5, 4)], # node 4
[(2, 6), (4, 4)]] # node 5
# sample input when given as adjacency matrix (adj_matrix=True)
edges = [[0, 2, 5, 4, inf, inf], # node 0
[2, 0, inf, 3, 6, inf], # node 1
[5, inf, 0, 2, inf, 6], # node 2
[4, 3, 2, 0, 2, inf], # node 3
[inf, 6, inf, 2, 0, 4], # node 4
[inf, inf, 6, inf, 4, 0]] # node 5
"""
n = len(edges)
inf = float("inf")
# costs = [inf] * n
costs = defaultdict(lambda: inf)
costs[start] = 0
pq, rem = [(0, start)], n - 1
while pq and rem:
tmp_cost, tmp_node = heappop(pq)
if costs[tmp_node] < tmp_cost:
continue
rem -= 1
nxt_edges = (
(
(node, cost)
for node, cost in enumerate(edges[tmp_node])
if cost != default_value
)
if adj_matrix
else edges[tmp_node]
)
for nxt_node, nxt_cost in nxt_edges:
new_cost = tmp_cost + nxt_cost
if costs[nxt_node] > new_cost:
costs[nxt_node] = new_cost
heappush(pq, (new_cost, nxt_node))
return costs
def dijkstra_route(
edges, start, goal, *, adj_matrix=False, default_value=float("inf"), verbose=False
):
"""
Trys to find the best route to the 'goal' from the 'start'
"""
n = len(edges)
inf = float("inf")
# costs = [inf] * n
costs = defaultdict(lambda: inf)
costs[start] = 0
pq, rem = [(0, start)], n - 1
# prevs = [-1 for _ in [None] * n]
prevs = defaultdict(lambda: -1)
while pq and rem:
tmp_cost, tmp_node = heappop(pq)
if costs[tmp_node] < tmp_cost:
continue
rem -= 1
nxt_edges = (
(
(node, cost)
for node, cost in enumerate(edges[tmp_node])
if cost != default_value
)
if adj_matrix
else edges[tmp_node]
)
for nxt_node, nxt_cost in nxt_edges:
new_cost = tmp_cost + nxt_cost
if costs[nxt_node] > new_cost:
costs[nxt_node] = new_cost
heappush(pq, (new_cost, nxt_node))
prevs[nxt_node] = tmp_node
min_route = []
prev = goal
cnt = 0
while prev != start:
min_route.append(prev)
prev = prevs[prev]
cnt += 1
if prev == -1 or cnt > n:
raise NoRouteError(
"There is no possible route in this graph \nedges: {} \nstart: {} \ngoal: {}".format(
edges, start, goal
)
)
else:
min_route.append(prev)
min_route = min_route[::-1]
min_cost = costs[goal]
if verbose:
print("---route---")
for node in min_route[:-1]:
print("{} -> ".format(node), end="")
else:
print(min_route[-1])
print("---distance---")
print(min_cost)
return costs, min_route
class NoRouteError(Exception):
pass
if __name__ == "__main__":
"""
an example of using this function
AIZU ONLINE JUDGE - ALDS_1_12_C
"""
n = int(input())
edges = [[] for i in range(n)]
for i in range(n):
i, k, *kedges = map(int, input().split())
for edge in zip(kedges[::2], kedges[1::2]):
edges[i].append(edge)
for i, cost in enumerate(dijkstra(edges, 0)):
print(i, cost)
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s344004382 | Wrong Answer | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | from heapq import heappop, heappush
import sys
class SSSP:
"""Given weighted graph, find Single Sorce Shortest Path from node 0.
>>> st = SSSP([[(2, 3), (3, 1), (1, 2)], \
[(0, 2), (3, 4)], \
[(0, 3), (3, 1), (4, 1)], \
[(2, 1), (0, 1), (1, 4), (4, 3)], \
[(2, 1), (3, 3)]])
>>> [st.weight(n) for n in range(5)]
[0, 2, 2, 1, 3]
"""
def __init__(self, graph):
self.size = len(graph)
self.tree = []
self.weights = [0] * self.size
self._search(graph)
def weight(self, n):
return self.weights[n]
def _search(self, graph):
h = []
count = 1
for i, w in graph[0]:
heappush(h, (w, 0, i))
while count < self.size:
while len(h) > 0:
weight, src, dst = heappop(h)
if self.weights[dst] == 0 and dst > 0:
self.weights[dst] = weight
count += 1
self.tree.append((src, dst))
for i, w in graph[dst]:
if self.weights[i] == 0 and dst > 0:
heappush(h, (w + weight, dst, i))
break
def run():
n = int(input())
nodes = [None] * n
for line in sys.stdin:
id_, deg, *edges = [int(i) for i in line.split()]
nodes[id_] = []
for _ in range(deg):
tgt, wgt, *edges = edges
nodes[id_].append((tgt, wgt))
st = SSSP(nodes)
for node in range(n):
print("{} {}".format(node, st.weight(node)))
if __name__ == "__main__":
run()
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s799847563 | Accepted | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | from heapq import heappop, heappush
def dijkstra(s):
dp[s] = 0
hq = []
used[s] = 0
for i in cost[s]:
heappush(hq, i)
while hq:
minv = heappop(hq)
if used[minv[1]] == 0:
continue
v = minv[1]
dp[v] = minv[0]
used[v] = 0
for i in cost[v]:
if used[i[1]]:
heappush(hq, [i[0] + dp[v], i[1]])
return
INF = 10**18
n = int(input())
cost = [[] for _ in range(n)]
used = [1] * n
dp = [INF] * n
for i in range(n):
lst = list(map(int, input().split()))
for j in range(lst[1]):
v, c = lst[2 + (2 * j)], lst[3 + (2 * j)]
cost[lst[0]].append([c, v])
dijkstra(0)
for i in range(n):
print(i, dp[i])
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s014100779 | Accepted | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | # Graph II - Single Source Shortest Path II
def dijkstra(length, adj_list):
INFTY = float("inf")
d = [INFTY for _ in range(length)]
d[0] = 0
Q = [i for i in range(length)]
while Q:
idx = INFTY
minv = INFTY
for q in Q:
if d[q] < minv:
idx, minv = q, d[q]
u = Q.pop(Q.index(idx))
for v in adj_list[u]:
if d[v[0]] > d[u] + v[1]:
d[v[0]] = d[u] + v[1]
return d
n = int(input())
adj_list = [set() for _ in range(n)]
for _ in range(n):
ss = list(map(int, input().split()))
u, k = ss[0], ss[1]
for i in range(k):
vi, ci = ss[2 * i + 2], ss[2 * i + 3]
adj_list[u].add((vi, ci))
d = dijkstra(n, adj_list)
for i, v in enumerate(d):
print(i, v)
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s069514169 | Accepted | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | import heapq
class Edge:
src = -1
dest = -1
cost = -1
def Dijkstra(graph, s):
INF = int(1e9)
d = [INF] * len(graph)
d[s] = 0
used = [False] * len(graph)
que = []
heapq.heappush(que, (0, s))
while len(que) != 0:
val = heapq.heappop(que)
v = val[1]
if used[v]:
continue
used[v] = True
for i in range(0, len(graph[v])):
e = graph[v][i]
if d[v] + e.cost < d[e.dest]:
d[e.dest] = d[v] + e.cost
heapq.heappush(que, (d[e.dest], e.dest))
return d
V = int(input())
graph = [[] for i in range(0, V)]
for i in range(0, V):
vals = list(map(int, input().split(" ")))
k = vals[1]
for j in range(0, k):
v = vals[2 + j * 2]
c = vals[3 + j * 2]
e = Edge()
e.src = i
e.dest = v
e.cost = c
graph[i].append(e)
d = Dijkstra(graph, 0)
for i in range(0, V):
print(str(i) + " " + str(d[i]))
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s903217020 | Accepted | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | def E_dijkstra(V, AL, S):
from heapq import heappush, heappop
INF = float("inf")
ans = [INF] * V
ans[S] = 0
used = [0] * V # 0:未確定
used[S] = 1
que = []
for i in range(V):
heappush(que, (ans[i], i))
while que:
x, u = heappop(que)
used[u] = 1
for v, w in AL[u]:
if not used[v] and ans[v] > x + w:
ans[v] = x + w
heappush(que, (ans[v], v))
return ans
# verified: https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/1/GRL_1_A
# import sys
# input = sys.stdin.readline
# V,E,R=map(int,input().split())
# AL=[[] for i in range(V)]
# for _ in range(E):
# S,T,D=map(int,input().split())
# AL[S].append((T,D))
# for ans in E_dijkstra(V,AL,R):
# print('INF' if ans==float('inf') else ans)
import sys
input = sys.stdin.readline
N = int(input())
AL = [[] for _ in range(N)]
for _ in range(N):
for i, x in enumerate(input().split()):
x = int(x)
if i == 0:
j = x
elif i == 1:
pass
else:
if i % 2 == 0:
tmp = [x]
else:
tmp.append(x)
AL[j].append(tmp)
for ans in enumerate(E_dijkstra(N, AL, 0)):
print(*ans)
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s487889134 | Accepted | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | from collections import defaultdict
import heapq
v_num = int(input())
connect = defaultdict(list)
for _ in range(v_num):
que = [int(n) for n in input().split(" ")]
connect[que[0]] = [
[v, w] for v, w in zip(que[2 : len(que) : 2], que[3 : len(que) : 2])
]
# weight_edge[que[0]] = {k:v for k, v in zip(que[2:len(que):2], que[3:len(que):2])}
queue = []
heapq.heapify(queue)
heapq.heappush(queue, [0, 0])
distance = [-1 for n in range(v_num)]
went = 0
visited = set()
while went < v_num:
q = heapq.heappop(queue)
weight, here = q
if here in visited:
continue
visited |= {here}
went += 1
distance[here] = weight
for conn in connect[here]:
if conn[0] not in visited:
heapq.heappush(queue, [weight + conn[1], conn[0]])
for i in range(v_num):
print(i, distance[i])
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
For each vertex, print its ID and the distance separated by a space character
in a line respectively. Print in order of vertex IDs. | s004827551 | Accepted | p02243 | In the first line, an integer $n$ denoting the number of vertices in $G$ is
given. In the following $n$ lines, adjacency lists for each vertex $u$ are
respectively given in the following format:
$u$ $k$ $v_1$ $c_1$ $v_2$ $c_2$ ... $v_k$ $c_k$
Vertices in $G$ are named with IDs $0, 1, ..., n-1$. $u$ is ID of the target
vertex and $k$ denotes its degree. $v_i (i = 1, 2, ... k)$ denote IDs of
vertices adjacent to $u$ and $c_i$ denotes the weight of a directed edge
connecting $u$ and $v_i$ (from $u$ to $v_i$). | import heapq
import sys
readline = sys.stdin.readline
def dijkstra(n):
inf = 10**6 + 1
dist = [0] + [inf] * (n - 1)
q = [(0, 0)]
while q:
u = heapq.heappop(q)[1]
for v, c in edge[u]:
alt = dist[u] + c
if dist[v] > alt:
dist[v] = alt
heapq.heappush(q, (alt, v))
return dist
n = int(input())
edge = [[]] * n
for _ in range(n):
l = list(map(int, readline().split()))
edge[l[0]] = (e for e in zip(l[2::2], l[3::2]))
for i, c in enumerate(dijkstra(n)):
print(i, c)
| Single Source Shortest Path II
For a given weighted graph $G = (V, E)$, find the shortest path from a source
to each vertex. For each vertex $u$, print the total weight of edges on the
shortest path from vertex $0$ to $u$. | [{"input": "5\n 0 3 2 3 3 1 1 2\n 1 2 0 2 3 4\n 2 3 0 3 3 1 4 1\n 3 4 2 1 0 1 1 4 4 3\n 4 2 2 1 3 3", "output": "0 0\n 1 2\n 2 2\n 3 1\n 4 3"}] |
Evaluate the formula and print the result.
* * * | s622007951 | Accepted | p03844 | The input is given from Standard Input in the following format:
A op B | o, p, q = map(str, input().split())
a = int(o)
b = int(q)
print(a + b if p == "+" else a - b)
| Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s747717274 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a, o, b = input().split()
if o = '+':
print(int(a) + int(b))
else:
print(int(a) - int(b)) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s209010282 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a,op,b=input().split()
a=int(a)
b=int(b)
if op="+":
print(a+b)
if op="-":
print(a-b) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s834362053 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | A, op, B = list(map(int,input().split()))
if op = '+':
print(A + B)
else:
print(A - B) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s396347084 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a,b,c=input().split()
a=int(a)
c=int(c)
if b="+":
print(a+c)
else:
print(a-c) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s743950720 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a,op,b=input().split())
if op=="+":
print(int(a)+int(b))
else:
print(int(a)-int(b)) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s887184248 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | A, op, B = input().split()
if op = '-':
print(A - B)
else:
print(A + B) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s507253823 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | print(eval(input()) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s177496019 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | A,c,B=input().split()
if c=="+":
print(A+B):
elif c=="-":
print(A-B)
| Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s361213502 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | print(eval(''join(input().strip().split(' ')))) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s674245404 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | print(eval(input()) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s900244823 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a = list(map(int,input().split()))
x = int(x[1])
print(x[0]x[1]x[2]) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s087485116 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | print(eval(input()) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s738836934 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | print(eval(input()) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s103576970 | Wrong Answer | p03844 | The input is given from Standard Input in the following format:
A op B | eval(input().replace(" ", ""))
| Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s232666881 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a, b, c = map(input().split())
if b == +:
print(a + c)
else:
print(a - c) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s894430228 | Accepted | p03844 | The input is given from Standard Input in the following format:
A op B | # 文字で出力する
a_num_str, operator, b_num_str = map(str, input().split())
# a_num_str と b_num_str を 整数にする。
a_num_int = int(a_num_str)
b_num_int = int(b_num_str)
# operator は 「+」「-」の2つがあるので場合わけし計算する。
if operator == "+":
sum_a_b = a_num_int + b_num_int
print(sum_a_b)
elif operator == "-":
sub_a_b = a_num_int - b_num_int
print(sub_a_b)
| Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s289236566 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a, op, b = map(str, input().split())
a = int(a)
b = int(b)
if op == "+":
result = a + b
else:
result = a - b
print(result | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s180769323 | Wrong Answer | p03844 | The input is given from Standard Input in the following format:
A op B | A, B, C = input().split()
if B is "+":
n = int(A) + int(C)
print(n)
elif B is "-":
n = int(A) - int(C)
print(n)
| Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s398965179 | Wrong Answer | p03844 | The input is given from Standard Input in the following format:
A op B | import sys
from io import StringIO
import unittest
def resolve():
input_string = list(input())
num1 = int(input_string[0])
num2 = int(input_string[4])
operater = input_string[2]
result = 0
if operater == "+":
result = num1 + num2
elif operater == "-":
result = num1 - num2
print(result)
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """1 + 2"""
output = """3"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """5 - 7"""
output = """-2"""
self.assertIO(input, output)
if __name__ == "__main__":
unittest.main()
| Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s513451422 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | # 数値と符合を取得
A,op,B = map(str,input().split())
# 計算結果を出力
A = int(A)
op = sign(op)
B = int(B)
calc = int(A op B)
print(calc) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s651991336 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a, op, b = map(str, input().split())
a = int(a)
b = int(b)
if op == "+":
result = a + b
else:
result = a - b
print(result) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s034941058 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | a,op,b = map(str,input().split())
if op = '+':
print(int(a)+int(b))
else:
print(int(a)-int(b)) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Evaluate the formula and print the result.
* * * | s096297840 | Runtime Error | p03844 | The input is given from Standard Input in the following format:
A op B | A, op, B = input().split()
A, B = int(A), int(B)
if op == '+'
print(A + B)
else:
print(A - B) | Statement
Joisino wants to evaluate the formula "A op B". Here, A and B are integers,
and the binary operator op is either `+` or `-`. Your task is to evaluate the
formula instead of her. | [{"input": "1 + 2", "output": "3\n \n\nSince 1 + 2 = 3, the output should be 3.\n\n* * *"}, {"input": "5 - 7", "output": "-2"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.