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 `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s507954634
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c = [int(x) for x in input().split()] if(b-a = c-b): print('YES') else: print('NO')
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s112370566
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c=map(int,input().split()) if b-a=c-b: print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s054155408
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int,input().split()) if c - b = b - a: print("Yes") else: print("No")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s587670642
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c = map(int, input().split()) if b-a = c-b: print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s400166639
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int,input().split()) if c - b = a - b: print("Yes") else: print("No")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s479027169
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c = map(int,input().split()) if b-a == c-b: print("YES") else print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s828870017
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c=input().split() if (int(b)-int(a)==(int(c)-int(b): print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s104928467
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int, input().split()) if b−a == c−b: print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s297122322
Accepted
p03759
Input is given from Standard Input in the following format: a b c
### ### atcorder test program ### import sys ### math class class math: ### pi pi = 3.14159265358979323846264338 ### GCD def gcd(self, a, b): if b == 0: return a return self.gcd(b, a % b) ### LCM def lcm(self, a, b): return (a * b) // self.gcd(a, b) ### Prime number search def Pnum(self, a): if a == 1: return False for i in range(2, int(a**0.5) + 1): if a % i == 0: return False return True ### Circle area def caria(self, r): return r * r * self.pi math = math() ### output class class output: ### list def list(self, l): l = list(l) print(" ", end="") for i, num in enumerate(l): print(num, end="") if i != len(l) - 1: print(" ", end="") print() output = output() ### input sample # i = input() # A, B, C = [x for x in input().split()] # inlist = [int(w) for w in input().split()] # R = float(input()) # A = [int(x) for x in input().split()] # for line in sys.stdin.readlines(): # x, y = [int(temp) for temp in line.split()] ### output sample # print("{0} {1} {2:.5f}".format(A//B, A%B, A/B)) # print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi)) # print(" {}".format(i), end="") A, B, C = [int(x) for x in input().split()] if B - A == C - B: print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s633164941
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a = input() b = input() n = len(b) x = 0 i = 0 j = 0 while x < n * 2: if x % 2: print(b[i], end="") i += 1 else: print(a[j], end="") j += 1 x += 1 print("")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s108904995
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
for i in range(1, 100): a = int(input("Enter the height a in meters=")) b = int(input("Enter the height b in meters=")) c = int(input("Enter the height c in meters=")) if b - a == c - b: print("Yes") print( "Since" + str(b) + "-" + str(a) + "=" + str(c) + "-" + str(b) + ",this arrangement of poles is beautiful." ) elif c - b == b - a: print("Yes") print( "Since" + str(c) + "-" + str(b) + "=" + str(b) + "-" + str(a) + ",this arrangement of poles is beautiful." ) else: print("NO") print( "Since" + str(b) + "-" + str(a) + "≠" + str(c) + "-" + str(b) + ",this arrangement of poles is not beautiful." )
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s849688610
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int, input().split()) if b−a == c−b: print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s248080114
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
def beautiful: a = int(input()) b = int(input()) c = int(input()) if abs(b-a) == abs(c-b): print('YES') else: print('NO') beautiful()
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s289537592
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a=int(input("Enter a")) b=int(input("Enter b")) c=int(input("Enter c")) if a-b == b-c || b-a == c-b: print("Beautiful") else: print("No")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s695799033
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a=int(input("Enter a")) b=int(input("Enter b")) c=int(input("Enter c")) if a-b == b-c || b-a == c-b: print(Beautiful") else: print("No")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s981067460
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
o = list(input()) e = list(input()) p = "" for i in range(len(e)): p += o[i] p += e[i] if len(o) - i == 2: p += o[i + 1] print(p)
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s733940223
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
def beautiful: a,b,c = input().split() if fabs(b-a) == fabs(c-b): print('YES') else: print('NO') beautiful()
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s602131499
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
def beautiful: a,b,c = int(input()).split() if ((abs(b-a)) == (abs(c-b))): print('YES') else: print('NO') beautiful()
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s428354399
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int, input().split()) print("YES" if b-a == c-b else "NO)
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s900945429
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
print("".join((a + b for a, b in zip(input(), input() + "\n"))).split("\n")[0])
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s071277174
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c=map(int,input().split()) print("YES" if b-a==c-b else "NO)
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s076067699
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int, input().split()) print('YES' if a - 2b + c == 0 else 'NO')
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s500293857
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int, input().split()) print("YES" if b - a = c - b else "NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s592007507
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c=map(int,input().split()) print('YES' if b-a==c-b else 'NO)
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s809786889
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
if b-a = c-b: print('YES') else: print('NO')
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s827690658
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int, input().split()) if (b−a) == (c−b): print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s057294490
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c = (int(x) for x in input().split()) if b-a=c-b: print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s253154149
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c = map(input().split(), int) 2.if a+c == 2*b: 3. print('YES') 4.else: 5. print('NO')
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s697773109
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a, b, c = map(int, input().split()) if b−a == c−b: print("YES") else: print("NO")
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s024386466
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c =map(int, input().split()) if a+c=2*b: print('YES') else: print('NO')
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print `YES` if the arrangement of the poles is beautiful; print `NO` otherwise. * * *
s140554084
Runtime Error
p03759
Input is given from Standard Input in the following format: a b c
a,b,c = map(int,input().split()) if b-a = c-b: print('YES') else: print('NO')
Statement Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles _beautiful_ if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful.
[{"input": "2 4 6", "output": "YES\n \n\nSince 4-2 = 6-4, this arrangement of poles is beautiful.\n\n* * *"}, {"input": "2 5 6", "output": "NO\n \n\nSince 5-2 \\neq 6-5, this arrangement of poles is not beautiful.\n\n* * *"}, {"input": "3 2 1", "output": "YES\n \n\nSince 1-2 = 2-3, this arrangement of poles is beautiful."}]
Print the minimum possible sadness of Snuke. * * *
s496116138
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s339693954
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
9 1 2 3 4 5 6 7 8 9
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s775068631
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = [int(i) for i in input().split()] for i in range(n): a[i] -= (i+1) ave = sum(a) // n foi i in range(n): a[i] = abs(a[i] - ave) print(sum(a))
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s254778882
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
from statistics import median as m n = int(input()) A = list(map(int, input().split())) B = sorted([A[i] - i - 1 for i in range(n)]) m(B) = mb print(int(sum([abs(b - mb) for b in B])))
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s935420044
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
こんなん解けへんやん普通
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s956631610
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input().strip()) A = list(map(int, input().strip().split(' '))) B = [a-(i+1) for i,a in enumerate(A)] avg = int(sum(B)/len(B)) ans = float('inf') for i in range(-2,3): ans = min(ans, sum([abs(b-(avg+i)) for b in B]) print(ans)
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s465335133
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import math import statistics import numpy as np size = int(input()) A = np.array(list(map(int,input().split()))) i = np.array(list(range(1,size+1))) remain_list = A-i median = statistics.median(remain_list) print(sum(remain_list - median))A
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s497310452
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) l = input().split() lst = list(map(int,l)) sum = 0 j = 1 for i in lst: sum += (i-j) j+=1 //四捨五入 b = round(sum/n) #print(b) j = 1 sad = 0 for a in lst: sad += abs(a-(b+j)) j += 1 print(sad)
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s414995600
Runtime Error
p03309
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 devide2a(x): def devide2b(y): if x % 2 == 0: return int(n / 2) else: return int((n - 1) / 2) for j in range(n): a[j] = a[j] - (j + 1) a.sort() if x % 2 == 0: print(sum(a[n / 2:]) - sum(a[:n / 2]) else: print(sum(a[(n + 1) / 2:]) - sum(a[:(n - 1) / 2])
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s310733332
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
fun main(args : Array<String>) { val N = readLine()!!.toInt() val A = readLine()!!.split(" ").map { it.toInt() } val B = (1..N).map { val index = it - 1 A.get(index) - it }.toMutableList() B.sort() val median = B.get(N / 2) val answer = B.map { Math.abs(it - median) }.sum() println(answer) }
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s981907786
Runtime Error
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(inputs[0]) A = list(map(int, inputs[1].split())) B = list(map(lambda x: x[1]-x[0], enumerate(A, 1))) b = floor(sum(B) / n) b1 = round(sum(B) / n) b2 = ceil(sum(B) / n) C = list(map(lambda x: abs(x-b), B)) C1 = list(map(lambda x: abs(x-b1), B)) C2 = list(map(lambda x: abs(x-b2), B)) print(min(list(map(sum, [C, C1, C2])))
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s306947801
Accepted
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from fractions import gcd from math import factorial, sqrt, ceil from functools import lru_cache, reduce INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10**7) # UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) def is_prime(n): if n == 1: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True # ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める) # 計算量n^3 (nは頂点の数) def warshall_floyd(d, n): # d[i][j]: iからjへの最短距離 for k in range(n): for i in range(n): for j in range(n): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d # ダイクストラ def dijkstra_heap(s, edge, n): # 始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n # True:未確定 d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d # 素因数分解 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 # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # 素数判定 # limit以下の素数を列挙 def eratosthenes(limit): A = [i for i in range(2, limit + 1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P # 同じものを含む順列 def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] # set(集合)型で重複を削除、ソート S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret # ここから書き始める n = int(input()) a = list(map(int, input().split())) a2 = sorted([a[i] - i for i in range(n)]) median = a2[n // 2] ans = sum([abs(a2[i] - median) for i in range(n)]) print(ans)
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s596681009
Accepted
p03309
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())) A = [a - i for i, a in enumerate(A, 1)] A.sort() A_posi = [0 for i in range(N)] A_posi[0] = A[0] for i in range(1, N): A_posi[i] = A_posi[i - 1] + A[i] value = [0 for i in range(N)] value[0] = A_posi[N - 1] - N * A[0] for i in range(1, N): value[i] = ( A_posi[N - 1] - A_posi[i] - (N - i - 1) * A[i] - A_posi[i - 1] + (i) * A[i] ) print(min(value))
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s371081859
Accepted
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A_list = [int(elem) for elem in input().split(" ")] assert len(A_list) == N modified_A_list = [A - i for i, A in enumerate(A_list, start=1)] minus_A_list = sorted([A for A in modified_A_list if A < 0])[::-1] zero_A_list = [A for A in modified_A_list if A == 0] plus_A_list = sorted([A for A in modified_A_list if A > 0]) # print(minus_A_list, zero_A_list, plus_A_list) len_minus = len(minus_A_list) len_zero = len(zero_A_list) len_plus = len(plus_A_list) assert len_minus + len_zero + len_plus == N current_sum = abs(sum(minus_A_list)) + sum(plus_A_list) # print(current_sum) if len_minus > len_plus + len_zero: i = 0 old_num = 0 while i < len(minus_A_list): current_num = minus_A_list[i] current_sum -= abs(current_num - old_num) * (len_minus - len_plus - len_zero) # 数の更新 num_current_val = 0 while i < len(minus_A_list) and (minus_A_list[i] == current_num): i += 1 num_current_val += 1 len_minus -= num_current_val len_zero_old = len_zero len_zero += num_current_val - len_zero_old len_plus += len_zero_old old_num = current_num if len_minus <= len_plus + len_zero: break elif len_plus > len_minus + len_zero: i = 0 old_num = 0 while i < len(plus_A_list): current_num = plus_A_list[i] current_sum -= (current_num - old_num) * (len_plus - len_minus - len_zero) # 数の更新 num_current_val = 0 while i < len(plus_A_list) and plus_A_list[i] == current_num: i += 1 num_current_val += 1 len_plus -= num_current_val len_zero_old = len_zero len_zero += num_current_val - len_zero_old len_minus += len_zero_old old_num = current_num if len_plus <= len_minus + len_zero: break print(current_sum)
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s134864675
Wrong Answer
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
def main6(): buf = int(input("")) strbuf = input("") strbufs = strbuf.split() buf2 = [] saisyo = 100000000 for i in range(buf): buf2.append((int(strbufs[i]) - (i + 1))) maxi = max(buf2) mini = min(buf2) kari2 = 0 for i in range(buf): kari2 = kari2 + buf2[i] kari2 = int(kari2 / buf) - 2 for i in range(kari2, kari2 + 4): kari = 0 for j in range(buf): kari = kari + abs(buf2[j] - i) if kari < saisyo: saisyo = kari print(saisyo) if __name__ == "__main__": main6()
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s795792542
Accepted
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import bisect as bi N = int(input()) A = [int(t) for t in input().split()] A = sorted([A[i] - i - 1 for i in range(N)]) nega_cnt = bi.bisect_left(A, 0) posi_cnt = N - bi.bisect_right(A, 0) zero_cnt = N - nega_cnt - posi_cnt def calc(): if nega_cnt + zero_cnt >= posi_cnt and posi_cnt + zero_cnt >= nega_cnt: return sum([abs(t) for t in A]) if posi_cnt > nega_cnt + zero_cnt: idx = (posi_cnt - (nega_cnt + zero_cnt)) // 2 + 1 a = A[-posi_cnt:][idx - 1] return sum([abs(t - a) for t in A]) if posi_cnt + zero_cnt < nega_cnt: idx = (nega_cnt - (posi_cnt + zero_cnt)) // 2 + 1 a = A[:nega_cnt][-idx] return sum([abs(t - a) for t in A]) print(calc())
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s045638772
Wrong Answer
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math # from math import gcd import bisect from collections import defaultdict from collections import deque from functools import lru_cache ############# # Constants # ############# MOD = 10**9 + 7 INF = float("inf") ############# # Functions # ############# ######INPUT###### def I(): return int(input().strip()) def S(): return input().strip() def IL(): return list(map(int, input().split())) def SL(): return list(map(str, input().split())) def ILs(n): return list(int(input()) for _ in range(n)) def SLs(n): return list(input().strip() for _ in range(n)) def ILL(n): return [list(map(int, input().split())) for _ in range(n)] def SLL(n): return [list(map(str, input().split())) for _ in range(n)] ######OUTPUT###### def P(arg): print(arg) return def Y(): print("Yes") return def N(): print("No") return def E(): exit() def PE(arg): print(arg) exit() def YE(): print("Yes") exit() def NE(): print("No") exit() #####Shorten##### def DD(arg): return defaultdict(arg) #####Inverse##### def inv(n): return pow(n, MOD - 2, MOD) ######Combination###### kaijo_memo = [] def kaijo(n): if len(kaijo_memo) > n: return kaijo_memo[n] if len(kaijo_memo) == 0: kaijo_memo.append(1) while len(kaijo_memo) <= n: kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD) return kaijo_memo[n] gyaku_kaijo_memo = [] def gyaku_kaijo(n): if len(gyaku_kaijo_memo) > n: return gyaku_kaijo_memo[n] if len(gyaku_kaijo_memo) == 0: gyaku_kaijo_memo.append(1) while len(gyaku_kaijo_memo) <= n: gyaku_kaijo_memo.append( gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD ) return gyaku_kaijo_memo[n] def nCr(n, r): if n == r: return 1 if n < r or r < 0: return 0 ret = 1 ret = ret * kaijo(n) % MOD ret = ret * gyaku_kaijo(r) % MOD ret = ret * gyaku_kaijo(n - r) % MOD return ret ######Factorization###### def factorization(n): arr = [] temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i arr.append([i, cnt]) if temp != 1: arr.append([temp, 1]) if arr == []: arr.append([n, 1]) return arr #####MakeDivisors###### def make_divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n // i) return divisors #####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]) * n**i for i in range(len(str(X)))) #####IntLog##### def int_log(n, a): count = 0 while n >= a: n //= a count += 1 return count ############# # Main Code # ############# N = I() A = IL() AA = [A[i] - i - 1 for i in range(N)] sumAA = sum(AA) avehiku = sumAA // N avetaka = -(-sumAA // N) AAhiku = [abs(AA[i] - avehiku) for i in range(N)] AAtaka = [abs(AA[i] - avetaka) for i in range(N)] print(min(sum(AAhiku), sum(AAtaka)))
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s646641731
Wrong Answer
p03309
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().rstrip().split())) work = int() testA = int() testB = int() testC = int() work = sum(A) // N - N // 2 testA = sum(abs(A[i] - i - work) for i in range(N)) testB = sum(abs(A[i] - i - work + 1) for i in range(N)) testC = sum(abs(A[i] - i - work - 1) for i in range(N)) testD = sum(abs(A[i] - i - work + 2) for i in range(N)) testE = sum(abs(A[i] - i - work - 2) for i in range(N)) output = min(testA, testB, testC, testD, testE) print(output)
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s800336455
Wrong Answer
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
# -*- coding:utf-8 -* N = int(input()) nums = list(map(int, input().split())) nums_s = sorted(nums) if len(nums) % 2 == 0: middle = int(len(nums_s) / 2) middles = [middle - 1, middle] res = [] for mid in middles: b = nums_s[mid] - (mid + 1) result = 0 for i in range(1, N + 1): result += abs(nums[i - 1] - (b + i)) res.append(result) print(min(res)) else: middle = int(len(nums_s) / 2) b = nums_s[middle] - (middle + 1) result = 0 for i in range(1, N + 1): result += abs(nums[i - 1] - (b + i)) print(result)
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum possible sadness of Snuke. * * *
s237160697
Accepted
p03309
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) ai = [int(e) for e in input().split()] bi = [] for i in range(len(ai)): bi.append(ai[i] - i - 1) bi = sorted(bi) b = bi[int(len(bi) / 2)] su = 0 for i in range(len(ai)): su += abs(ai[i] - (b + i + 1)) print(su)
Statement Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the _sadness_ of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N)) Here, abs(x) is a function that returns the absolute value of x. Find the minimum possible sadness of Snuke.
[{"input": "5\n 2 2 3 5 5", "output": "2\n \n\nIf we choose b=0, the sadness of Snuke would be\nabs(2-(0+1))+abs(2-(0+2))+abs(3-(0+3))+abs(5-(0+4))+abs(5-(0+5))=2. Any choice\nof b does not make the sadness of Snuke less than 2, so the answer is 2.\n\n* * *"}, {"input": "9\n 1 2 3 4 5 6 7 8 9", "output": "0\n \n\n* * *"}, {"input": "6\n 6 5 4 3 2 1", "output": "18\n \n\n* * *"}, {"input": "7\n 1 1 1 1 2 3 4", "output": "6"}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s370649860
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
import sys R1 = input().split() R2 = input().split() K = int(R1[0]) T = int(R1[1]) answer = int(0) A = [] for i in range(0, T): A.append(int(R2[i])) A.sort() A.reverse() if T == 1: print(A[0] - 1) sys.exit() if T == 2: print(A[0] - A[1] - 1) sys.exit() for i in range(0, K): C = A[0] if C - 1 > A[1]: if A[1] == 0: answer += 1 if A[1] != 0: K -= 1 D = int(A[1]) A.remove(D) F = int(1) left = int(0) right = int(T - 2) while left <= right: mid = int(left + (right - left) / 2) if A[mid] >= D - 1: left = mid + 1 F = max(F, mid + 1) else: right = mid - 1 A.insert(F, D - 1) A[0] -= 1 if C - 1 == A[1]: A[0] -= 1 if C == A[1]: F = int(0) left = int(0) right = int(T - 1) while left <= right: mid = int(left + (right - left) / 2) if A[mid] == C: left = mid + 1 F = max(F, mid + 1) else: right = mid - 1 A.insert(F, C - 1) A.remove(C) print(answer)
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s115251920
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
import sys import heapq import re from itertools import permutations from bisect import bisect_left, bisect_right from collections import Counter, deque from math import factorial, sqrt, ceil, gcd from functools import lru_cache, reduce from decimal import Decimal from operator import mul INF = 1 << 60 MOD = 1000000007 sys.setrecursionlimit(10**7) # UnionFind class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots()) # ダイクストラ def dijkstra_heap(s, edge, n): # 始点sから各頂点への最短距離 d = [10**20] * n used = [True] * n # True:未確定 d[s] = 0 used[s] = False edgelist = [] for a, b in edge[s]: heapq.heappush(edgelist, a * (10**6) + b) while len(edgelist): minedge = heapq.heappop(edgelist) # まだ使われてない頂点の中から最小の距離のものを探す if not used[minedge % (10**6)]: continue v = minedge % (10**6) d[v] = minedge // (10**6) used[v] = False for e in edge[v]: if used[e[1]]: heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1]) return d # 素因数分解 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 # 組合せnCr def combinations_count(n, r): if n < r: return 0 r = min(r, n - r) numer = reduce(mul, range(n, n - r, -1), 1) denom = reduce(mul, range(1, r + 1), 1) return numer // denom # 2数の最小公倍数 def lcm(x, y): return (x * y) // gcd(x, y) # リストの要素の最小公倍数 def lcm_list(numbers): return reduce(lcm, numbers, 1) # リストの要素の最大公約数 def gcd_list(numbers): return reduce(gcd, numbers) # 素数判定 def is_prime(n): if n <= 1: return False p = 2 while True: if p**2 > n: break if n % p == 0: return False p += 1 return True # limit以下の素数を列挙 def eratosthenes(limit): A = [i for i in range(2, limit + 1)] P = [] while True: prime = min(A) if prime > sqrt(limit): break P.append(prime) i = 0 while i < len(A): if A[i] % prime == 0: A.pop(i) continue i += 1 for a in A: P.append(a) return P # 同じものを含む順列 def permutation_with_duplicates(L): if L == []: return [[]] else: ret = [] # set(集合)型で重複を削除、ソート S = sorted(set(L)) for i in S: data = L[:] data.remove(i) for j in permutation_with_duplicates(data): ret.append([i] + j) return ret def make_divisors(n): lower_divisors, upper_divisors = [], [] i = 1 while i * i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n // i) i += 1 return lower_divisors + upper_divisors[::-1] # ここから書き始める k, t = map(int, input().split()) a = list(map(int, input().split())) ans = max(0, -sum(a) + 2 * max(a) - 1) print(ans)
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s352984650
Runtime Error
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
n,k=map(int,input().split()) a=list(map(int,input()split())) s=max(a) print(max(2*s-n-1))
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s518768433
Wrong Answer
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
k_t = input().split() k = int(k_t[0]) t = int(k_t[1]) t_amount = input().split(" ") while True: if t == 1: max = k break max = 0 for i in range(t - 1): if t_amount[i + 1] >= t_amount[i]: max = t_amount[i + 1] elif max == 0: max = t_amount[0] t_amount.remove(max) max2 = 0 for i in range(t - 2): if t_amount[i + 1] >= t_amount[i]: max2 = t_amount[i + 1] elif max2 == 0: max2 = t_amount[0] t_amount.remove(max2) if max2 == "0": break else: max = int(max) - 1 max2 = int(max2) - 1 t_amount.append(str(max)) t_amount.append(str(max2)) if max == "0": print(0) else: print(int(max) - 1)
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s088027586
Runtime Error
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) import math #from itertools import product, accumulate, combinations, product #import bisect #import numpy as np #from copy import deepcopy from collections import deque #from decimal import Decimal INF = 1 << 50 def run(): K, T, *A = map(int, read().split()) A = sorted(A) A = deque(A) high, low = 0, 0 last = None while A: #print(A) if high == 1: A.appendleft(1) high = A.pop() if not high: high = A.pop() if high == 1:break elif not low: low = A.popleft() #print(high, low) val = min(low, high-1) if not val: last = None else: last = 'LOW' high -= val low -= val #print('-->', high, low) if high == 1 if last == None: print(max(low-high-1, 0)) return else: print(max(low - 1, 0))) return print(high - 1 + max(low - 1, 0)) if __name__ == "__main__": run()
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s497053176
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
k, _, *a = map(int, open(0).read().split()) print(max(0, 2 * max(a) + ~k))
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s433008063
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
n, t, *a = map(int, open(0).read().split()) print(max(2 * max(a) - n - 1, 0))
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s472783954
Wrong Answer
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
# coding: utf-8 # Your code here! k, t = map(int, input().split(" ")) cake = list(map(int, input().split(" "))) sum = 0 maxCake = -1 for i in range(t): maxCake = max(maxCake, cake[i]) print(maxCake - 1 - (k - maxCake))
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s413128933
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
K, T = map(int, input().split()) A = list(map(int, input().split())) assert len(A) == T amax = max(A) rest = sum(A) - amax print(max(amax - rest - 1, 0))
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s867751982
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
import sys import math import copy import heapq from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = float("inf") MOD = 10**9 + 7 divide = lambda x: pow(x, MOD - 2, MOD) def nck(n, k, kaijyo): return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD def npk(n, k, kaijyo): if k == 0 or k == n: return n % MOD return (kaijyo[n] * divide(kaijyo[n - k])) % MOD def fact_and_inv(SIZE): inv = [0] * SIZE # inv[j] = j^{-1} mod MOD fac = [0] * SIZE # fac[j] = j! mod MOD finv = [0] * SIZE # finv[j] = (j!)^{-1} mod MOD inv[1] = 1 fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2, SIZE): inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD fac[i] = fac[i - 1] * i % MOD finv[i] = finv[i - 1] * inv[i] % MOD return fac, finv def renritsu(A, Y): # example 2x + y = 3, x + 3y = 4 # A = [[2,1], [1,3]]) # Y = [[3],[4]] または [3,4] A = np.matrix(A) Y = np.matrix(Y) Y = np.reshape(Y, (-1, 1)) X = np.linalg.solve(A, Y) # [1.0, 1.0] return X.flatten().tolist()[0] class TwoDimGrid: # 2次元座標 -> 1次元 def __init__(self, h, w, wall="#"): self.h = h self.w = w self.size = (h + 2) * (w + 2) self.wall = wall self.get_grid() # self.init_cost() def get_grid(self): grid = [self.wall * (self.w + 2)] for i in range(self.h): grid.append(self.wall + getS() + self.wall) grid.append(self.wall * (self.w + 2)) self.grid = grid def init_cost(self): self.cost = [INF] * self.size def pos(self, x, y): # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed return y * (self.w + 2) + x def getgrid(self, x, y): return self.grid[y][x] def get(self, x, y): return self.cost[self.pos(x, y)] def set(self, x, y, v): self.cost[self.pos(x, y)] = v return def show(self): for i in range(self.h + 2): print(self.cost[(self.w + 2) * i : (self.w + 2) * (i + 1)]) def showsome(self, tgt): for t in tgt: print(t) return def showsomejoin(self, tgt): for t in tgt: print("".join(t)) return def search(self): grid = self.grid move = [(0, 1), (0, -1), (1, 0), (-1, 0)] move_eight = [ (0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1), ] # for i in range(1, self.h+1): # for j in range(1, self.w+1): # cx, cy = j, i # for dx, dy in move_eight: # nx, ny = dx + cx, dy + cy def solve(): k, t = getList() nums = getList() mx = max(nums) if mx + mx - 1 <= k: print(0) return else: print(mx - 1 - (k - mx)) return def main(): n = getN() for _ in range(n): solve() return if __name__ == "__main__": # main() solve()
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s808245317
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
#!/usr/bin/env python3 # %% for atcoder uniittest use import sys input = lambda: sys.stdin.readline().rstrip() def pin(type=int): return map(type, input().split()) def tupin(t=int): return tuple(pin(t)) def lispin(t=int): return list(pin(t)) # %%code def resolve(): K, T = pin() A = tupin() B = [[A[i], i] for i in range(T)] # print(B) prev = None for k in range(K): B.sort(key=lambda x: x[0]) # print(B,"#") for i in reversed(range(T)): if B[i][0] > 0 and B[i][1] != prev: B[i][0] -= 1 prev = B[i][1] break print(sum([B[k][0] for k in range(T)])) # %%submit! resolve()
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s737044807
Runtime Error
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
k, t = map(int, input().split()) A = list(map(int, input().split())) at = max(A) print(max(2 * at−1−k, 0))
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s601115392
Runtime Error
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
k, t = map(int, input().split()) A = list(map(int, input().split())) at = max(A) print(max(at−1−(k−at), 0))
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the minimum number of days on which the same type of cake as the previous day will be eaten. * * *
s756232615
Accepted
p03958
The input is given from Standard Input in the following format: K T a_1 a_2 ... a_T
import sys stdin = sys.stdin inf = 1 << 60 mod = 1000000007 ni = lambda: int(ns()) nin = lambda y: [ni() for _ in range(y)] na = lambda: list(map(int, stdin.readline().split())) nan = lambda y: [na() for _ in range(y)] nf = lambda: float(ns()) nfn = lambda y: [nf() for _ in range(y)] nfa = lambda: list(map(float, stdin.readline().split())) nfan = lambda y: [nfa() for _ in range(y)] ns = lambda: stdin.readline().rstrip() nsn = lambda y: [ns() for _ in range(y)] ncl = lambda y: [list(ns()) for _ in range(y)] nas = lambda: stdin.readline().split() k, t = na() a = na() s = sum(a) a.sort() s -= a[-1] if a[-1] - s <= 0: print(0) else: print(a[-1] - s - 1)
Statement There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating cakes that minimizes the number of days on which he has to eat the same type of cake as the day before. Compute the minimum number of days on which the same type of cake as the previous day will be eaten.
[{"input": "7 3\n 3 2 2", "output": "0\n \n\nFor example, if Mr. Takahashi eats cakes in the order of 2, 1, 2, 3, 1, 3, 1,\nhe can avoid eating the same type of cake as the previous day.\n\n* * *"}, {"input": "6 3\n 1 4 1", "output": "1\n \n\nThere are 6 cakes. For example, if Mr. Takahashi eats cakes in the order of 2,\n3, 2, 2, 1, 2, he has to eat the same type of cake (i.e., type 2) as the\nprevious day only on the fourth day. Since this is the minimum number, the\nanswer is 1.\n\n* * *"}, {"input": "100 1\n 100", "output": "99\n \n\nSince Mr. Takahashi has only one type of cake, he has no choice but to eat the\nsame type of cake as the previous day from the second day and after."}]
Print the answer in the following format: c_0 c_1 ... c_{(N - 1) + (M - 1)} * * *
s708662430
Accepted
p02563
Input is given from Standard Input in the following format: N M a_0 a_1 ... a_{N-1} b_0 b_1 ... b_{M-1}
class Ntt: def __init__(self, mod=10**9 + 7, root=3): self.mod = mod self.roots = [pow(root, (mod - 1) >> i, mod) for i in range(24)] self.iroots = [pow(x, mod - 2, mod) for x in self.roots] def untt(self, a, n): for i in range(n): m = 1 << (n - i - 1) for s in range(1 << i): wn = 1 s *= m * 2 for p in range(m): a[s + p], a[s + p + m] = (a[s + p] + a[s + p + m]) % self.mod, ( a[s + p] - a[s + p + m] ) * wn % self.mod wn = wn * self.roots[n - i] % self.mod def iuntt(self, a, n): for i in range(n): m = 1 << i for s in range(1 << (n - i - 1)): wn = 1 s *= m * 2 for p in range(m): a[s + p], a[s + p + m] = ( a[s + p] + a[s + p + m] * wn ) % self.mod, (a[s + p] - a[s + p + m] * wn) % self.mod wn = wn * self.iroots[i + 1] % self.mod inv = pow((self.mod + 1) // 2, n, self.mod) for i in range(1 << n): a[i] = a[i] * inv % self.mod def convolution(self, a, b): deg = len(a) + len(b) - 2 n = deg.bit_length() N = 1 << n a += [0] * (N - len(a)) b += [0] * (N - len(b)) self.untt(a, n) self.untt(b, n) for i in range(N): a[i] = a[i] * b[i] % self.mod self.iuntt(a, n) return a[: deg + 1] N, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) mod = 998244353 ntt = Ntt(mod=mod) print(*ntt.convolution(a, b))
Statement You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.
[{"input": "4 5\n 1 2 3 4\n 5 6 7 8 9", "output": "5 16 34 60 70 70 59 36\n \n\n* * *"}, {"input": "1 1\n 10000000\n 10000000", "output": "871938225"}]
Print the answer in the following format: c_0 c_1 ... c_{(N - 1) + (M - 1)} * * *
s016433082
Accepted
p02563
Input is given from Standard Input in the following format: N M a_0 a_1 ... a_{N-1} b_0 b_1 ... b_{M-1}
import sys readline = sys.stdin.readline MOD = 998244353 def frac(limit): frac = [1] * limit for i in range(2, limit): frac[i] = i * frac[i - 1] % MOD fraci = [None] * limit fraci[-1] = pow(frac[-1], MOD - 2, MOD) for i in range(-2, -limit - 1, -1): fraci[i] = fraci[i + 1] * (limit + i + 1) % MOD return frac, fraci frac, fraci = frac(1341398) class NTT: def __init__(self, MOD=998244353, pr=3, LS=20): self.MOD = MOD self.N0 = 1 << LS omega = pow(pr, (MOD - 1) // self.N0, MOD) omegainv = pow(omega, MOD - 2, MOD) self.w = [0] * (self.N0 // 2) self.winv = [0] * (self.N0 // 2) self.w[0] = 1 self.winv[0] = 1 for i in range(1, self.N0 // 2): self.w[i] = (self.w[i - 1] * omega) % MOD self.winv[i] = (self.winv[i - 1] * omegainv) % MOD used = set() for i in range(self.N0 // 2): if i in used: continue j = 0 for k in range(LS - 1): j |= (i >> k & 1) << (LS - 2 - k) used.add(j) self.w[i], self.w[j] = self.w[j], self.w[i] self.winv[i], self.winv[j] = self.winv[j], self.winv[i] def _fft(self, A): MOD = self.MOD M = len(A) bn = 1 hbs = M >> 1 while hbs: for j in range(hbs): A[j], A[j + hbs] = A[j] + A[j + hbs], A[j] - A[j + hbs] if A[j] > MOD: A[j] -= MOD if A[j + hbs] < 0: A[j + hbs] += MOD for bi in range(1, bn): wi = self.w[bi] for j in range(bi * hbs * 2, bi * hbs * 2 + hbs): A[j], A[j + hbs] = (A[j] + wi * A[j + hbs]) % MOD, ( A[j] - wi * A[j + hbs] ) % MOD bn <<= 1 hbs >>= 1 def _ifft(self, A): MOD = self.MOD M = len(A) bn = M >> 1 hbs = 1 while bn: for j in range(hbs): A[j], A[j + hbs] = A[j] + A[j + hbs], A[j] - A[j + hbs] if A[j] > MOD: A[j] -= MOD if A[j + hbs] < 0: A[j + hbs] += MOD for bi in range(1, bn): winvi = self.winv[bi] for j in range(bi * hbs * 2, bi * hbs * 2 + hbs): A[j], A[j + hbs] = (A[j] + A[j + hbs]) % MOD, winvi * ( A[j] - A[j + hbs] ) % MOD bn >>= 1 hbs <<= 1 def convolve(self, A, B): LA = len(A) LB = len(B) LC = LA + LB - 1 M = 1 << (LC - 1).bit_length() A += [0] * (M - LA) B += [0] * (M - LB) self._fft(A) self._fft(B) C = [0] * M for i in range(M): C[i] = A[i] * B[i] % self.MOD self._ifft(C) minv = pow(M, self.MOD - 2, self.MOD) for i in range(LC): C[i] = C[i] * minv % self.MOD return C[:LC] return C def inverse(self, A): LA = len(A) dep = (LA - 1).bit_length() M = 1 << dep A += [0] * (M - LA) g = [pow(A[0], self.MOD - 2, self.MOD)] for n in range(dep): dl = 1 << (n + 1) f = A[:dl] fg = self.convolve(f, g[:])[:dl] fgg = self.convolve(fg, g[:])[:dl] ng = [None] * dl for i in range(dl // 2): ng[i] = (2 * g[i] - fgg[i]) % self.MOD for i in range(dl // 2, dl): ng[i] = self.MOD - fgg[i] g = ng[:] return g[:LA] def integral(self, A): A = [1] + [A[i] * fraci[i + 2] % self.MOD for i in range(len(A))] N, M = map(int, readline().split()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) T = NTT() print(*T.convolve(A, B))
Statement You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.
[{"input": "4 5\n 1 2 3 4\n 5 6 7 8 9", "output": "5 16 34 60 70 70 59 36\n \n\n* * *"}, {"input": "1 1\n 10000000\n 10000000", "output": "871938225"}]
Print the answer in the following format: c_0 c_1 ... c_{(N - 1) + (M - 1)} * * *
s170558356
Accepted
p02563
Input is given from Standard Input in the following format: N M a_0 a_1 ... a_{N-1} b_0 b_1 ... b_{M-1}
# ----------- gcd ----------- # def gcd(x, y): k, l = x, y if y < 0: k, l = -k, -l while l: k, l = l, k % l return k def extgcd(a, b, c): if b == 0: return c // a, 0 if b < 0: a, b, c = -a, -b, -c x, y, u, v, k, l = 1, 0, 0, 1, a, b while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return c * x, c * y # --------- IsPrime --------- # def IsPrime(n): if n == 1: return False p = 2 while p * p <= n: if n % p == 0: return False p += 1 return True # --- fraction calculator --- # def fracsum(f1, f2, sign=1): fs = [f1[0] * f2[1] + sign * f1[1] * f2[0], f1[1] * f2[1]] g = gcd(fs[0], fs[1]) fs[0] //= g fs[1] //= g return fs def fracprod(f1, f2): fs = [f1[0] * f2[0], f1[1] * f2[1]] g = gcd(fs[0], fs[1]) fs[0] //= g fs[1] //= g return fs # ------ factorization ------ # def factorization(n): D = {} a = n p = 2 while a != 1: cnt = 0 while a % p == 0: cnt += 1 a //= p if cnt != 0: D[p] = cnt p += 1 if p * p > n and a != 1: D[a] = 1 break return D def divisors_list(D): F = [1] for i in D: mL = F[:] dp = i for j in range(D[i]): for k in mL: F.append(dp * k) dp *= i F.sort() return F def doubling(n, m, modulo=0): y = 1 base = n tmp = m while tmp: if tmp % 2 == 1: y *= base if modulo > 0: y %= modulo base *= base if modulo > 0: base %= modulo tmp //= 2 return y def inved(a, modulo): x, y, u, v, k, l = 1, 0, 0, 1, a, modulo while l != 0: x, y, u, v = u, v, x - u * (k // l), y - v * (k // l) k, l = l, k % l return x % modulo def bic(n): # count time divided by 2 cnt = 0 while n % 2 == 0: cnt += 1 n //= 2 return cnt def powlimit(n): y = 1 cnt = 0 while y < n: y *= 2 cnt += 1 return y, cnt def CRT(n, a, b): # x = a[i] mod b[i] r = a[0] bas = b[0] x, y = 0, 0 for i in range(1, n): x, y = extgcd(bas, -b[i], a[i] - r) r += bas * x bas *= b[i] return r % bas # making lists of mod and prim. root def mod_maker(cnt, num): bin_list = [1 for _ in range(cnt + 1)] for i in range(cnt, 0, -1): bin_list[i - 1] = 2 * bin_list[i] L = [] pm = [] bas = doubling(2, cnt) ccnt = 0 j = 1 while ccnt < num: if IsPrime(j * bas + 1): x = j * bas + 1 L.append(j * bas + 1) ccnt += 1 st = 1 flg = 0 while not flg: flg = doubling(st, bin_list[0], x) == 1 for k in range(cnt): flg *= doubling(st, bin_list[k + 1], x) != 1 if flg: pm.append(st) break st += 1 j += 2 return L, pm def NTT(f, n, cn, num, inverse=False): if n == 1: return f if n == 2: return [(f[0] + f[1]) % mod[num], (f[0] - f[1]) % mod[num]] dn = n // 2 fe = [f[2 * i + 0] for i in range(dn)] fo = [f[2 * i + 1] for i in range(dn)] fe = NTT(fe, dn, cn - 1, num, inverse) fo = NTT(fo, dn, cn - 1, num, inverse) seed = inverse * prim[num][cn] + (1 - inverse) * invp[num][cn] grow = 1 xf = [0 for _ in range(n)] for i in range(dn): right = fo[i] * grow % mod[num] xf[i + 0 * dn] = (fe[i] + right) % mod[num] xf[i + 1 * dn] = (fe[i] - right) % mod[num] grow *= seed grow %= mod[num] return xf # ----------- NTT test zone ----------- # N, M = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) pl, bn = powlimit(2 * max(N, M)) A = A[:] + [0] * (pl - N) B = B[:] + [0] * (pl - M) convolution_time = 1 # convolution level (number of 'mod's) binary_count = 23 mod, primod = [998244353], [31] prim = [ [ doubling(primod[j], doubling(2, binary_count - i), mod[j]) for i in range(binary_count) ] for j in range(convolution_time) ] invp = [ [inved(prim[j][i], mod[j]) for i in range(binary_count)] for j in range(convolution_time) ] X1 = NTT(A, pl, bn, 0) X2 = NTT(B, pl, bn, 0) XX = [X1[i] * X2[i] % mod[0] for i in range(pl)] Y = NTT(XX, pl, bn, 0, 1) ipl = inved(pl, mod[0]) for i in range(N + M - 1): Y[i] *= ipl Y[i] %= mod[0] print(Y[i], end=" " * (i != N + M - 2)) print()
Statement You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.
[{"input": "4 5\n 1 2 3 4\n 5 6 7 8 9", "output": "5 16 34 60 70 70 59 36\n \n\n* * *"}, {"input": "1 1\n 10000000\n 10000000", "output": "871938225"}]
Print the answer in the following format: c_0 c_1 ... c_{(N - 1) + (M - 1)} * * *
s157273732
Accepted
p02563
Input is given from Standard Input in the following format: N M a_0 a_1 ... a_{N-1} b_0 b_1 ... b_{M-1}
MOD = [469762049, 2281701377, 2483027969] D = dict() def DFTm(A, proot, mod, s): n = 1 << s m = n >> 1 if n == 1: return 0 X, Y = [], [] for i in range(0, n, 2): X.append(A[i]) Y.append(A[i + 1]) DFTm(X, proot, mod, s - 1) DFTm(Y, proot, mod, s - 1) a, b = 1, 0 if D.get((proot, s), -1) == -1: b = pow(proot, (mod - 1) >> s, mod) D[(proot, s)] = b else: b = D[(proot, s)] for i in range(n): A[i] = (X[i & (m - 1)] + a * Y[i & (m - 1)]) % mod a = a * b % mod def FFTm(X, Y, mod): n = 1 c = 0 while len(X) + len(Y) > n: n <<= 1 c += 1 A = X[:] B = Y[:] while len(A) < n: A.append(0) while len(B) < n: B.append(0) DFTm(A, 3, mod, c) DFTm(B, 3, mod, c) for i in range(n): A[i] = A[i] * B[i] % mod DFTm(A, pow(3, mod - 2, mod), mod, c) z = pow(n, mod - 2, mod) for i in range(n): A[i] = A[i] * z % mod return A N, M = map(int, input().split()) print( *FFTm(list(map(int, input().split())), list(map(int, input().split())), 998244353)[ : N + M - 1 ] )
Statement You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353.
[{"input": "4 5\n 1 2 3 4\n 5 6 7 8 9", "output": "5 16 34 60 70 70 59 36\n \n\n* * *"}, {"input": "1 1\n 10000000\n 10000000", "output": "871938225"}]
Print the string formed. * * *
s983912813
Accepted
p02830
Input is given from Standard Input in the following format: N S T
N = int(input()) S, T = input().split() ans = [0] * (N * 2) Scount = 0 Tcount = 1 for i in S: ans[Scount] = i Scount += 2 for j in T: ans[Tcount] = j Tcount += 2 print("".join(ans))
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the string formed. * * *
s250437606
Runtime Error
p02830
Input is given from Standard Input in the following format: N S T
n = int(input()) for _ in range(n): s, t = input().split() c = "" i = 0 j = 0 f = 0 for _ in range(len(s) + len(t)): if f == 0: c += s[i] i += 1 f = 1 else: c += t[j] j += 1 f = 0 print(c)
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the string formed. * * *
s970466705
Accepted
p02830
Input is given from Standard Input in the following format: N S T
n = int(input()) inp = input().split() b = inp[1] a = inp[0] f = "" i = 0 while i < n: f += a[i] + b[i] i += 1 print(f)
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the string formed. * * *
s901868311
Runtime Error
p02830
Input is given from Standard Input in the following format: N S T
s1, s2 = input() r = [[s[0], s[1]] for s in zip(s1, s2)] print("".join(["".join(s) for s in r]))
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the string formed. * * *
s050123964
Accepted
p02830
Input is given from Standard Input in the following format: N S T
# -*- 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() S, T = input().split() S = list(S) T = list(T) ans = [] for i in range(N): ans.append(S[i]) ans.append(T[i]) print("".join(ans))
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the string formed. * * *
s522237107
Runtime Error
p02830
Input is given from Standard Input in the following format: N S T
num = input() moji_list = input().split() new_moji = "" for i in range(num): new_moji = moji_list[0][i] + moji_list[1][i] print(new_moji)
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the string formed. * * *
s027426800
Wrong Answer
p02830
Input is given from Standard Input in the following format: N S T
tmp = input() print("".join(input().split()))
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the string formed. * * *
s730131977
Runtime Error
p02830
Input is given from Standard Input in the following format: N S T
num = int(input()) strs = input().split() for i in range(num): strs[1].insert(i, strs[0][i]) print(strs[1])
Statement Given are strings s and t of length N each, both consisting of lowercase English letters. Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.
[{"input": "2\n ip cc", "output": "icpc\n \n\n* * *"}, {"input": "8\n hmhmnknk uuuuuuuu", "output": "humuhumunukunuku\n \n\n* * *"}, {"input": "5\n aaaaa aaaaa", "output": "aaaaaaaaaa"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s129264814
Accepted
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [input() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(input()) for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def roundUp(a, b): return -(-a // b) @staticmethod def toUpperMultiple(a, x): return Math.roundUp(a, x) * x @staticmethod def toLowerMultiple(a, x): return (a // x) * x @staticmethod def nearPow2(n): if n <= 0: return 0 if n & (n - 1) == 0: return n ret = 1 while n > 0: ret <<= 1 n >>= 1 return ret @staticmethod def sign(n): if n == 0: return 0 if n < 0: return -1 return 1 @staticmethod def isPrime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True MOD = int(1e09) + 7 INF = int(1e15) def main(): # sys.stdin = open("sample.txt") N, M = Scanner.map_int() class Edge: def __init__(self, a, b, c): self.from_ = a self.to_ = b self.cost_ = c edges = [Edge] * M for i in range(M): a, b, c = Scanner.map_int() a -= 1 b -= 1 c = -c edges[i] = Edge(a, b, c) dist = [INF] * N dist[0] = 0 for loop in range(N - 1): for i in range(M): e = edges[i] if dist[e.from_] == INF: continue if dist[e.to_] > dist[e.from_] + e.cost_: dist[e.to_] = dist[e.from_] + e.cost_ ans = dist[N - 1] negatives = [False] * N for loop in range(N): for i in range(M): e = edges[i] if dist[e.from_] == INF: continue if dist[e.to_] > dist[e.from_] + e.cost_: dist[e.to_] = dist[e.from_] + e.cost_ negatives[e.to_] = True if negatives[e.from_]: negatives[e.to_] = True if negatives[N - 1]: print("inf") else: print(-ans) if __name__ == "__main__": main()
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s609529145
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
# -*- coding: utf-8 -*- inf = 10**50 n,m = map(int, input().split()) ea = [] eb = [] cost = [] for _ in range(m): a,b,c = map(int, input().split()) a -= 1 b -= 1 ea.append(a) eb.append(b) cost.append(-c) d = [inf for _ in range(n)] d[0] = 0 for _ in range(n): update = False for i in range(m): a = ea[i] b = eb[i] c = cost[i] if d[a]!=inf and d[b]>d[a]+c: d[b] = d[a]+c update = True if not update: break ans = d[n-1] negative = [False for _ in range(n)] for _ in range(n): update = False for i in range(m): a = ea[i] b = eb[i] c = cost[i] if d[a]!=inf and d[b]>d[a]+c: d[b] = d[a]+c negative[b] = True update = True if negative[a]: negative[b] = True update = True if no update: break # print(d) if negative[n-1]: print("inf") else: print(-ans)
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s451552160
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
import sys N,M=map(int, input().split()) a=[] b=[] c=[] for m in range (0,M): A,B,C=map(int, input().split() ) a+=[A] b+=[B] c+=[C] V=[0]*N# iに到達するときの最大得点 moji=[1]+[0]*(N-1)#infなら0をかえす for n in range(N-1): for m in range(M): u=a[m] v=b[m] if moji[a[m]-1]:#共に有限の時はやる if moji[b[m]-1]: V[b[m]-1]=max(V[b[m]-1],V[a[m]-1]+c[m]) else: V[b[m]-1]=V[a[m]-1]+c[m] moji[b[m]-1]=1 W=V[] for n in range(N-1): for m in range(M): u=a[m] v=b[m] if moji[a[m]-1]:#共に有限の時はやる if moji[b[m]-1]: W[b[m]-1]=max(W[b[m]-1],W[a[m]-1]+c[m]) else: W[b[m]-1]=W[a[m]-1]+c[m] moji[b[m]-1]=1 if V[N-1]==W[N-1]: print(V[N-1]) else: print("inf")
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s306882212
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
inf = float('inf') # distの初期化: dist = [inf for _ in range(N)]; dist[start] = 0 # True - >正常に更新, False -> 負閉路有り def bellmanford(dist,edges,N): for i in range(N): for v ,nv, w in edges: if dist[nv] > dist[v] + w: dist[nv] = dist[v] + w # 頂点数Nなら更新は高々N-1回で済む # N回目に更新を行うなら負閉路があるということ if i == N-1 nv == N-1: return False return True N,M = map(int,input().split()) info = [] for _ in range(M): a,b,c = map(int,input().split()) a -= 1; b -= 1; c = -c info.append((a,b,c)) dist = [inf for _ in range(N)] dist[0] = 0 flag = bellmanford(dist,info,N) ans = -dist[N-1] if flag is True else "inf" print(ans)
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s525222628
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
mport sys N,M=map(int, input().split()) a=[] b=[] c=[] for m in range (0,M): A,B,C=map(int, input().split() ) a+=[A] b+=[B] c+=[C] V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点 for n in range(N-1): for m in range(M): u=a[m] v=b[m] if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる V[b[m]-1]=V[a[m]-1]+c[m] moji2=[0]*N for n in range(N): for m in range(M): u=a[m] v=b[m] if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる V[b[m]-1]=V[a[m]-1]+c[m] moji2[b[m]-1]=1 if moji2[N-1]: print("inf") sys.exit() print(V[N-1])
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s482421325
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
N, M = map(int, input().split()) adjacent = [] score = ['None' for i in range(N)] score[0] = 0 for i in range(M): a, b, c = map(int, input().split()) adjacent.append([a-1, b-1, c]) for i in range(2N): for j in adjacent: if score[j[1]] == 'None' and score[j[0]] != 'None': score[j[1]] = score[j[0]] + j[2] if score[j[1]] != 'None' and score[j[0]] != 'None': if score[j[1]] < score[j[0]] + j[2]: score[j[1]] = score[j[0]] + j[2] if i == N-1: t = score[N-1] if i == 2N: if t != score[N-1]: score[N-1] = 1e+15 if score[N-1] < 1e+15: print(score[N-1]) else: print('inf')
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s251379953
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
mport sys N,M=map(int, input().split()) a=[] b=[] c=[] for m in range (0,M): A,B,C=map(int, input().split() ) a+=[A] b+=[B] c+=[C] V=[0]+[-10**12]*(N-1)# iに到達するときの最大得点 for n in range(N-1): for m in range(M): u=a[m] v=b[m] if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる V[b[m]-1]=V[a[m]-1]+c[m] moji2=[0]*N for n in range(N): for m in range(M): u=a[m] v=b[m] if V[b[m]-1]<V[a[m]-1]+c[m]:#共に有限の時はやる V[b[m]-1]=V[a[m]-1]+c[m] moji2[b[m]-1]=1 if moji2[N-1]: print("inf") sys.exit() else: print(V[N-1])
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s480856560
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
#Nは頂点数, Mは辺数(2 <= N <= 1000, 1 <= M <= min(N(N-1, 2000))) #頂点1から頂点Nに移動して、移動スコアを最大にする #->移動スコアを正負反転させれば最短経路問題 #->負閉路を考慮してベルマンフォード法を利用 INF = 1 << 50 N,M = map(int,input().split()) #辺を登録 Sides = [] for i in range (M): Sides.append(map(int,input().split())) #コストを反転 Sides[i][2] = Sides[i][2] * (-1) #各頂点の最短距離を初期化 Vertexes = [INF]*N+1 Vertexes[1] = [0] #負閉路のチェック用 negative = [False] * N+1 #ベルマンフォード法による最短距離探索 for count in range(N): for i in range(M): from_v = Sides[i][0] to_v = Sides[i][1] cost = Sides[i][2] if (Vertexes[to_v] > Vertexes[from_v]+cost): if(count==N): negative[to_v] = True: Vertexes[to_v] = Vertexes[from_v]+cost #負閉路の確認 for count in range(N-1): flag = 0 for i in range(M): from_v = Sides[i][0] to_v = Sides[i][1] if negative[from_v] and negative[to_v] is False: negative[to_v] = True flag = 1 if flag ==0: break if negative[N]: print('inf') else: print(Vertexes[N])
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s798063170
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(), (x).end() #define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;}) #define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end())) #define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;}) #define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end()) #define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl #define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i) #define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end())) #define OUT(x) cout<<x<<endl #define REP(i,n) FOR(i,0,n) struct edge { int to,cost; }; struct ftedge { int from,to,cost; }; typedef long long ll; typedef pair<ll, ll> P; typedef vector<int> VECINT; typedef vector<ll> VECLL; ll bellman_ford(int V, int s, vector<ftedge> es) { vector<ll> d(V,LLONG_MIN);d[s]=0; REP(i,V) { for (ftedge e:es) { if (d[e.from]!=INT_MIN && d[e.to]<d[e.from]+e.cost) { d[e.to] = d[e.from]+e.cost; if (i==V-1) return LLONG_MAX; } } } return d[V-1]; } int main() { int N,M;cin>>N>>M; vector<ftedge> es; REP(i,M) { int a,b,c;cin>>a>>b>>c; a--;b--; es.push_back({a,b,c}); } ll ans = bellman_ford(N,0,es); ans==LLONG_MAX ? OUT("inf") : OUT(ans); return 0; }
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s791089717
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
# -*- 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 def bellman_ford(N: int, edges: list, src: int) -> list: """ ベルマンフォード(頂点数, 辺集合(0-indexed), 始点) """ # 頂点[ある始点からの最短距離] (経路自体を知りたい時はここに前の頂点も持たせる) res = [INF] * N res[src] = 0 # 各辺によるコストの置き換えを頂点数N-1回繰り返す for _ in range(N-1): for src, dest, cost in edges: if res[dest] > res[src] + cost: res[dest] = res[src] + cost ans = res[N-1] # 負の閉路(いくらでもコストを減らせてしまう場所)がないかチェックする for _ in range(N-1): for src, dest, cost in edges: if res[dest] > res[src] + cost: res[dest] = res[src] + cost if ans != res[N-1] # あったら空リストを返却 return [] # 問題なければ頂点リストを返却 return res N, M = MAP() edges = [] for i in range(M): a, b, c = MAP() a -= 1; b -= 1 edges.append((a, b, -c)) res = bellman_ford(N, edges, 0) if res: print(-res[N-1]) else: print('inf')
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s023572224
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
n, m = map(int, input().split()) edge = [tuple(map(int, input().split())) for _ in range(m)] inf = 10 ** 18 dis = [inf] * n dis[0] = 0 for z in range(n+1) update = False for a, b, c in edge: a -= 1 b -= 1 if dis[a] != inf and dis[b] > dis[a] - c: dis[b] = dis[a] - c update = True if z == n: print('inf') exit() print(-dis[n-1])
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s994955033
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
inf=float('inf') n, m=map(int, input().split()) abc=[list(map(int, input().split())) for i in range(m)] abc=[[ai[0]-1, ai[1]-1, -ai[2]] for ai in abc] d=[inf]*n d[0]=0 for i in range(n): flag=False for abci in abc: if d[abci[1]]>d[abci[0]]+abci[2]: flag=True d[abci[1]]=d[abci[0]]+abci[2] if i==n-1 and abci[1]=n-1: print('inf') exit() print(-d[n-1])
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s777134548
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
6 5 1 2 -1000000000 2 3 -1000000000 3 4 -1000000000 4 5 -1000000000 5 6 -1000000000
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print `inf`. * * *
s086401953
Runtime Error
p03722
Input is given from Standard Input in the following format: N M a_1 b_1 c_1 a_2 b_2 c_2 : a_M b_M c_M
N,M = map(int,input().split()) edge = [0]*M for i in range(M): a,b,c=map(int,input().split()) a -= 1 b -= 1 c *= -1 edge[i] = (a,b,c) inf = float('inf') V = N E = M def shortest_path(s,d): for i in range(V): for j in range(E): From,To,cost = edge[j] if d[From] != inf and d[To]>d[From]+cost: d[To]=d[From]+cost return d d = [inf]*V d[0] = 0 d = shortest_path(0,d) d_ = shortest_path(0,d) if d[N-1]!=d_[N-1] print('inf') else: print(-d[N-1])
Statement There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex 1, and the score of the player is set to 0. The player can move the piece as follows: * When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i. The player can end the game only when the piece is placed at vertex N. The given graph guarantees that it is possible to traverse from vertex 1 to vertex N. When the player acts optimally to maximize the score at the end of the game, what will the score be? If it is possible to increase the score indefinitely, print `inf`.
[{"input": "3 3\n 1 2 4\n 2 3 3\n 1 3 5", "output": "7\n \n\nThere are two ways to move the piece to vertex N=3:\n\n * vertex 1 \u2192 vertex 2 \u2192 vertex 3 : score 4+3=7\n * vertex 1 \u2192 vertex 3 : score 5\n\nThus, the maximum possible score at the end of the game is 7.\n\n* * *"}, {"input": "2 2\n 1 2 1\n 2 1 1", "output": "inf\n \n\nIt is possible to increase the score indefinitely by alternating between\nvertex 1 and 2.\n\n* * *"}, {"input": "6 5\n 1 2 -1000000000\n 2 3 -1000000000\n 3 4 -1000000000\n 4 5 -1000000000\n 5 6 -1000000000", "output": "-5000000000"}]
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise. * * *
s650712683
Wrong Answer
p03688
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
print("No")
Statement There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
[{"input": "3\n 1 2 2", "output": "Yes\n \n\nFor example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it\nis consistent with the remarks of the cats.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "No\n \n\nFrom the remark of cat 1, we can see that cat 2 and 3 wear hats of the same\ncolor. Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats\nof the same color. Therefore, cat 1 and 2 wear hats of the same color, which\ncontradicts the remark of cat 3.\n\n* * *"}, {"input": "5\n 4 3 4 3 4", "output": "No\n \n\n* * *"}, {"input": "3\n 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "4\n 2 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "5\n 3 3 3 3 3", "output": "No"}]
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise. * * *
s630526521
Accepted
p03688
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
# 解説 def solve(): n = int(input()) a = tuple(map(int, input().split())) # n匹全体でA色とする # aloneな猫: a_i = A-1 # 同色がいる猫: a_i = A M = max(a) m = min(a) delta = M - m # 最大値と最小値の差 if delta > 1: return False # 各猫視点の色数の差は2以上にはならない elif delta == 1: # alone,同色ありが混在 # aloneな猫: a_i = A-1 # 同色がいる猫: a_i = A x = a.count(m) # alone猫数,この猫だけでx色ある y = n - x # 同色いる猫数 # 最低1色、最大でy//2色(2匹ずつに分けて、端数はどこかのグループに入れる) if x >= M: return False # x + y//2 = A # x = A - y//2 < A if (y - (M - x) * 2) not in {0, 1}: return False # x + y//2 = A # y//2 = A - x # y = (A - x) * 2 or (A - x) * 2 + 1 return True else: # if delta == 0 if all(a_ == n - 1 for a_ in a): return True # 全員alone=A-1=n-1 if all(a_ * 2 <= n for a_ in a): return True # 全員同色がいる=A # ooxxzz -> A=3: 色の総数は各グループが2匹以上なので、A*2<=n # oooxxx -> A=2 return False return True print("Yes" if solve() else "No")
Statement There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
[{"input": "3\n 1 2 2", "output": "Yes\n \n\nFor example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it\nis consistent with the remarks of the cats.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "No\n \n\nFrom the remark of cat 1, we can see that cat 2 and 3 wear hats of the same\ncolor. Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats\nof the same color. Therefore, cat 1 and 2 wear hats of the same color, which\ncontradicts the remark of cat 3.\n\n* * *"}, {"input": "5\n 4 3 4 3 4", "output": "No\n \n\n* * *"}, {"input": "3\n 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "4\n 2 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "5\n 3 3 3 3 3", "output": "No"}]
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise. * * *
s579875988
Runtime Error
p03688
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
import sys from collections import Counter sys.stdin = open("b1.in") def read_int_list(): return list(map(int, input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() yes, no = "Yes", "No" def solve(n, a): s = set(a) c = Counter(a) if len(s) == 1: a = list(s)[0] n_colors = a + 1 if n_colors == n: return yes n_colors = a if 2 * n_colors <= n: return yes if len(s) == 2: a, b = sorted(s) if a + 1 == b: n_colors = b appear_once = c[a] appear_twice_or_more = n_colors - appear_once if appear_once < n_colors: if c[b] >= 2 * appear_twice_or_more: return yes return no n = read_int() a = read_int_list() res = solve(n, a) print(res)
Statement There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
[{"input": "3\n 1 2 2", "output": "Yes\n \n\nFor example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it\nis consistent with the remarks of the cats.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "No\n \n\nFrom the remark of cat 1, we can see that cat 2 and 3 wear hats of the same\ncolor. Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats\nof the same color. Therefore, cat 1 and 2 wear hats of the same color, which\ncontradicts the remark of cat 3.\n\n* * *"}, {"input": "5\n 4 3 4 3 4", "output": "No\n \n\n* * *"}, {"input": "3\n 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "4\n 2 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "5\n 3 3 3 3 3", "output": "No"}]
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise. * * *
s125136047
Wrong Answer
p03688
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
print("Yes")
Statement There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
[{"input": "3\n 1 2 2", "output": "Yes\n \n\nFor example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it\nis consistent with the remarks of the cats.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "No\n \n\nFrom the remark of cat 1, we can see that cat 2 and 3 wear hats of the same\ncolor. Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats\nof the same color. Therefore, cat 1 and 2 wear hats of the same color, which\ncontradicts the remark of cat 3.\n\n* * *"}, {"input": "5\n 4 3 4 3 4", "output": "No\n \n\n* * *"}, {"input": "3\n 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "4\n 2 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "5\n 3 3 3 3 3", "output": "No"}]
Print `Yes` if there exists a sequence of colors of the hats that is consistent with the remarks of the cats; print `No` otherwise. * * *
s148140873
Wrong Answer
p03688
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())) print("Yes")
Statement There are N cats. We number them from 1 through N. Each of the cats wears a hat. Cat i says: "there are exactly a_i different colors among the N - 1 hats worn by the cats except me." Determine whether there exists a sequence of colors of the hats that is consistent with the remarks of the cats.
[{"input": "3\n 1 2 2", "output": "Yes\n \n\nFor example, if cat 1, 2 and 3 wears red, blue and blue hats, respectively, it\nis consistent with the remarks of the cats.\n\n* * *"}, {"input": "3\n 1 1 2", "output": "No\n \n\nFrom the remark of cat 1, we can see that cat 2 and 3 wear hats of the same\ncolor. Also, from the remark of cat 2, we can see that cat 1 and 3 wear hats\nof the same color. Therefore, cat 1 and 2 wear hats of the same color, which\ncontradicts the remark of cat 3.\n\n* * *"}, {"input": "5\n 4 3 4 3 4", "output": "No\n \n\n* * *"}, {"input": "3\n 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "4\n 2 2 2 2", "output": "Yes\n \n\n* * *"}, {"input": "5\n 3 3 3 3 3", "output": "No"}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s603684001
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
N, C = map(int, input().split()) xv = [[0, 0]] + [list(map(int, input().split())) for i in range(N)] + [[C, 0]] # 0~N+1 # xがある位置 # vがカロリー # 時計回りでの最大値 tokei_maxs = [0] * (N + 2) # 時計まわりでの最大値(現状) tokei = [0] * (N + 2) tokei_max = 0 preans = 0 for i in range(1, N + 1, 1): tmpans = preans + xv[i][1] - (xv[i][0] - xv[i - 1][0]) tokei_max = max(tokei_max, tmpans) tokei[i] = tmpans tokei_maxs[i] = tokei_max preans = tmpans # h時計回りでの最大値 htokei_maxs = [0] * (N + 2) htokei = [0] * (N + 2) # h時計まわりでの最大値(現状) htokei_max = 0 preans = 0 for i in range(N, 0, -1): tmpans = preans + xv[i][1] - (xv[i + 1][0] - xv[i][0]) htokei_max = max(htokei_max, tmpans) htokei_maxs[i] = htokei_max htokei = tmpans preans = tmpans ans = 0 for i in range(0, N + 1, 1): ans = max(ans, tokei[i] + max(0, htokei_maxs[i + 1] - xv[i][0])) for i in range(N + 1, 0, 1): ans = max(ans, htokei[i] + max(0, tokei_maxs[i - 1] - C + xv[i][0])) print(ans)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s294589844
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
# -*- coding: utf-8 -*- ############# # 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, L = IL() XA = [0] C = [] for _ in range(N): x, c = IL() XA.append(x) C.append(c) XB = [0] for x in XA[:0:-1]: XB.append(L - x) CA = [0] CB = [0] for c in C: CA.append(CA[-1] + c) for c in C[::-1]: CB.append(CB[-1] + c) A = [0] AA = [0] B = [0] BB = [0] for i in range(1, N + 1): A.append(CA[i] - XA[i]) AA.append(CA[i] - XA[i] * 2) for i in range(1, N + 1): B.append(CB[i] - XB[i]) BB.append(CB[i] - XB[i] * 2) MAXA = [] MAX = 0 for a in A: MAX = max(MAX, a) MAXA.append(MAX) MAXB = [] MAX = 0 for b in B: MAX = max(MAX, b) MAXB.append(MAX) MAX = 0 for i in range(N + 1): MAX = max(MAX, AA[i] + MAXB[N - i]) for i in range(N + 1): MAX = max(MAX, BB[i] + MAXA[N - i]) print(MAX)
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s404181598
Accepted
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
#!/usr/bin/env python3 from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random import itertools sys.setrecursionlimit(10**5) stdin = sys.stdin bisect_left = bisect.bisect_left bisect_right = bisect.bisect_right def LI(): return list(map(int, stdin.readline().split())) def LF(): return list(map(float, stdin.readline().split())) def LI_(): return list(map(lambda x: int(x) - 1, stdin.readline().split())) def II(): return int(stdin.readline()) def IF(): return float(stdin.readline()) def LS(): return list(map(list, stdin.readline().split())) def S(): return list(stdin.readline().rstrip()) def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = float("INF") # A def A(): s = S() s.append("o") a = s.count("o") - 1 print(700 + a * 100) return # B def B(): n, x = LI() m = IR(n) m.sort() msum = sum(m) print(n + (x - msum) // m[0]) return # C def C(): a, b, c, x, y = LI() if c * 2 > a + b: print(x * a + y * b) return if x > y: if c * 2 > a: print(c * 2 * y + (x - y) * a) return print(c * 2 * x) return if c * 2 > b: print(c * 2 * x + (y - x) * b) return print(c * 2 * y) return # D def D(): n, c = LI() clock_wise = [0] * n clock_wise_max = [0] * n clock_wise_rev = [0] * n clock_wise_rev_max = [0] * n xv = LIR(n) clock_wise[0] = xv[0][1] - xv[0][0] clock_wise_rev[-1] = -c + xv[-1][1] + xv[-1][0] for i in range(1, n): clock_wise[i] = clock_wise[i - 1] + xv[i][1] - xv[i][0] + xv[i - 1][0] clock_wise_rev[-i - 1] = ( clock_wise_rev[-i] + xv[-i - 1][1] + xv[-i - 1][0] - xv[-i][0] ) clock_wise_max[0] = clock_wise[0] clock_wise_rev_max[-1] = clock_wise_rev[-1] for i in range(1, n): clock_wise_max[i] = max(clock_wise[i], clock_wise_max[i - 1]) clock_wise_rev_max[-i - 1] = max(clock_wise_rev[-i - 1], clock_wise_rev_max[-i]) ans = max(0, max(clock_wise), max(clock_wise_rev)) for i in range(n - 1): ans = max(ans, clock_wise[i] + clock_wise_rev_max[i + 1] - xv[i][0]) ans = max( ans, clock_wise_rev[-i - 1] + clock_wise_max[-i - 2] - (c - xv[-i - 1][0]) ) print(ans) return # Solve if __name__ == "__main__": D()
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c. * * *
s881904944
Wrong Answer
p03372
Input is given from Standard Input in the following format: N C x_1 v_1 x_2 v_2 : x_N v_N
n, c = map(int, input().split()) ls = [map(int, input().split()) for i in range(n)] acc = 0 temp = [0] for x, v in ls: acc += v temp.append(acc - x) print(max(temp))
Statement "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter. Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories. Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter. Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.
[{"input": "3 20\n 2 80\n 9 120\n 16 1", "output": "191\n \n\nThere are three sushi on the counter with a circumference of 20 meters. If he\nwalks two meters clockwise from the initial place, he can eat a sushi of 80\nkilocalories. If he walks seven more meters clockwise, he can eat a sushi of\n120 kilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 9 kilocalories, thus he can\ntake in 191 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "3 20\n 2 80\n 9 1\n 16 120", "output": "192\n \n\nThe second and third sushi have been swapped. Again, if he walks two meters\nclockwise from the initial place, he can eat a sushi of 80 kilocalories. If he\nwalks six more meters counterclockwise this time, he can eat a sushi of 120\nkilocalories. If he leaves now, the total nutrition taken in is 200\nkilocalories, and the total energy consumed is 8 kilocalories, thus he can\ntake in 192 kilocalories on balance, which is the largest possible value.\n\n* * *"}, {"input": "1 100000000000000\n 50000000000000 1", "output": "0\n \n\nEven though the only sushi is so far that it does not fit into a 32-bit\ninteger, its nutritive value is low, thus he should immediately leave without\ndoing anything.\n\n* * *"}, {"input": "15 10000000000\n 400000000 1000000000\n 800000000 1000000000\n 1900000000 1000000000\n 2400000000 1000000000\n 2900000000 1000000000\n 3300000000 1000000000\n 3700000000 1000000000\n 3800000000 1000000000\n 4000000000 1000000000\n 4100000000 1000000000\n 5200000000 1000000000\n 6600000000 1000000000\n 8000000000 1000000000\n 9300000000 1000000000\n 9700000000 1000000000", "output": "6500000000\n \n\nAll these sample inputs above are included in the test set for the partial\nscore."}]