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 abbreviation of the name of the contest. * * *
s497548998
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("A" + input()[7] + "C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s393624648
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
l = input().split() print(l[0] + l[1][0] + l[2])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s956779010
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("A%sC" % input()[0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s196741903
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
s = input() print('A{}C'.format(s[8])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s576878756
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print(f"A{input().split()[1][0]}C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s424556442
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("A%sC" % input[8])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s704290082
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print(input().split()[1][0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s268812845
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print(A + input()[8] + C)
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s696965849
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("A" + input()[8] + "c")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s333241185
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print(input()[int(input()) - 1])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s295120326
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
b = input().split print("A" + b[1] + "c")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s135107777
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
s1, s2, s3 = map( str, input().split() ) print( "A" + list(s2)[0] + "C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s077801648
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("A" + input() + "C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s121842541
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
data = [i for i in input().split()] print("A{}C".format(data[1][0]))
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s222045153
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
[print(s, end="") for s in map(lambda x: x[0].upper(), input().split())]
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s474624105
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
a = [i for i in input().split()] print("{}{}{}".format(a[0][0], a[1][0], a[2][0]))
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s647562862
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
mozi = list(map(list, input().split())) print(mozi[0][0] + mozi[1][0] + mozi[2][0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s515661618
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
name = input().split() print(name[0][0] + name[1][0] + name[2][0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s351771610
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
if sorted([int(_) for _ in input().split()]) == [5, 5, 7]: print("YES") else: print("NO")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s935219555
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
a, b, x = [int(i) for i in input().split()] count = 0 count = [_ for i in range(a, b + 1) if i % x == 0] print(len(count)) """for i in range(a,b+1): if(i%x==0): count+=1 print(count)"""
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s385488278
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("".join([i[0] for i in input().split()]))
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s829800184
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
abc = list(input().split()) print("A" + abc[1][0] + "C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s452968539
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
A, S, C = input().split() print(A[0] + S[0] + C[0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s108860210
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
line = input().split() print("A" + line[1][0] + "C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s967060490
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
c = list(map(int, input().split())) print(str[1])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s647828046
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
x = str(input().split()[1]) print("A{}C".format(x))
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s631711046
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
num1 = list(input().split()) print("A" + num1[1][0] + "C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s638051812
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("".join(w[0] for w in input().upper().split()))
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s813245487
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
[print(s, end="") for s in map(lambda x: x[0], input().split())]
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s098090741
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
a, b, s = input().split() print(list(a)[0] + list(b)[0] + list(s)[0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s416561801
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
A, X, C = map(int, input().split()) print(A[0] + X[0] + C[0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s854427741
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
A = list(input()) print("A" + A[8] + "C")
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s399253740
Accepted
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
X = input() print(X[0] + X[8] + X[-7])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s906179834
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
input("A%sC" % input()[0])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s010344151
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("A"%s"C"%input()[8])
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s241138651
Wrong Answer
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
print("A%sC" % input())
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the abbreviation of the name of the contest. * * *
s319786641
Runtime Error
p03860
The input is given from Standard Input in the following format: AtCoder s Contest
wk = input().split() print(A + wk[1][0] + C)
Statement Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
[{"input": "AtCoder Beginner Contest", "output": "ABC\n \n\nThe contest in which you are participating now.\n\n* * *"}, {"input": "AtCoder Snuke Contest", "output": "ASC\n \n\nThis contest does not actually exist.\n\n* * *"}, {"input": "AtCoder X Contest", "output": "AXC"}]
Print the answer. * * *
s845572085
Wrong Answer
p03499
Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N}
(n,) = map(int, input().split()) p = [-1] + [*map(int, input().split())] MOD = 10**9 + 7 dp = [[] for _ in range(n + 1)] dep = [0] * (n + 1) nxt = [0] * (n + 1) for v in range(n, 0, -1): _, nxt[p[v]], dep[p[v]] = sorted([nxt[p[v]], dep[p[v]], dep[v] + 1]) tot = [0] * (dep[0] + 1) for i in range(n + 1): tot[dep[i]] += 1 def merge(p, v): if len(dp[p]) < len(dp[v]): dp[p], dp[v] = dp[v], dp[p] for i in range(-len(dp[v]), 0): a, b, c = dp[p][i] d, e, f = dp[v][i] dp[p][i][:] = [a * d % MOD, (b * d + a * e) % MOD, c * f % MOD] for v in range(n, -1, -1): dp[v].append([1, 1, 2]) for i in range(-nxt[v] - 1, 0): dp[v][i][0] = dp[v][i][2] - dp[v][i][1] if v: merge(p[v], v) ans = 0 for d in dp[0]: ans += pow(d[2], MOD - 2, MOD) * d[1] % MOD print(ans * pow(2, n + 1, MOD) % MOD) print(1)
Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find **the number of marbles that will be in the box at the end of the play** , and compute the sum of all those numbers modulo 1,000,000,007.
[{"input": "2\n 0 0", "output": "8\n \n\nWhen we place a marble on both Vertex 1 and 2, there will be multiple marbles\non Vertex 0 by step 2. In such a case, these marbles will be removed instead\nof being moved to the box.\n\n* * *"}, {"input": "5\n 0 1 1 0 4", "output": "96\n \n\n* * *"}, {"input": "31\n 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23", "output": "730395550\n \n\nBe sure to compute the sum modulo 1,000,000,007."}]
Print the answer. * * *
s864907802
Runtime Error
p03499
Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N}
n, k = map(int, input().split()) a = list(map(int, input().split())) cnt = {} for i in a: if i in cnt.keys(): cnt[i] += 1 else: cnt[i] = 1 cnt = sorted(cnt.items(), key=lambda x: x[1]) ans, k = 0, k - len(cnt) for i in range(len(cnt) + 1): if 0 <= k: print(ans) break ans += cnt[i] k -= 1
Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find **the number of marbles that will be in the box at the end of the play** , and compute the sum of all those numbers modulo 1,000,000,007.
[{"input": "2\n 0 0", "output": "8\n \n\nWhen we place a marble on both Vertex 1 and 2, there will be multiple marbles\non Vertex 0 by step 2. In such a case, these marbles will be removed instead\nof being moved to the box.\n\n* * *"}, {"input": "5\n 0 1 1 0 4", "output": "96\n \n\n* * *"}, {"input": "31\n 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23", "output": "730395550\n \n\nBe sure to compute the sum modulo 1,000,000,007."}]
Print the answer. * * *
s818517902
Wrong Answer
p03499
Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N}
#!/usr/bin/python # -*- coding: utf-8 -*- import sys import math import collections (N,) = list(map(int, sys.stdin.readline().rstrip().split())) Ps = list(map(int, sys.stdin.readline().rstrip().split())) tree = collections.defaultdict(list) for i, P in enumerate(Ps): tree[P].append(i + 1) collisions = [0 for _ in range(N + 1)] visited = 0 current_levels = [0] # sames = [1] while visited < N + 1: next_levels = [] for n in current_levels: if n in tree: for t in tree[n]: collisions[t] = collisions[n] + len(tree[n]) - 1 next_levels += tree[n] visited += len(current_levels) # sames.append(len(current_levels)) current_levels = next_levels result = 0 c = 1 collision_cache = [0 for _ in range(N + 1)] collision_cache[N] = c for i in range(N): c = c * 2 % 1000000007 collision_cache[N - 1 - i] = c for collision in collisions: # print(collision) result += collision_cache[collision] result = result % 1000000007 # print(math.pow(2, N - collision)) # print(collision_cache[collision]) # result += math.pow(2, N - collision) # result = result % 1000000007 # for same in sames: # print(same, math.pow(2, N + 1 - same)) # result += same * math.pow(2, N + 1 - same) % 1000000007 print(result) # print(Ps) # print(collisions) exit(0)
Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find **the number of marbles that will be in the box at the end of the play** , and compute the sum of all those numbers modulo 1,000,000,007.
[{"input": "2\n 0 0", "output": "8\n \n\nWhen we place a marble on both Vertex 1 and 2, there will be multiple marbles\non Vertex 0 by step 2. In such a case, these marbles will be removed instead\nof being moved to the box.\n\n* * *"}, {"input": "5\n 0 1 1 0 4", "output": "96\n \n\n* * *"}, {"input": "31\n 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23", "output": "730395550\n \n\nBe sure to compute the sum modulo 1,000,000,007."}]
Print the answer. * * *
s398196874
Runtime Error
p03499
Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N}
import sys input = sys.stdin.readline from collections import deque MOD = 10**9 + 7 N = int(input()) graph = [[] for _ in range(N + 1)] for i, x in enumerate(input().rstrip().split(), 1): x = int(x) graph[i].append(x) graph[x].append(i) # 各深さから来ている (0個、1個、2個以上) の分布を 確率 mod MODで持つ。 half = (MOD + 1) // 2 def merge(dp, dp1): L = len(dp1) for i in range(L): # 0個,1個,2個以上 a, b, c = dp[i] d, e, f = dp1[i] a, b, c = a * d, a * e + b * d, a * f + b * e + b * f + c * d + c * e + c * f a %= MOD b %= MOD c %= MOD dp[i] = (a, b, c) return def dfs(v, parent=None): dp = None L = 0 for u in graph[v]: if u == parent: continue dp1 = dfs(u, v) if dp is None: dp = dp1 else: if len(dp) < len(dp1): dp, dp1 = dp1, dp # 2個以上が入っているインデックス if L < len(dp1): L = len(dp1) merge(dp, dp1) if dp is None: dp = deque() else: # 2個以上あるときに、0個化する for i in range(L): a, b, c = dp[i] dp[i] = (a + c, b, 0) dp.appendleft((half, half, 0)) return dp dp = dfs(0) answer = sum(b for a, b, c in dp) answer *= pow(2, N + 1, MOD) answer %= MOD print(answer)
Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find **the number of marbles that will be in the box at the end of the play** , and compute the sum of all those numbers modulo 1,000,000,007.
[{"input": "2\n 0 0", "output": "8\n \n\nWhen we place a marble on both Vertex 1 and 2, there will be multiple marbles\non Vertex 0 by step 2. In such a case, these marbles will be removed instead\nof being moved to the box.\n\n* * *"}, {"input": "5\n 0 1 1 0 4", "output": "96\n \n\n* * *"}, {"input": "31\n 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23", "output": "730395550\n \n\nBe sure to compute the sum modulo 1,000,000,007."}]
Print the answer. * * *
s432070594
Wrong Answer
p03499
Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N}
MOD = 10**9 + 7 N = int(input()) plist = list(map(int, input().split())) def powmod(a, p): if p == 0: return 1 elif p == 1: return a else: pow2 = powmod(a, p // 2) if p % 2 == 0: return (pow2**2) % MOD else: return (a * pow2**2) % MOD def invmod(a): return powmod(a, MOD - 2) graph = [] graph_rev = [] for i in range(N + 1): graph.append([]) graph_rev.append([]) for i in range(N): graph[i + 1].append(plist[i]) graph_rev[plist[i]].append(i + 1) # print(graph) # print(graph_rev) num_box = 0 pow_2n = powmod(2, N) ball_list = [pow_2n] * (N + 1) # print(ball_list) while sum(ball_list) > 0: # print(num_box,ball_list) for i in range(N + 1): if i == 0: num_box += ball_list[0] num_box %= MOD ball_list[i] = 0 ball_sum = 0 for v in graph_rev[i]: ball_sum += ball_list[v] num_v = len(graph_rev[i]) if num_v == 1: ball_list[i] = ball_sum else: ball_list[i] = ball_sum * num_v * invmod(powmod(2, num_v)) ball_list[i] %= MOD print(num_box)
Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find **the number of marbles that will be in the box at the end of the play** , and compute the sum of all those numbers modulo 1,000,000,007.
[{"input": "2\n 0 0", "output": "8\n \n\nWhen we place a marble on both Vertex 1 and 2, there will be multiple marbles\non Vertex 0 by step 2. In such a case, these marbles will be removed instead\nof being moved to the box.\n\n* * *"}, {"input": "5\n 0 1 1 0 4", "output": "96\n \n\n* * *"}, {"input": "31\n 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23", "output": "730395550\n \n\nBe sure to compute the sum modulo 1,000,000,007."}]
Print the answer. * * *
s457989248
Wrong Answer
p03499
Input is given from Standard Input in the following format: N p_1 p_2 ... p_{N}
#!/usr/bin/env python3 import sys sys.setrecursionlimit(202020) def powmod(a, x, m): y = 1 while 0 < x: if x % 2 == 1: y *= a y %= m x //= 2 a = a**2 a %= m return y M = 10**9 + 7 I2 = powmod(2, M - 2, M) def dfs(g, v): r = [I2] if len(g[v]) == 0: return r cr = [] for w in g[v]: cr.append(dfs(g, w)) cr.sort(key=lambda v: -len(v)) d_max = len(cr[0]) for j in range(d_max): pr = 1 sm = 0 nc = 0 for cri in cr: if len(cri) <= j: break c = cri[j] pr *= c pr %= M sm += powmod(c, M - 2, M) sm %= M nc += 1 pr *= sm + M - nc pr %= M pp = 1 + M - pr pp %= M r.append(pp) return r def solve(n, p): g = [[] for _ in range(n + 1)] for i in range(n): g[p[i]].append(i + 1) r = dfs(g, 0) ans = 0 P2 = powmod(2, n, M) for c in r: ans += P2 * (1 + M - c) ans %= M return ans def main(): n = input() n = int(n) p = list(map(int, input().split())) print(solve(n, p)) if __name__ == "__main__": main()
Statement Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many marbles, and playing with them. The play begins with placing one marble on some of the vertices, then proceeds as follows: 1. If there is a marble on Vertex 0, move the marble into the box. 2. Move each marble from the vertex to its parent (all at once). 3. For each vertex occupied by two or more marbles, remove all the marbles from the vertex. 4. If there exists a vertex with some marbles, go to Step 1. Otherwise, end the play. There are 2^{N+1} ways to place marbles on some of the vertices. For each of them, find **the number of marbles that will be in the box at the end of the play** , and compute the sum of all those numbers modulo 1,000,000,007.
[{"input": "2\n 0 0", "output": "8\n \n\nWhen we place a marble on both Vertex 1 and 2, there will be multiple marbles\non Vertex 0 by step 2. In such a case, these marbles will be removed instead\nof being moved to the box.\n\n* * *"}, {"input": "5\n 0 1 1 0 4", "output": "96\n \n\n* * *"}, {"input": "31\n 0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23", "output": "730395550\n \n\nBe sure to compute the sum modulo 1,000,000,007."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s680610506
Wrong Answer
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") AZ = "abcdefghijklmnopqrstuvwxyz" ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####MakePrimes###### def make_primes(N): max = int(math.sqrt(N)) seachList = [i for i in range(2, N + 1)] primeNum = [] while seachList[0] <= max: primeNum.append(seachList[0]) tmp = seachList[0] seachList = [i for i in seachList if i % tmp != 0] primeNum.extend(seachList) return primeNum #####GCD##### def gcd(a, b): while b: a, b = b, a % b return a #####LCM##### def lcm(a, b): return a * b // gcd(a, b) #####BitCount##### def count_bit(n): count = 0 while n: n &= n - 1 count += 1 return count #####ChangeBase##### def base_10_to_n(X, n): if X // n: return base_10_to_n(X // n, n) + [X % n] return [X % n] def base_n_to_10(X, n): return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X)))) def base_10_to_n_without_0(X, n): X -= 1 if X // n: return base_10_to_n_without_0(X // n, n) + [X % n] return [X % n] #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N, W = IL() data = ILL(N) dp = [[0 for w in range(W + 1)] for i in range(N + 1)] for i in range(N): w0, v0 = data[i] for w in range(W): if w + w0 <= W: dp[i + 1][w + w0] = max(dp[i][w + w0], dp[i][w] + v0) print(max(dp[-1]))
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s149952372
Accepted
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
""" =============================== -- @uthor : Kaleab Asfaw -- Handle : kaleabasfaw2010 -- Bio : High-School Student ===============================""" # Fast IO import sys import os from io import BytesIO, IOBase 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") # Others # from math import floor, ceil, gcd # from decimal import Decimal as d mod = 10**9 + 7 def lcm(x, y): return (x * y) / (gcd(x, y)) def fact(x, mod=mod): ans = 1 for i in range(1, x + 1): ans = (ans * i) % mod return ans def arr2D(n, m, default=0): lst = [] for i in range(n): temp = [default] * m lst.append(temp) return lst def sortDictV(x): return {k: v for k, v in sorted(x.items(), key=lambda item: item[1])} def solve(n, W, weight, value): dp = arr2D(n + 1, W + 1) for i in range(1, n + 1): for j in range(1, W + 1): # print(i, j) val = max(dp[i][j - 1], dp[i - 1][j]) if j >= weight[i - 1]: dp[i][j] = max(val, dp[i - 1][j - weight[i - 1]] + value[i - 1]) else: dp[i][j] = val return dp[n][W] n, W = list(map(int, input().split())) weight = [] value = [] for i in range(n): a, b = list(map(int, input().split())) weight.append(a) value.append(b) print(solve(n, W, weight, value))
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s613108679
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
from sys import stdin, gettrace if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def main(): dn,w=map(int,input().split()) li=[] for i in range(n): temp=[int(x) for x in input().split()] li.append(temp) dp=[[[-1,-1] for j in range(w+1)] for i in range(n)] dp[n-1][0]=[li[n-1][1],li[n-1][1]] for i in range(n-1,-1,-1): for j in range(w,-1,-1): if j==0: dp[i][j]=li[i][1],li[i][1] if i==(n-1): if li[i][0]<=j: dp[i][j]=li[i][1],li[i][1] else: dp[i][j]=0,0 else: mx=li[i][1] for k in range(i+1,n): if (j-li[i][0])>=li[k][0]: val=dp[k][j-li[i][0]] mx=max(mx,val[0]+li[i][1]) val=dp[i+1][j] overall=max(mx,val[1]) dp[i][j]=[mx,overall] print(dp[0][w][1]) if __name__ == "__main__": main()
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s573500015
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
from sys import stdin, gettrace if not gettrace(): def input(): return next(stdin)[:-1] # def input(): # return stdin.buffer.readline() def main(): n,w=map(int,input().split()) li=[] for i in range(n): temp=[int(x) for x in input().split()] li.append(temp) dp=[[[-1,-1] for j in range(w+1)] for i in range(n)] dp[n-1][0]=[li[n-1][1],li[n-1][1]] for i in range(n-1,-1,-1): for j in range(w,-1,-1): if j==0: dp[i][j]=li[i][1],li[i][1] if i==(n-1): if li[i][0]<=j: dp[i][j]=li[i][1],li[i][1] else: dp[i][j]=0,0 else: mx=li[i][1] for k in range(i+1,n): if (j-li[i][0])>=li[k][0]: val=dp[k][j-li[i][0]] mx=max(mx,val[0]+li[i][1]) val=dp[i+1][j] overall=max(mx,val[1]) dp[i][j]=[mx,overall] print(dp[0][w][1]) if __name__ == "__main__": main()
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s452476504
Wrong Answer
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
N, W = map(int, input().rstrip().split(" ")) wv = [[0, 0, 0] for _ in range(N)] ans = [0, 0] for i in range(N): p = list(map(int, input().rstrip().split(" "))) wv[i][1] = p[0] wv[i][2] = p[1] wv[i][0] = p[1] / p[0] wv.sort() wv.reverse() for i in range(N): if wv[i][1] + ans[0] < W: ans[0] += wv[i][1] ans[1] += wv[i][2] print(ans[1])
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s086812952
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
import java.util.*; public class Main{ public static void main(String args[]){ Scanner in = new Scanner(System.in); int N = in.nextInt(); int W = in.nextInt(); int w[] = new int[N]; int v[] = new int[N]; for(int i=0;i<N;i++){ w[i] = in.nextInt(); v[i] = in.nextInt(); } in.close(); long dp[][] = new long[N+1][W+1]; for(int i=0;i<W+1;i++){ dp[N][i] = 0; } for(int i=N-1;i>=0;i--){ for(int j=0;j<W+1;j++){ if(j < w[i]){ dp[i][j] = dp[i+1][j]; } else{ dp[i][j] = Math.max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]); } } } System.out.println(dp[0][W]); } }
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s262757573
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
#include<bits/stdc++.h> using namespace std; int main(){ #ifndef ONLINE_JUDGE freopen("D:\\input.txt", "r", stdin); freopen("D:\\out.txt", "w", stdout); #endif int n,w; cin>>n>>w; int weights[n]; int values[n]; for(int i=0;i<n;i++){ cin>>weights[i]>>values[i]; } long long dp[n+1][w+1]; for(int i=0;i<n+1;i++){ dp[i][0] = 0; } for(int i=0;i<w+1;i++){ dp[0][i] = 0; } for(int i = 1;i < n+1;i++){ for(int j = 1;j<w+1;j++){ if(j < weights[i-1]){ dp[i][j] = dp[i-1][j]; } else{ dp[i][j] = max(dp[i-1][j],dp[i-1][max(0,j-weights[i-1])]+values[i-1]); } } } cout << dp[n][w] << endl; return 0; }
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s326739156
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
from sys import stdin input = stdin.readline def main(): N, W = map(int, input().split()) wv = list(map(int, input().split()) for _ in range(N)) dp = [0] * (W + 1) for w, v in wv: for i in range(W, w - 1a, -1): dp[i] = max(dp[i], dp[i - w] + v) print(dp[-1]) if __name__ == '__main__': main()
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s399358890
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
def main() import numpy as np import sys input = sys.stdin.readline n,w = map(int,input().split()) l = [list(map(int,input().split())) for i in range(n)] dp = np.zeros(n+1,w+1) for i in range(n): dp[i+1,l[i][0]:] = np.maximum(dp[i,l[i][0]:],dp[i,-l[i][0]]+l[i][1]) print(dp[n][w]) if __name__ == "__main__": main()
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s246394701
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
import sys input = sys.stdin.readline def nap(n, cap): val = [0] * (cap + 1) for _ in range(n): w, v = map(int, input().split()) for wk in range(cap, w - 1, -1): nv = val[wk - w] + v if val[wk] < nv: val[wk] = nv return max(val) n, cap = map(int, input().split()) print(nap(n, cap)
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s343525972
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
N, W = map(int, input().split()) item = [] for i in range(N): item.append(tuple(map(int, input().split()))) def f(N, W, item): dp = [[0]*(W+1) for i in range(N+1)] for i in range(1, N+1): for j in range(1, W+1): w = j - item[i-1][0] dp[i][j] = max((dp[i-1][w]+item[i-1][1])*(w>=0), dp[i-1][j]) return dp[N][W] print(f(N, W, item)
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s151661344
Wrong Answer
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
# Atcoder Knapsack 1 items, cap = map(int, input().strip().split()) weight = [0] * items value = [0] * items for i in range(items): weight[i], value[i] = map(int, input().strip().split()) zipped = zip(value, weight) tup = [(x, y) for x, y in sorted(zipped, reverse=True)] newvalue = [x for x, _ in tup] newweight = [x for _, x in tup] # print(newweight, newvalue) total = 0 i = 0 while i < items: if cap >= newweight[i]: cap -= newweight[i] total += newvalue[i] i += 1 print(total)
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s418105917
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
import sys import numba as nb input = sys.stdin.readline @nb.njit N, W = map(int, input().split()) x = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0] * (W + 1) for _ in range(N + 1)] for i, (w, v) in enumerate(x, 1): dpi = dp[i] dpim = dp[i-1] for j in range(1, W + 1): if w <= j: a = dpim[j - w] + v if a > dpim[j]: dpi[j] = a else: dpi[j] = dpim[j] else: dpi[j] = dpim[j] print(dp[-1][W])
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s052806108
Runtime Error
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
N,W = map(int,input().split()) w=[] v=[] for i in range(N): x,y = map(int,input().split()) w.append(x) v.append(y) ans = [0] def knap(index,W,temp): #base case if index == len(w): ans[0] = max(ans[0],temp) if W - w[index] >= 0: return max(v[index]+knap(index + 1,W-w[index],temp+v[index]) , knap(index+1 , W,temp)) else: return knap(index+1,W,temp) knap(0,W,0) print(ans[0])
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s418015799
Accepted
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
# coding: utf-8 import re import math import itertools from copy import deepcopy import fractions import random from functools import lru_cache from heapq import heappop, heappush import time import sys readline = sys.stdin.readline sys.setrecursionlimit(2000) # import numpy as np alphabet = "abcdefghijklmnopqrstuvwxyz" mod = int(10**9 + 7) inf = int(10**20) def yn(b): if b: print("yes") else: print("no") def Yn(b): if b: print("Yes") else: print("No") def YN(b): if b: print("YES") else: print("NO") class union_find: def __init__(self, n): self.n = n self.P = [a for a in range(N)] self.rank = [0] * n def find(self, x): if x != self.P[x]: self.P[x] = self.find(self.P[x]) return self.P[x] def same(self, x, y): return self.find(x) == self.find(y) def link(self, x, y): if self.rank[x] < self.rank[y]: self.P[x] = y elif self.rank[y] < self.rank[x]: self.P[y] = x else: self.P[x] = y self.rank[y] += 1 def unite(self, x, y): self.link(self.find(x), self.find(y)) def size(self): S = set() for a in range(self.n): S.add(self.find(a)) return len(S) def bin_(num, size): A = [0] * size for a in range(size): if (num >> (size - a - 1)) & 1 == 1: A[a] = 1 else: A[a] = 0 return A def fac_list(n, mod_=0): A = [1] * (n + 1) for a in range(2, len(A)): A[a] = A[a - 1] * a if mod > 0: A[a] %= mod_ return A def comb(n, r, mod, fac): if n - r < 0: return 0 return (fac[n] * pow(fac[n - r], mod - 2, mod) * pow(fac[r], mod - 2, mod)) % mod def next_comb(num, size): x = num & (-num) y = num + x z = num & (~y) z //= x z = z >> 1 num = y | z if num >= (1 << size): return False else: return num def get_primes(n, type="int"): A = [True] * (n + 1) A[0] = False A[1] = False for a in range(2, n + 1): if A[a]: for b in range(a * 2, n + 1, a): A[b] = False if type == "bool": return A B = [] for a in range(n + 1): if A[a]: B.append(a) return B def is_prime(num): if num <= 2: return False i = 2 while i * i <= num: if num % i == 0: return False i += 1 return True def join(A, c=" "): n = len(A) A = list(map(str, A)) s = "" for a in range(n): s += A[a] if a < n - 1: s += c return s # main N, w = map(int, input().split()) W = [0] * N V = [0] * N for a in range(N): W[a], V[a] = map(int, input().split()) dp = [[0 for _ in range(w + 1)] for _ in range(N + 1)] for a in range(1, N + 1): for b in range(1, w + 1): if b - W[a - 1] >= 0: dp[a][b] = max(dp[a - 1][b], dp[a - 1][b - W[a - 1]] + V[a - 1]) else: dp[a][b] = dp[a - 1][b] print(dp[N][w])
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s017977187
Wrong Answer
p03163
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
# D_knapsack 1 N, W = input().split() N = int(N) W = int(W) items = list() for nn in range(N): h = [int(x) for x in input().split()] items.append(h) dp = [[0] * (W + 1) for x in range(N + 1)] for ii in range(N): di = ii + 1 for ww in range(W): dw = ww + 1 if ww >= items[ii][0]: # if we can get ii-th item tmp1 = dp[di][dw] tmp2 = dp[di - 1][dw - items[ii][0] + 1] + items[ii][1] dp[di][dw] = max(tmp1, tmp2) dp[di][dw] = max(dp[di][dw], dp[di - 1][dw]) print(dp[-1][-1])
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "5 5\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000\n 1 1000000000", "output": "5000000000\n \n\nThe answer may not fit into a 32-bit integer type.\n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s038062773
Wrong Answer
p03533
Input is given from Standard Input in the following format: S
print("YES" if input().replace("A", "") == "KIHBR" else "NO")
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s298310131
Accepted
p03533
Input is given from Standard Input in the following format: S
import sys sys.setrecursionlimit(10**6) from math import floor, ceil, sqrt, factorial, log from heapq import heappop, heappush, heappushpop from collections import Counter, defaultdict, deque from itertools import ( accumulate, permutations, combinations, product, combinations_with_replacement, ) from bisect import bisect_left, bisect_right from copy import deepcopy from operator import itemgetter from fractions import gcd mod = 10**9 + 7 inf = float("inf") ninf = -float("inf") # 整数input def ii(): return int(sys.stdin.readline().rstrip()) # int(input()) def mii(): return map(int, sys.stdin.readline().rstrip().split()) def limii(): return list(mii()) # list(map(int,input().split())) def lin(n: int): return [ii() for _ in range(n)] def llint(n: int): return [limii() for _ in range(n)] # 文字列input def ss(): return sys.stdin.readline().rstrip() # input() def mss(): return sys.stdin.readline().rstrip().split() def limss(): return list(mss()) # list(input().split()) def lst(n: int): return [ss() for _ in range(n)] def llstr(n: int): return [limss() for _ in range(n)] # 本当に貪欲法か? DP法では?? # 本当に貪欲法か? DP法では?? # 本当に貪欲法か? DP法では?? # https://atcoder.jp/contests/cf17-final-open/tasks/cf17_final_a s = list(ss()) if len(list(s)) > 9: print("NO") exit() ans = [] kih = ["K", "I", "H"] b = ["B"] r = ["R"] chk = False for i in list(product([0, 1], repeat=4)): a1, a2, a3, a4 = [], [], [], [] if i[0] == 1: a1.append("A") if i[1] == 1: a2.append("A") if i[2] == 1: a3.append("A") if i[3] == 1: a4.append("A") if s == a1 + kih + a2 + b + a3 + r + a4: chk = True # print(a1+kih+a2+b+a3+r+a4) if chk == True: print("YES") else: print("NO")
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s019463847
Accepted
p03533
Input is given from Standard Input in the following format: S
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**15 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): s = S() t = "AKIHABARA" l = len(t) ti = 0 for c in s: if ti >= l: return "NO" if t[ti] == c: ti += 1 else: while ti < l and t[ti] == "A" and t[ti] != c: ti += 1 if ti >= l or t[ti] != c: return "NO" ti += 1 while ti < l and t[ti] == "A": ti += 1 if ti == l: return "YES" return "NO" print(main())
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s177663976
Wrong Answer
p03533
Input is given from Standard Input in the following format: S
a = input() if a.replace("A", "") == "KIHBR": print("Yes") else: print("No")
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s904547581
Wrong Answer
p03533
Input is given from Standard Input in the following format: S
S = input() N = len(S) K, I, H, B, R = S.find("K"), S.find("I"), S.find("H"), S.find("B"), S.find("R") print( "YES" if (K == 0 or K == 1) and K == I - 1 == H - 2 and (H + 1 == B or S[H + 1] == "A") and (B + 1 == R or S[B + 1] == "A") and (R == N - 2 and S[R + 1] == "A" or R == N - 1) else "NO" )
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s612536255
Wrong Answer
p03533
Input is given from Standard Input in the following format: S
need = ["K", "I", "H", "B", "R"] noneed = [ "C", "D", "E", "F", "G", "J", "L", "M", "N", "O", "P", "Q", "S", "T", "U", "V", "W", "X", "Y", "Z", ] s = "KIHBRC" def judge(s: str) -> bool: pos = [0] * 5 for i, c in enumerate(need): if s.count(c) != 1: return False else: pos[i] = s.index(c) for c in noneed: if s.count(c) != 0: return False if pos[0] > 2: return False if pos[1] - pos[0] > 1: return False if pos[2] - pos[1] > 1: return False if pos[3] - pos[2] > 2: return False if pos[4] - pos[3] > 2: return False if len(s) - pos[4] > 2: return False return True print(judge(s))
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s426774682
Wrong Answer
p03533
Input is given from Standard Input in the following format: S
print("YNEOS"[input() in ["KIHABARA", "AKIHBARA", "AKIHABRA", "AKIHABAR"] :: 2])
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s212447694
Runtime Error
p03533
Input is given from Standard Input in the following format: S
2import re print('Yes' if re.match('A?KIHA?BA?RA?', input()) else 'No')
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s953477539
Accepted
p03533
Input is given from Standard Input in the following format: S
a = input() R = int(len(a)) if ( a == "KIHBR" or a == "KIHBRA" or a == "KIHBAR" or a == "KIHBARA" or a == "KIHABR" or a == "KIHABRA" or a == "KIHABAR" or a == "KIHABARA" or a == "AKIHBR" or a == "AKIHBRA" or a == "AKIHBAR" or a == "AKIHBARA" or a == "AKIHABR" or a == "AKIHABRA" or a == "AKIHABAR" or a == "AKIHABARA" ): print("YES") else: print("NO")
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
If it is possible to change S into `AKIHABARA`, print `YES`; otherwise, print `NO`. * * *
s170405932
Accepted
p03533
Input is given from Standard Input in the following format: S
S = input() origin = ["", "K", "I", "H", "", "B", "", "R", ""] idx = [0, 4, 6, 8] candidate = [] for state in range(1 << 4): tmp = origin[:] for i in range(4): if state >> i & 1: tmp[idx[i]] = "A" candidate.append("".join(tmp)) print("YES" if S in candidate else "NO")
Statement You are given a string S. Takahashi can insert the character `A` at any position in this string any number of times. Can he change S into `AKIHABARA`?
[{"input": "KIHBR", "output": "YES\n \n\nInsert one `A` at each of the four positions: the beginning, immediately after\n`H`, immediately after `B` and the end.\n\n* * *"}, {"input": "AKIBAHARA", "output": "NO\n \n\nThe correct spell is `AKIHABARA`.\n\n* * *"}, {"input": "AAKIAHBAARA", "output": "NO"}]
Print the maximum possible distance of A and B. * * *
s472296084
Wrong Answer
p02908
Input is given from Standard Input in the following format: N P_0 P_1 \cdots P_{N-1} Q_0 Q_1 \cdots Q_{N-1}
import networkx as nx from networkx.algorithms.flow import dinitz import sys def input(): return sys.stdin.readline()[:-1] G = nx.Graph() n = int(input()) p = list(map(int, input().split())) q = list(map(int, input().split())) G.add_nodes_from(list(range(2 * n + 2))) S, T = 2 * n, 2 * n + 1 INF = 10**6 for i in range(2 * n): if i < n: if p[i] != i: G.add_edge(p[i], i, capacity=INF) if p[i] == q[i]: G.add_edge(i + n, i, capacity=1) else: G.add_edge(S, i, capacity=INF) G.add_edge(i, i + n, capacity=1) else: if q[i - n] != i - n: G.add_edge(i, q[i - n] + n, capacity=INF) else: G.add_edge(i, T, capacity=INF) R = dinitz(G, S, T) cut = int(R.graph["flow_value"]) # print(cut) ans = n - cut print(ans)
Statement Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1). Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions: * For each i (0 \leq i \leq N-1), A_i should be i or P_i. * For each i (0 \leq i \leq N-1), B_i should be i or Q_i. Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
[{"input": "4\n 2 1 3 0\n 0 2 3 1", "output": "3\n \n\nFor example, if we make A=(0,1,2,3) and B=(0,2,3,1), the distance will be 3,\nwhich is the maximum result possible.\n\n* * *"}, {"input": "10\n 0 4 5 3 7 8 2 1 9 6\n 3 8 5 6 4 0 2 1 7 9", "output": "8\n \n\n* * *"}, {"input": "32\n 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13\n 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31", "output": "28"}]
Print the maximum possible distance of A and B. * * *
s140006100
Wrong Answer
p02908
Input is given from Standard Input in the following format: N P_0 P_1 \cdots P_{N-1} Q_0 Q_1 \cdots Q_{N-1}
from collections import deque # 枝を表すクラス # altは逆の枝を表す class Edge: def __init__(self, from_v, to_v, cap): self.from_v = from_v self.to_v = to_v self.cap = cap self.alt = None # 頂点を表すクラス class Vertex: def __init__(self, id): self.id = id self.edge_list = [] # グラフを表すクラス class Graph: # 初期化する # vnumは頂点数を表す # s_vは始点、t_vは終点を表す def __init__(self, vnum): self.__vertex_list = [Vertex(i) for i in range(vnum + 2)] self.__edge_list = [] # 枝を追加する def add_edge(self, from_id, to_id, cap): from_v = self.vertex(from_id) to_v = self.vertex(to_id) normal_edge = Edge(from_v, to_v, cap) reverse_edge = Edge(to_v, from_v, 0) normal_edge.alt = reverse_edge reverse_edge.alt = normal_edge from_v.edge_list.append(normal_edge) to_v.edge_list.append(reverse_edge) self.__edge_list.append(normal_edge) self.__edge_list.append(reverse_edge) def vertex(self, id): return self.__vertex_list[id] # 辺の状況をprintする def print_edge(self): for i in range(len(self.__edge_list)): print("[f_v={}, ".format(self.__edge_list[i].from_v.id), end="") print("t_v={}, ".format(self.__edge_list[i].to_v.id), end="") print("cap={}]".format(self.__edge_list[i].cap)) # print(self.__edge_list.from_v) # print(self.__edge_list.to_v) # print(self.__edge_list.cap) # print(self.__edge_list.alt) class MaxFlow: # def __init__(self, graph, s_id, t_id): self.graph = graph self.s_v = graph.vertex(s_id) self.t_v = graph.vertex(t_id) self.dq = deque() self.from_dict = dict() def calc(self): f = 0 while self.find_path(): f += 1 # デバッグ用 self.graph.print_edge() print("f = {}".format(f)) # self.from_dict.clear() # self.from_dict = dict() return f # sからtへのパスを一つ見つけ、そのパス上の枝の容量を0にし、 # 逆の枝の容量を1にする # 経路が見つかればTrue,見つからなければFalseを返す def find_path(self): # -1はfrom_idとして不正な値 self.put_q(self.s_v, None) s_id = self.s_v.id t_id = self.t_v.id while len(self.dq) > 0: v = self.dq.popleft() v_id = v.id # print(self.from_dict) if v_id == t_id: # from_dictを使ってs_vまでの経路をたどる while v_id != s_id: n_e = self.from_dict[v_id] r_e = n_e.alt n_e.cap = 0 r_e.cap = 1 v_id = n_e.from_v.id return True # vに接続した枝eのうち、以下の条件を満たしたものを探す # * eの容量が1である # * e.toがfrom_dictに含まれていない for e in v.edge_list: if e.cap == 0: continue if e.to_v in self.from_dict: continue self.put_q(e.to_v, e) return False # vをqに積む、from_dictにvに至る枝eを記録する def put_q(self, v, e): self.dq.append(v) self.from_dict[v.id] = e if __name__ == "__main__": def make_graph1(): g1 = Graph(2) s1 = 0 t1 = 1 g1.add_edge(s1, t1, 1) return g1, s1, t1 g1, s1, t1 = make_graph1() mf1 = MaxFlow(g1, s1, t1) f1 = mf1.calc() print("f1 ={}".format(f1)) def make_graph2(): g = Graph(4) s = 0 a = 1 b = 2 t = 3 g.add_edge(s, a, 1) g.add_edge(s, b, 1) g.add_edge(a, b, 1) g.add_edge(a, t, 1) g.add_edge(b, t, 1) return g, s, t g2, s2, t2 = make_graph2() mf2 = MaxFlow(g2, s2, t2) print("f2 = {}".format(mf2.calc()))
Statement Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1). Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions: * For each i (0 \leq i \leq N-1), A_i should be i or P_i. * For each i (0 \leq i \leq N-1), B_i should be i or Q_i. Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
[{"input": "4\n 2 1 3 0\n 0 2 3 1", "output": "3\n \n\nFor example, if we make A=(0,1,2,3) and B=(0,2,3,1), the distance will be 3,\nwhich is the maximum result possible.\n\n* * *"}, {"input": "10\n 0 4 5 3 7 8 2 1 9 6\n 3 8 5 6 4 0 2 1 7 9", "output": "8\n \n\n* * *"}, {"input": "32\n 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13\n 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31", "output": "28"}]
Print the maximum possible distance of A and B. * * *
s235546749
Wrong Answer
p02908
Input is given from Standard Input in the following format: N P_0 P_1 \cdots P_{N-1} Q_0 Q_1 \cdots Q_{N-1}
N = int(input()) Pn = list(map(int, input().split(" "))) Qn = list(map(int, input().split(" "))) # print(Pn) # print(Qn) GenPn = [x for x in range(N)] # print(GenPn) def distance(Pn, Qn): d = 0 for i in range(len(Pn)): if Pn[i] != Qn[i]: d = d + 1 return d answer = distance(Pn, Qn) answer = max(answer, distance(Pn, GenPn)) answer = max(answer, distance(GenPn, Qn)) print(answer)
Statement Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1). Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions: * For each i (0 \leq i \leq N-1), A_i should be i or P_i. * For each i (0 \leq i \leq N-1), B_i should be i or Q_i. Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
[{"input": "4\n 2 1 3 0\n 0 2 3 1", "output": "3\n \n\nFor example, if we make A=(0,1,2,3) and B=(0,2,3,1), the distance will be 3,\nwhich is the maximum result possible.\n\n* * *"}, {"input": "10\n 0 4 5 3 7 8 2 1 9 6\n 3 8 5 6 4 0 2 1 7 9", "output": "8\n \n\n* * *"}, {"input": "32\n 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13\n 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31", "output": "28"}]
Print the maximum possible distance of A and B. * * *
s965522601
Wrong Answer
p02908
Input is given from Standard Input in the following format: N P_0 P_1 \cdots P_{N-1} Q_0 Q_1 \cdots Q_{N-1}
n = int(input()) list_a = input().split(" ") list_b = input().split(" ") tmp_a = 0 tmp_b = 0 tmp_c = 0 for i in range(0, n): if list_a[i] != str(i): tmp_a += 1 if list_b[i] != str(i): tmp_b += 1 if list_a[i] != list_b[i]: tmp_c += 1 max = tmp_a if max < tmp_b: max = tmp_b if max < tmp_c: max = tmp_c print(max)
Statement Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1). Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions: * For each i (0 \leq i \leq N-1), A_i should be i or P_i. * For each i (0 \leq i \leq N-1), B_i should be i or Q_i. Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
[{"input": "4\n 2 1 3 0\n 0 2 3 1", "output": "3\n \n\nFor example, if we make A=(0,1,2,3) and B=(0,2,3,1), the distance will be 3,\nwhich is the maximum result possible.\n\n* * *"}, {"input": "10\n 0 4 5 3 7 8 2 1 9 6\n 3 8 5 6 4 0 2 1 7 9", "output": "8\n \n\n* * *"}, {"input": "32\n 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13\n 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31", "output": "28"}]
Print the maximum possible distance of A and B. * * *
s675675748
Wrong Answer
p02908
Input is given from Standard Input in the following format: N P_0 P_1 \cdots P_{N-1} Q_0 Q_1 \cdots Q_{N-1}
def mapcount(n): if n != 0: return 1 else: return 0 import numpy as np N = int(input()) P = list(map(int, input().split())) Q = list(map(int, input().split())) V = [i for i in range(N)] npP = np.array(P) npQ = np.array(Q) npV = np.array(V) countPQ = sum(map(mapcount, npP - npQ)) countQV = sum(map(mapcount, npQ - npV)) countVP = sum(map(mapcount, npV - npP)) print(max([countPQ, countQV, countVP]))
Statement Snuke has permutations (P_0,P_1,\cdots,P_{N-1}) and (Q_0,Q_1,\cdots,Q_{N-1}) of (0,1,\cdots,N-1). Now, he will make new permutations A and B of (0,1,\cdots,N-1), under the following conditions: * For each i (0 \leq i \leq N-1), A_i should be i or P_i. * For each i (0 \leq i \leq N-1), B_i should be i or Q_i. Let us define the distance of permutations A and B as the number of indices i such that A_i \neq B_i. Find the maximum possible distance of A and B.
[{"input": "4\n 2 1 3 0\n 0 2 3 1", "output": "3\n \n\nFor example, if we make A=(0,1,2,3) and B=(0,2,3,1), the distance will be 3,\nwhich is the maximum result possible.\n\n* * *"}, {"input": "10\n 0 4 5 3 7 8 2 1 9 6\n 3 8 5 6 4 0 2 1 7 9", "output": "8\n \n\n* * *"}, {"input": "32\n 22 31 30 29 7 17 16 3 14 9 19 11 2 5 10 1 25 18 15 24 20 0 12 21 27 4 26 28 8 6 23 13\n 22 3 2 7 17 9 16 4 14 8 19 26 28 5 10 1 25 18 15 13 11 0 12 23 21 20 29 24 27 6 30 31", "output": "28"}]
Print the maximum total happiness points the children can earn. * * *
s881280168
Accepted
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 N = INT() A = LIST() A = [(a, i) for i, a in enumerate(A)] A.sort(reverse=1) # dp[i][j] := 左にi人、右にj人確定した状態での最大値 dp = list2d(N + 1, N + 1, -INF) dp[0][0] = 0 for i, (a, x) in enumerate(A): # j := 今左に確定してる人数 for j in range(i + 1): # k := 今右に確定してる人数 k = i - j # このaを左にする遷移 y = j dp[j + 1][k] = max(dp[j + 1][k], dp[j][k] + abs(x - y) * a) # このaを右にする遷移 y = N - 1 - k dp[j][k + 1] = max(dp[j][k + 1], dp[j][k] + abs(x - y) * a) ans = 0 for i in range(N + 1): # 左右に計N人決まった状態での最大を取る ans = max(ans, dp[i][N - i]) print(ans)
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s593703667
Accepted
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
def main(): N, *A = map(int, open(0).read().split()) A = sorted(enumerate(A), reverse=True, key=lambda x: x[1]) dp = [[0] * r for r in reversed(range(1, N + 2))] for l in range(N): for r in range(N - l): p, a = A[l + r] dp[l + 1][r] = max(dp[l + 1][r], a * (p - l) + dp[l][r]) dp[l][r + 1] = max(dp[l][r + 1], a * (N - 1 - r - p) + dp[l][r]) print(max(dp[l][N - l] for l in range(N))) main()
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s545737767
Accepted
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = sorted((int(x), k) for k, x in enumerate(input().split())) opt = [[0 for j in range(n + 1)] for i in range(n + 1)] for i in reversed(range(n)): for j in range(i, n): val, k = a[j - i] opt[i][j] = max( val * abs(k - i) + opt[i + 1][j], val * abs(k - j) + opt[i][j - 1] ) print(opt[0][n - 1])
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s081893619
Accepted
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = list(map(int, input().split())) from collections import Counter dp = [[0 for _ in range(n + 1)] for _ in range(n)] cnt = Counter() dic = {} for i in range(n): if dic.get(a[i]) is None: dic[a[i]] = [i] else: dic[a[i]] += [i] cnt[a[i]] += 1 def maximize(rang, pos): lb_rang = 0 ub_rang = len(rang) - 1 lb_pos = 0 ub_pos = len(pos) - 1 ret = 0 while lb_rang <= ub_rang: if abs(rang[lb_rang] - pos[ub_pos]) < abs(rang[ub_rang] - pos[lb_pos]): ret += abs(rang[ub_rang] - pos[lb_pos]) ub_rang -= 1 lb_pos += 1 else: ret += abs(rang[lb_rang] - pos[ub_pos]) lb_rang += 1 ub_pos -= 1 return ret sorted_keys = sorted(cnt.keys()) acm = 0 for x in sorted_keys: num = cnt[x] for i in range(n): if i + acm + num <= n: if acm == 0: dp[i][acm + num] = x * maximize(list(range(i, i + num)), dic[x]) else: for j in range(i, i + num + 1): # print(f"dp[{i}][{acm}+{num}] = max(dp[{i}][{acm}+{num}],dp[{j}][{acm}] + {x}*maximize(list(range({i},{j}))+list(range({j}+{acm},{i}+{acm}+{num})), dic[{x}]))") # print(j,acm,dp[j][acm]) dp[i][acm + num] = max( dp[i][acm + num], dp[j][acm] + x * maximize( list(range(i, j)) + list(range(j + acm, i + acm + num)), dic[x], ), ) acm += num print(max(dp[0]))
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s881549360
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = list(map(int, input().split())) right = 0 left = n - 1 stay = [] l = [] ans = 0 for i in range(n): l.append([a[i], i]) l.sort(reverse=True) for i in range(n): l0 = 0 r0 = 0 for j in range(l[i][1] - 1): r0 = max(r0, a[j]) for j in range(l[i][1] + 1, n): l0 = max(l0, a[j]) r0 = l[i][0] - r0 l0 = l[i][0] - l0 # print(l0,r0) if len(stay) == 0: if (left - l[i][1]) * r0 > (l[i][1] - right) * l0: ans += l[i][0] * (left - l[i][1]) left -= 1 elif (left - l[i][1]) * r0 < (l[i][1] - right) * l0: ans += l[i][0] * (l[i][1] - right) right += 1 else: stay.append(l[i]) a[l[i][1]] = 0 else: k = len(stay) if (left - l[i][1] - k // 2) * r0 > (l[i][1] - right - k // 2) * l0: for j in range(k): if j % 2 == 0: ans += (stay[k - 1 - j][1] - right - k // 2 + j) * stay[k - 1 - j][ 0 ] right += 1 else: ans += (left - stay[k - 1 - j][1] - k // 2 + j) * stay[k - 1 - j][0] left -= 1 ans += l[i][0] * (left - l[i][1]) left -= 1 stay = [] elif (left - l[i][1] - k // 2) * r0 < (l[i][1] - right - k // 2) * l0: for j in range(k): if j % 2 == 1: ans += abs( (stay[k - 1 - j][1] - right - k // 2 + j) * stay[k - 1 - j][0] ) right += 1 else: ans += abs( (left - stay[k - 1 - j][1] - k // 2 + j) * stay[k - 1 - j][0] ) left -= 1 ans += l[i][0] * (l[i][1] - right) right += 1 stay = [] else: stay.append(l[i]) a[l[i][1]] = 0 # print(stay,ans) if len(stay) > 0: k = len(stay) for j in range(k): if j % 2 == 0: ans += abs((stay[k - 1 - j][1] - right - k // 2 + j) * stay[k - 1 - j][0]) right += 1 else: ans += abs((left - stay[k - 1 - j][1] - k // 2 + j) * stay[k - 1 - j][0]) left -= 1 print(ans)
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s209321237
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = [int(INPUT) for INPUT in input().strip().split(" ")] happiness = 0 exist_index = list(range(N)) exist_visited = [0] * N empty_index = list(range(N)) for k in range(N): largest_gain = -1 # print(exist_index, exist_visited, empty_index) for i in range(N): if exist_visited[i] == 1: continue place = ( 0 if abs(exist_index[i] - empty_index[0]) > abs(exist_index[i] - empty_index[-1]) else -1 ) gain = A[exist_index[i]] * abs(exist_index[i] - empty_index[place]) # print(place, gain) if gain > largest_gain: largest_gain = gain best_child = exist_index[i] best_place = place # print("--") # print(largest_gain, best_child) # print("--") happiness += largest_gain exist_visited[best_child] = 1 if best_place == 0: empty_index = empty_index[1:] else: empty_index = empty_index[:-1] # empty_index = empty_index[0:place] + empty_index[place + 1:] print(happiness)
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s138055883
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n, *a = map(int, open(0).read().split()) b = list(range(n)) def f(): for i, x in enumerate(a): for j in range(n): if ( abs(b[i] - i) * a[i] + abs(b[j] - j) * a[j] < abs(b[j] - i) * a[i] + abs(b[i] - j) * a[j] ): b[i], b[j] = b[j], b[i] exec("f();" * 15) print(sum(x * abs(i - b[i]) for i, x in enumerate(a)))
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s142304741
Accepted
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys import numpy as np def f(n, a_): a = [] for i, ai in enumerate(a_): a.append([1 + i, ai]) a.sort(key=lambda x: x[1], reverse=True) dp = np.zeros( (n + 1, n + 1), np.int64 ) # dp[i,j]:i人目までを配置し終えていて、そのうちj人を右に置いた時の最大値。j<=i dp[1, 1] = a[0][1] * (n - a[0][0]) dp[1, 0] = a[0][1] * (a[0][0] - 1) for i in range(2, n + 1): # i人目の幼児。a[i-1] dp[i, 0] = dp[i - 1, 0] + a[i - 1][1] * abs( (a[i - 1][0] - 1 - (i - 1)) ) # i人目を左にする。その時左に溜まっているのはi-1人 dp[i, i] = dp[i - 1, i - 1] + a[i - 1][1] * abs( (n - a[i - 1][0] - (i - 1)) ) # i人目を右にする。その時右に溜まっているのはi-1人 # i人目を左に l = dp[i - 1, 1:i] + [ a[i - 1][1] * abs((a[i - 1][0] - 1 - j)) for j in range(i - 2, -1, -1) ] # j:左に溜まっている人数 # i人目を右に r = dp[i - 1, : i - 1] + [ a[i - 1][1] * abs((n - a[i - 1][0] - j)) for j in range(i - 1) ] # j:右に溜まっている人数 dp[i, 1:i] = np.maximum(l, r) return max(dp[n]) if __name__ == "__main__": input = sys.stdin.readline n = int(input()) a_ = list(map(int, input().split())) print(f(n, a_))
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s836581072
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
NN = 202020 MOD = 10**9 + 7 # MOD = 998244353 INF = float("inf") n = int(input()) A = list(map(int, input().split())) que = [] for i in range(len(A)): for j in range(len(A)): que.append((-A[i] * abs(i - j), abs(i - j), i, j)) que.sort() ans = [-1] * len(A) seen = set() for t in range(len(que)): val, _, i, j = que[t] if ans[j] == -1 and i not in seen: ans[j] = -val seen.add(i) if len(seen) >= len(A): break # print(val, j, ans) # print(ans) print(sum(ans))
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s605509311
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = list(map(int, input().split())) def solve(): happy = [[0] * N for _ in range(N)] pref = [[] for _ in range(N)] for i, a in enumerate(A): for j in range(N): h = abs(j - i) * a happy[i][j] = h pref[i].append((h, j)) pref[i].sort(reverse=True) det = set() res = {} for i in range(N): hbest = -1 arg = None for j in range(N): if j in det: continue for h, pos in pref[j]: if pos in res: continue if hbest < h: hbest = h arg = (j, pos) baby, pos = arg res[pos] = hbest det.add(baby) assert len(det) == N return sum(res.values()) print(solve())
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s863985850
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) As = list(map(int, input().split())) preans = [] for n in range(N): preans.append([n, As[n]]) preans.append(preans.pop(0)) judge = 0 while judge == 0: for _ in range(N - 1): for n in range(N - 1): if abs(preans[n][0] - n) >= abs(preans[n][0] - (n + 1)): ans1 = -preans[n][1] else: ans1 = preans[n][1] if abs(preans[n + 1][0] - (n + 1)) >= abs(preans[n + 1][0] - n): ans2 = -preans[n + 1][1] else: ans2 = preans[n + 1][1] # print(ans1, ans2) if ans1 + ans2 >= 0: preans[n], preans[n + 1] = preans[n + 1], preans[n] else: judge = 1 continue ans = 0 # print(preans) for n in range(N): num = abs(preans[n][0] - n) ans += num * preans[n][1] print(ans)
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s714352889
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import numpy as np N = int(input()) A_list = np.array(list(map(int, input().split()))) arg_list = np.argsort(-A_list) r_fill = 0 l_fill = 0 max_all = 0 for i in range(N): max_value = 0 max_idx = 0 tmp_l_fill = 0 tmp_r_fill = 0 for idx, j in enumerate(arg_list): tmp_max = A_list[j] * max(j - l_fill, N - j - 1 - r_fill) if tmp_max > max_value: max_idx = idx max_value = tmp_max if j - l_fill > N - j - 1 - r_fill: tmp_l_fill = 1 tmp_r_fill = 0 else: tmp_r_fill = 1 tmp_l_fill = 0 r_fill += tmp_r_fill l_fill += tmp_l_fill max_all += max_value print(arg_list, max_value) arg_list = np.concatenate([arg_list[:max_idx], arg_list[max_idx + 1 :]]) print(max_all)
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s302349403
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = list(map(int, input().split())) B = list(range(N)) Aleft = 0 Aright = 0 Aleftlist = [] Arightlist = [] Amax = 0 Amaxmax = 0 Apoint = 0 Bpoint = 0 check = 0 for i in range(N): Amax = 0 Apoint = 0 Bpoint = 0 check = 0 for j in range((N - i) // 2): if Amax < A[B[j]] * (N - i - j): Amax = A[B[j]] * (N - i - j) Apoint = B[j] Bpoint = j for j in range((N - i) // 2, N - i): if Amax < A[B[j]] * j: Amax = A[B[j]] * j Apoint = B[j] Bpoint = 0 check = 1 Amaxmax += Amax A[Apoint] = 0 del B[Bpoint] if check == 0: Aleft += 1 else: Aright += 1 print(Amaxmax)
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s924771818
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) L, R = 0, N - 1 A = [[a, -1] for i, a in enumerate(list(map(int, input().split())))] for _ in range(N): max_p, max_i = -1, -1 for i in range(N): if A[i][1] == -1 and A[i][0] * max(abs(i - L), abs(i - R)) > max_p: max_p, max_i = A[i][0] * max(abs(i - L), abs(i - R)), i if abs(max_i - L) > abs(max_i - R): A[max_i][1], L = L, L + 1 else: A[max_i][1], R = R, R - 1 print(sum([A[i][0] * abs(i - A[i][1]) for i in range(N)]))
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s459727423
Wrong Answer
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
tmp = input().split() NChild = int(tmp[0]) tmp = input().split() Active_List = [int(s) for s in tmp] ArrayD = [0] * NChild for i in range(NChild): ArrayD[i] = [ i + 1, Active_List[i], max(abs(i), abs(NChild - i - 1)), Active_List[i] * max(abs(i), abs(NChild - i - 1)), ] ArrayC = sorted(ArrayD, key=lambda x: (x[3], x[1], x[2]), reverse=True) NArray = [0] * NChild EndP = NChild - 1 StartP = 0 for i in range(NChild): P = ArrayC[i][0] if abs(P - StartP - 1) < abs(P - EndP - 1): NArray[EndP] = P EndP = EndP - 1 else: NArray[StartP] = P StartP = StartP + 1 TotalResult = 0 for i in range(NChild): KeyA = ArrayC.index(ArrayD[NArray[i] - 1]) TotalResult = TotalResult + ArrayC[KeyA][1] * abs(NArray[i] - i - 1) print(TotalResult)
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Print the maximum total happiness points the children can earn. * * *
s656752843
Accepted
p02709
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = sorted([(int(a), i) for i, a in enumerate(input().split())], key=lambda x: x[0])[ ::-1 ] X = [0] + [-1 << 100] * (N + 1) for k, (a, i) in enumerate(A): nX = [0] * (N + 2) for j in range(k + 1): nX[j] = max(nX[j], X[j] + abs(N - (k - j) - 1 - i) * a) nX[j + 1] = max(nX[j + 1], X[j] + abs(j - i) * a) X = nX print(max(X))
Statement There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child earns A_x \times |x-y| happiness points. Find the maximum total happiness points the children can earn.
[{"input": "4\n 1 3 4 2", "output": "20\n \n\nIf we move the 1-st child from the left to the 3-rd position from the left,\nthe 2-nd child to the 4-th position, the 3-rd child to the 1-st position, and\nthe 4-th child to the 2-nd position, the children earns 1 \\times |1-3|+3\n\\times |2-4|+4 \\times |3-1|+2 \\times |4-2|=20 happiness points in total.\n\n* * *"}, {"input": "6\n 5 5 6 1 1 1", "output": "58\n \n\n* * *"}, {"input": "6\n 8 6 9 1 2 1", "output": "85"}]
Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed ± 10-3.
s966029491
Accepted
p00364
The input is given in the following format. N t x_1 h_1 x_2 h_2 : x_N h_N The first line provides the number of existing buildings N (1≤N≤1000) and the planned location of the tower t (2≤t≤105) in integers. Each of the subsequent N lines provides the information of the i-th building: location x_i (1 ≤ x_i < t) and height from the ground h_i (1 ≤ h_i ≤ 100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if i ≠ j, then x_i ≠ x_j).
N, t = map(int, input().split()) tan = 0 for _ in range(N): x, h = map(int, input().split()) tan = max(tan, h / x) print(tan * t)
Bange Hills Tower A project is underway to build a new viewing tower in Bange town called “Bange Hills Tower” whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wakamatsuCastle) Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. “view of the entire keep” means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings).
[{"input": "3 10\n 6 4\n 4 2\n 3 2", "output": "6.666667"}]
Output the required height as a real number. No limits on the number of decimal places as long as the error does not exceed ± 10-3.
s453230867
Accepted
p00364
The input is given in the following format. N t x_1 h_1 x_2 h_2 : x_N h_N The first line provides the number of existing buildings N (1≤N≤1000) and the planned location of the tower t (2≤t≤105) in integers. Each of the subsequent N lines provides the information of the i-th building: location x_i (1 ≤ x_i < t) and height from the ground h_i (1 ≤ h_i ≤ 100). All position information is one-dimensional along the ground line whose origin coincides with the Keep location. No more than one building is located in the same location (i.e. if i ≠ j, then x_i ≠ x_j).
N, t = [int(e) for e in input().split()] ts = [[int(e) for e in input().split()] for _ in range(N)] result = 0 for x, h in ts: r = h * t / x result = max(result, r) print(result)
Bange Hills Tower A project is underway to build a new viewing tower in Bange town called “Bange Hills Tower” whose selling point will be the gorgeous view of the entire main keep of Wakamatsu Castle from top to bottom. Therefore, the view line from the top of the tower must reach the bottom of the keep without being hindered by any of the buildings in the town. ![](https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE2_PCK2017_wakamatsuCastle) Write a program to calculate the minimum tower height required to view the keep in its entirety based on the following information: the planned location of the tower and the heights and locations of existing buildings. Assume all the buildings, including the keep, are vertical lines without horizontal stretch. “view of the entire keep” means that the view line from the tower top can cover the keep from the bottom to the top without intersecting (contacts at the top are exempted) any of the other vertical lines (i.e., buildings).
[{"input": "3 10\n 6 4\n 4 2\n 3 2", "output": "6.666667"}]
Print three rational numbers p, q, r, separated by spaces. * * *
s734560231
Wrong Answer
p03118
Input is given from Standard Input in the following format: N s
print("いつもありがとうございます!") print("ACしてくれてえらい!すき!")
Statement There is a very long bench. The bench is divided into M sections, where M is a very large integer. Initially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action: * We call a section _comfortable_ if the section is currently unoccupied and is not adjacent to any occupied sections. If there is no comfortable section, the person leaves the bench. Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there. (The choices are independent from each other). After all M people perform actions, Snuke chooses an interval of N consecutive sections uniformly at random (from M-N+1 possible intervals), and takes a photo. His photo can be described by a string of length N consisting of `X` and `-`: the i-th character of the string is `X` if the i-th section from the left in the interval is occupied, and `-` otherwise. Note that the photo is directed. For example, `-X--X` and `X--X-` are different photos. What is the probability that the photo matches a given string s? This probability depends on M. You need to compute the limit of this probability when M goes infinity. Here, we can prove that the limit can be uniquely written in the following format using three **rational** numbers p, q, r and e = 2.718 \ldots (the base of natural logarithm): p + \frac{q}{e} + \frac{r}{e^2} Your task is to compute these three rational numbers, and print them modulo 10^9 + 7, as described in Notes section.
[{"input": "1\n X", "output": "500000004 0 500000003\n \n\nThe probability that a randomly chosen section is occupied converge to\n\\frac{1}{2} - \\frac{1}{2e^2}.\n\n* * *"}, {"input": "3\n ---", "output": "0 0 0\n \n\nAfter the actions, no three consecutive unoccupied sections can be left.\n\n* * *"}, {"input": "5\n X--X-", "output": "0 0 1\n \n\nThe limit is \\frac{1}{e^2}.\n\n* * *"}, {"input": "5\n X-X-X", "output": "500000004 0 833333337\n \n\nThe limit is \\frac{1}{2} - \\frac{13}{6e^2}.\n\n* * *"}, {"input": "20\n -X--X--X-X--X--X-X-X", "output": "0 0 183703705\n \n\nThe limit is \\frac{7}{675e^2}.\n\n* * *"}, {"input": "100\n X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X-", "output": "0 0 435664291"}]
Print three rational numbers p, q, r, separated by spaces. * * *
s142827059
Wrong Answer
p03118
Input is given from Standard Input in the following format: N s
print("I am tourist")
Statement There is a very long bench. The bench is divided into M sections, where M is a very large integer. Initially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action: * We call a section _comfortable_ if the section is currently unoccupied and is not adjacent to any occupied sections. If there is no comfortable section, the person leaves the bench. Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there. (The choices are independent from each other). After all M people perform actions, Snuke chooses an interval of N consecutive sections uniformly at random (from M-N+1 possible intervals), and takes a photo. His photo can be described by a string of length N consisting of `X` and `-`: the i-th character of the string is `X` if the i-th section from the left in the interval is occupied, and `-` otherwise. Note that the photo is directed. For example, `-X--X` and `X--X-` are different photos. What is the probability that the photo matches a given string s? This probability depends on M. You need to compute the limit of this probability when M goes infinity. Here, we can prove that the limit can be uniquely written in the following format using three **rational** numbers p, q, r and e = 2.718 \ldots (the base of natural logarithm): p + \frac{q}{e} + \frac{r}{e^2} Your task is to compute these three rational numbers, and print them modulo 10^9 + 7, as described in Notes section.
[{"input": "1\n X", "output": "500000004 0 500000003\n \n\nThe probability that a randomly chosen section is occupied converge to\n\\frac{1}{2} - \\frac{1}{2e^2}.\n\n* * *"}, {"input": "3\n ---", "output": "0 0 0\n \n\nAfter the actions, no three consecutive unoccupied sections can be left.\n\n* * *"}, {"input": "5\n X--X-", "output": "0 0 1\n \n\nThe limit is \\frac{1}{e^2}.\n\n* * *"}, {"input": "5\n X-X-X", "output": "500000004 0 833333337\n \n\nThe limit is \\frac{1}{2} - \\frac{13}{6e^2}.\n\n* * *"}, {"input": "20\n -X--X--X-X--X--X-X-X", "output": "0 0 183703705\n \n\nThe limit is \\frac{7}{675e^2}.\n\n* * *"}, {"input": "100\n X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X-", "output": "0 0 435664291"}]
Print three rational numbers p, q, r, separated by spaces. * * *
s636759991
Wrong Answer
p03118
Input is given from Standard Input in the following format: N s
print("Hello World")
Statement There is a very long bench. The bench is divided into M sections, where M is a very large integer. Initially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action: * We call a section _comfortable_ if the section is currently unoccupied and is not adjacent to any occupied sections. If there is no comfortable section, the person leaves the bench. Otherwise, the person chooses one of comfortable sections uniformly at random, and sits there. (The choices are independent from each other). After all M people perform actions, Snuke chooses an interval of N consecutive sections uniformly at random (from M-N+1 possible intervals), and takes a photo. His photo can be described by a string of length N consisting of `X` and `-`: the i-th character of the string is `X` if the i-th section from the left in the interval is occupied, and `-` otherwise. Note that the photo is directed. For example, `-X--X` and `X--X-` are different photos. What is the probability that the photo matches a given string s? This probability depends on M. You need to compute the limit of this probability when M goes infinity. Here, we can prove that the limit can be uniquely written in the following format using three **rational** numbers p, q, r and e = 2.718 \ldots (the base of natural logarithm): p + \frac{q}{e} + \frac{r}{e^2} Your task is to compute these three rational numbers, and print them modulo 10^9 + 7, as described in Notes section.
[{"input": "1\n X", "output": "500000004 0 500000003\n \n\nThe probability that a randomly chosen section is occupied converge to\n\\frac{1}{2} - \\frac{1}{2e^2}.\n\n* * *"}, {"input": "3\n ---", "output": "0 0 0\n \n\nAfter the actions, no three consecutive unoccupied sections can be left.\n\n* * *"}, {"input": "5\n X--X-", "output": "0 0 1\n \n\nThe limit is \\frac{1}{e^2}.\n\n* * *"}, {"input": "5\n X-X-X", "output": "500000004 0 833333337\n \n\nThe limit is \\frac{1}{2} - \\frac{13}{6e^2}.\n\n* * *"}, {"input": "20\n -X--X--X-X--X--X-X-X", "output": "0 0 183703705\n \n\nThe limit is \\frac{7}{675e^2}.\n\n* * *"}, {"input": "100\n X-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X-", "output": "0 0 435664291"}]
Print the answer. * * *
s044240693
Accepted
p03548
Input is given from Standard Input in the following format: X Y Z
a = input().split() print((int(a[0]) - int(a[2])) // (int(a[1]) + int(a[2])))
Statement We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
[{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n![](https://img.atcoder.jp/abc078/4a35302937c3cbc2f625156e7834d27f.png)\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}]
Print the answer. * * *
s056279610
Accepted
p03548
Input is given from Standard Input in the following format: X Y Z
x = list(map(int, input().split())) print((x[0] - x[2]) // (x[1] + x[2]))
Statement We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
[{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n![](https://img.atcoder.jp/abc078/4a35302937c3cbc2f625156e7834d27f.png)\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}]
Print the answer. * * *
s702720517
Wrong Answer
p03548
Input is given from Standard Input in the following format: X Y Z
a, b, c = input().split() a = int(a) b = int(b) c = int(c) print((a - c) // b)
Statement We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
[{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n![](https://img.atcoder.jp/abc078/4a35302937c3cbc2f625156e7834d27f.png)\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}]
Print the answer. * * *
s252680758
Accepted
p03548
Input is given from Standard Input in the following format: X Y Z
X, Y, Z = list(map(int, input().split())) for i in range(0, 10**5 + 1): if X - (i * Y + (i + 1) * Z) == 0: print(i) exit() if X - (i * Y + (i + 1) * Z) < 0: print(i - 1) exit()
Statement We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
[{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n![](https://img.atcoder.jp/abc078/4a35302937c3cbc2f625156e7834d27f.png)\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}]
Print the answer. * * *
s490685953
Accepted
p03548
Input is given from Standard Input in the following format: X Y Z
data = list(map(int, input().split())) x = data[0] y = data[1] z = data[2] people = int((x - z) / (y + z)) print(people)
Statement We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
[{"input": "13 3 1", "output": "3\n \n\nThere is just enough room for three, as shown below:\n\n![](https://img.atcoder.jp/abc078/4a35302937c3cbc2f625156e7834d27f.png)\n\nFigure\n\n* * *"}, {"input": "12 3 1", "output": "2\n \n\n* * *"}, {"input": "100000 1 1", "output": "49999\n \n\n* * *"}, {"input": "64146 123 456", "output": "110\n \n\n* * *"}, {"input": "64145 123 456", "output": "109"}]