output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s567421170
Accepted
p03631
Input is given from Standard Input in the following format: N
print((lambda x: "Yes" if x == x[::-1] else "No")(list(input())))
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s211000109
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = input() if n = n[::-1]: print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s600374050
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = str(input()) if n == n[::-1]: print("Yes") else("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s527069610
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N = input() if N[0] =- N[2]: print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s282648214
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N = input() if N = N[::-1]: r = 'Yes' else: r = 'No' print(r)
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s869246322
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = input() if n[0] == n[2]: print("Yes) else: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s524442108
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N = input() if N = N[::-1]: print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s563382714
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a = int(input()) if a[0] == a[2]: print("Yes") els: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s481689532
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = input() if n[0]=n[2]: priint('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s455839468
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N = str(input()) if N == N[::-1] print('Yes') else print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s626636018
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n=input() if n[0]==n[2[]: print("Yes") else: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s204147872
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = list(map(str, input())) if n[0] = n[2]: print("Yes") else: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s134822421
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a=input() b=.join(reversed(a)); if(a==b): print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s996535128
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N = input() rN = N[::-1] if N = rN: r = 'Yes' else: r = 'No' print(r)
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s316371286
Runtime Error
p03631
Input is given from Standard Input in the following format: N
if (n = input().split())[0] == n[2] : print('Yes') else : print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s811435804
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a = map(int.input().split()) if a[0]=a[-1]: print("YES") else: print("NO")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s148204659
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a = input() b = a[0] c = a[2] if b = c: print("Yes") else: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s396084801
Runtime Error
p03631
Input is given from Standard Input in the following format: N
A, B, C, D = map(int, input().split()) print(max(0, min(B, D) - max(A, C)))
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s139811794
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N=int(input()) if (N[0]==N[-1]): print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s116309637
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a = list(int.input().split()) if a[0]=a[-1]: print("YES") else: print("NO")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s402302362
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a=[int(d) for d in str(n)]; if b==a[-1:]; return True else: return False
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s994674821
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a = int(input().split()) if a[0]=a[-1]: print("YES") else: print("NO")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s451371802
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a = list(int,input().split()) if a[0]=a[-1]: print("YES") else: print("NO")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s526398383
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N = input() if (N = N[::-1]): print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s286682224
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a, b, c, d = list(map(int, input().split())) print(max(max(b, d) - min(a, c), 0))
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s858712974
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = int(input()) if (int)n/100==n%10: print("Yes") else: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s730482341
Runtime Error
p03631
Input is given from Standard Input in the following format: N
N=input() if N[0]==N[-1]: print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s795495491
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = list(input()) if n[0]==n[2]: print("Yes") else: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s577957128
Runtime Error
p03631
Input is given from Standard Input in the following format: N
print(["No", "Yes"][input() == input()[::-1]])
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s976131893
Runtime Error
p03631
Input is given from Standard Input in the following format: N
a,b,c=input() print('Yes' if a==c,else 'No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s931337557
Runtime Error
p03631
Input is given from Standard Input in the following format: N
l = input() print("Yes" if l[0]=l[2] else "No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s074630097
Runtime Error
p03631
Input is given from Standard Input in the following format: N
s = map(int, input().split()) A, B, C, D = [i for i in s] greater = max(A, C) less = min(B, D) if min(0, greater - less):  print(min(0, greater- less) else: print("0")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s067913579
Runtime Error
p03631
Input is given from Standard Input in the following format: N
# encoding:utf-8 import sys def main(): n = int(input()) vers = [list(map(int, input().split())) for _ in range(n - 1)] q, k = list(map(int, input().split())) queries = [list(map(int, input().split())) for _ in range(q)] # n = 10 ** 5 # vers = [[i + 1, i + 2, 10 ** 9] for i in range(n - 1)] new_vers = mapping(n, vers) dist = calcMinDist(n, new_vers, k, queries) calcQueries(dist, queries, k) def mapping(n, vers): new_vers = {i: [] for i in range(n)} for ver in vers: new_vers[ver[0] - 1].append((ver[1], ver[2])) new_vers[ver[1] - 1].append((ver[0], ver[2])) return new_vers def calcMinDist(n, new_vers, k, queries): dist = [-1 for _ in range(n)] flag = [False for _ in range(n)] dist[k - 1] = 0 flag[k - 1] = True dfs(new_vers, dist, flag, k) return dist def dfs(new_vers, dist, flag, frm): flag[frm - 1] = True vs = new_vers[frm - 1] for v in vs: if flag[v[0] - 1] == False: dist[v[0] - 1] = dist[frm - 1] + v[1] new_ver, dist, flag, _ = dfs(new_vers, dist, flag, v[0]) return [new_vers, dist, flag, frm] def calcQuery(dist, query, k): print(dist[query[0] - 1] + dist[query[1] - 1]) def calcQueries(dist, queries, k): for query in queries: calcQuery(dist, query, k) if __name__ == "__main__": sys.setrecursionlimit(1000000) main()
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s939036350
Runtime Error
p03631
Input is given from Standard Input in the following format: N
print("Yes") if str(input()) == str(input())[::-1] else print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s380518118
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n=str(input()) if n[0]=n[2]: print("Yes") else: print("No")
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
If N is a palindromic number, print `Yes`; otherwise, print `No`. * * *
s329705339
Runtime Error
p03631
Input is given from Standard Input in the following format: N
n = int(input()) if str(n[0]) = str(n[2]): print('Yes') else: print('No')
Statement You are given a three-digit positive integer N. Determine whether N is a _palindromic number_. Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.
[{"input": "575", "output": "Yes\n \n\nN=575 is also 575 when read backward, so it is a palindromic number. You\nshould print `Yes`.\n\n* * *"}, {"input": "123", "output": "No\n \n\nN=123 becomes 321 when read backward, so it is not a palindromic number. You\nshould print `No`.\n\n* * *"}, {"input": "812", "output": "No"}]
Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s575190733
Accepted
p02309
The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers.
from math import sqrt if __name__ == "__main__": c1x, c1y, c1r = map(float, input().split()) c2x, c2y, c2r = map(float, input().split()) dx, dy = c2x - c1x, c2y - c1y cdist = dx**2 + dy**2 a = (cdist + c1r**2 - c2r**2) / 2 df = sqrt(cdist * c1r**2 - a**2) ix1, ix2 = (a * dx + dy * df) / cdist, (a * dx - dy * df) / cdist iy1, iy2 = (a * dy - dx * df) / cdist, (a * dy + dx * df) / cdist if (ix1, iy1) > (ix2, iy2): ix1, ix2, iy1, iy2 = ix2, ix1, iy2, iy1 print(ix1 + c1x, iy1 + c1y, ix2 + c1x, iy2 + c1y)
Cross Points of Circles For given two circles $c1$ and $c2$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input 1\n\n \n \n 0 0 2\n 2 0 2", "output": "1.00000000 -1.73205080 1.00000000 1.73205080"}, {"input": "0 0 2\n 0 3 1", "output": "0.00000000 2.00000000 0.00000000 2.00000000"}]
Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s475260563
Accepted
p02309
The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers.
import math class Vector2: def __init__(self, x, y): self.x = x self.y = y def __add__(self, v): return Vector2(self.x + v.x, self.y + v.y) def __sub__(self, v): return Vector2(self.x - v.x, self.y - v.y) def __mul__(self, v): return Vector2(self.x * v, self.y * v) def __truediv__(self, v): return Vector2(self.x / v, self.y / v) def __abs__(self): return math.sqrt(float(self.x * self.x + self.y * self.y)) def __str__(self): return f"({self.x},{self.y})" def __lt__(self, v): if math.isclose(self.x, v.x): return self.y < v.y return self.x < v.x def dot(self, v): return self.x * v.x + self.y * v.y def cross(self, v): return self.x * v.y - self.y * v.x def norm(self): d = abs(self) return Vector2(self.x / d, self.y / d) def projection(v1, v2, p): v12 = (v2 - v1).norm() v1p = p - v1 d = v12.dot(v1p) return v1 + v12 * d def distanceLP(v1, v2, p): """ v1 -> v2の直線とpとの距離 """ return abs((v2 - v1).cross(p - v1)) / abs(v2 - v1) def distanceSP(v1, v2, p): """ v1 -> v2の線分とpとの距離 """ if (v2 - v1).dot(p - v1) < 0.0: return abs(p - v1) if (v1 - v2).dot(p - v2) < 0.0: return abs(p - v2) return distanceLP(v1, v2, p) def ccw(p0, p1, p2): c = (p1 - p0).cross(p2 - p0) if math.isclose(c, 0.0, abs_tol=1e-10): d = (p1 - p0).dot(p2 - p0) if d < 0.0: return -1 else: d1 = abs(p1 - p0) d2 = abs(p2 - p0) if d1 < d2: return 1 else: return 0 elif c < 0.0: return -1 else: return 1 def intersect(p1, p2, p3, p4): """ p1p2とp3p4の交差判定 """ # t1 = (p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x) # t2 = (p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x) # t3 = (p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x) # t4 = (p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x) # return (t1*t2) <= 0.0 and (t3*t4) <= 0.0 c1 = ccw(p1, p2, p3) * ccw(p1, p2, p4) c2 = ccw(p3, p4, p1) * ccw(p3, p4, p2) return c1 <= 0.0 and c2 <= 0.0 def distance(a1, a2, b1, b2): """ 線分a1a2とb1b2の距離 """ if intersect(a1, a2, b1, b2): return 0.0 return min( [ min([distanceSP(a1, a2, b1), distanceSP(a1, a2, b2)]), min([distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)]), ] ) cx1, cy1, r1 = map(int, input().split()) cx2, cy2, r2 = map(int, input().split()) c1 = Vector2(cx1, cy1) c2 = Vector2(cx2, cy2) c12 = c2 - c1 d = abs(c12) # 余弦定理 a = math.acos((r1 * r1 + d * d - r2 * r2) / (2 * r1 * d)) t = math.atan2(c12.y, c12.x) a1 = c1 + Vector2(math.cos(t + a) * r1, math.sin(t + a) * r1) a2 = c1 + Vector2(math.cos(t - a) * r1, math.sin(t - a) * r1) ans = "" for a in sorted([a1, a2]): ans += f"{a.x:.8f} {a.y:.8f} " print(ans.strip())
Cross Points of Circles For given two circles $c1$ and $c2$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input 1\n\n \n \n 0 0 2\n 2 0 2", "output": "1.00000000 -1.73205080 1.00000000 1.73205080"}, {"input": "0 0 2\n 0 3 1", "output": "0.00000000 2.00000000 0.00000000 2.00000000"}]
Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s506281256
Wrong Answer
p02309
The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers.
x1, y1, r1 = map(float, input().split()) x2, y2, r2 = map(float, input().split()) a, b = x2 - x1, y2 - y1 d = (a**2 + b**2 + r1**2 - r2**2) / 2 x = (d * a + b * (((a**2 + b**2) * r1**2 - d**2) ** 0.5)) / (a**2 + b**2) y = (d * b - a * (((a**2 + b**2) * r1**2 - d**2) ** 0.5)) / (a**2 + b**2) print(x1 + x, y1 + y, end=" ") x = (d * a - b * (((a**2 + b**2) * r1**2 - d**2) ** 0.5)) / (a**2 + b**2) y = (d * b + a * (((a**2 + b**2) * r1**2 - d**2) ** 0.5)) / (a**2 + b**2) print(x1 + x, y1 + y)
Cross Points of Circles For given two circles $c1$ and $c2$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input 1\n\n \n \n 0 0 2\n 2 0 2", "output": "1.00000000 -1.73205080 1.00000000 1.73205080"}, {"input": "0 0 2\n 0 3 1", "output": "0.00000000 2.00000000 0.00000000 2.00000000"}]
Print the coordinates ($x1$, $y1$) and ($x2$, $y2$) of the cross points $p1$ and $p2$ respectively in the following rules. * If there is one cross point, print two coordinates with the same values. * Print the coordinate with smaller $x$ first. In case of a tie, print the coordinate with smaller $y$ first. The output values should be in a decimal fraction with an error less than 0.000001.
s411022967
Accepted
p02309
The input is given in the following format. $c1x\; c1y\; c1r$ $c2x\; c2y\; c2r$ $c1x$, $c1y$ and $c1r$ represent the coordinate and radius of the first circle. $c2x$, $c2y$ and $c2r$ represent the coordinate and radius of the second circle. All input values are given in integers.
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 0 0 2 2 0 2 output: 1.00000000 -1.73205080 1.00000000 1.73205080 """ import sys from math import sin, cos, atan2, acos class Circle(object): __slots__ = ("centre", "radius") def __init__(self, centre=float("inf"), radius=-1): self.centre = complex(centre) self.radius = float(radius) def arg(p_vector): return atan2(p_vector.imag, p_vector.real) def polar(a, r): return cos(r) * a + sin(r) * a * 1j def get_circles_cross_points(c1, c2): centre_distance = abs(c1.centre - c2.centre) a = acos( (pow(c1.radius, 2) + pow(centre_distance, 2) - pow(c2.radius, 2)) / (2 * c1.radius * centre_distance) ) t = arg(c2.centre - c1.centre) p1, p2 = c1.centre + polar(c1.radius, t + a), c1.centre + polar(c1.radius, t - a) if p1.real < p2.real: ans = (p1, p2) elif p1.real == p2.real: if p1.imag < p2.imag: ans = (p1, p2) else: ans = (p2, p1) else: ans = (p2, p1) return ans def solve(_circle_info): for i, circle in enumerate(_circle_info): cx, cy, r = map(int, circle) circles[i].centre = cx + cy * 1j circles[i].radius = r cp1, cp2 = get_circles_cross_points(*circles) print( "{0:.8f} {1:.8f} {2:.8f} {3:.8f}".format(cp1.real, cp1.imag, cp2.real, cp2.imag) ) return None if __name__ == "__main__": _input = sys.stdin.readlines() circle_info = map(lambda x: x.split(), _input) circles = [Circle() for _ in range(2)] solve(circle_info)
Cross Points of Circles For given two circles $c1$ and $c2$, print the coordinates of the cross points of them.
[{"input": "and Output\n\n \n\n## Sample Input 1\n\n \n \n 0 0 2\n 2 0 2", "output": "1.00000000 -1.73205080 1.00000000 1.73205080"}, {"input": "0 0 2\n 0 3 1", "output": "0.00000000 2.00000000 0.00000000 2.00000000"}]
Print the answer. * * *
s579797700
Accepted
p02759
Input is given from Standard Input in the following format: N
print(int(input()) + 1 >> 1)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s932982565
Runtime Error
p02759
Input is given from Standard Input in the following format: N
print(int(input) + 1 // 2)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s713829413
Runtime Error
p02759
Input is given from Standard Input in the following format: N
import bisect import sys sys.setrecursionlimit(10**9) def main(): N = int(input()) S = list(input()) a_ord = ord("a") z_ord = ord("z") set_list = [[] for _ in range(z_ord + 1)] for i in range(N): s = S[i] set_list[ord(s)].append(i) Q = int(input()) for q in range(Q): ipt = input().split() if ipt[0] == "1": i, c = int(ipt[1]), ipt[2] j = ord(S[i - 1]) if j == ord(c): continue set_list[j].remove(i - 1) bisect.insort_left(set_list[ord(c)], i - 1) S[i - 1] = c # print(set_list[]) else: l, r = int(ipt[1]), int(ipt[2]) ans = 0 # if l == r: # print(1) # continue for i in range(a_ord, z_ord + 1): st = set_list[i] if not len(st) > 0: continue # print(i,set_list[i]) l_p = bisect.bisect_left(st, l - 1) r_p = bisect.bisect_right(st, r - 1) # print(l-1,r-1,l_p,r_p) if l_p < r_p: ans += 1 # print(ans,"____") print(ans) if __name__ == "__main__": main()
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s146129743
Runtime Error
p02759
Input is given from Standard Input in the following format: N
import sys sys.setrecursionlimit(4100000) line = input().split() nPerson = int(line[0]) nFriend = int(line[1]) nBlock = int(line[2]) friends = [[] for i in range(nFriend)] for i in range(nFriend): line = input().split() friends[i] = [int(line[0]), int(line[1])] blocks = [[] for i in range(nBlock)] for i in range(nBlock): line = input().split() blocks[i] = [int(line[0]), int(line[1])] connected = [[] for i in range(nPerson + 1)] for i in friends: if i[1] not in connected[i[0]]: connected[i[0]].append(i[1]) if i[0] not in connected[i[1]]: connected[i[1]].append(i[0]) blocked = [[] for i in range(nPerson + 1)] for i in blocks: if i[1] not in blocked[i[0]]: blocked[i[0]].append(i[1]) if i[0] not in blocked[i[1]]: blocked[i[1]].append(i[0]) for i in range(len(connected)): connected[i] = set(connected[i]) for i in range(len(blocked)): blocked[i] = set(blocked[i]) nCand = [0] * (nPerson + 1) def findCand(target, curPer): if visited[curPer] == True: return visited[curPer] = True if curPer not in connected[target] and curPer not in blocked[target]: nCand[target] += 1 for i in connected[curPer]: findCand(target, i) for i in range(1, nPerson + 1): visited = [False] * (nPerson + 1) visited[i] = True for j in connected[i]: findCand(i, j) res = "" for i in range(1, nPerson + 1): res += str(nCand[i]) + " " print(res)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s053614471
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
for i in range(1, 101): if i % 2 != 0: ans = (i // 2) + 1 if i % 2 == 0: ans = i // 2 print(round(ans, 2))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s231533401
Accepted
p02759
Input is given from Standard Input in the following format: N
print((int(input()) + 2 - 1) // 2)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s574744368
Accepted
p02759
Input is given from Standard Input in the following format: N
X = int(input()) print(X // 2 + (1 if X % 2 == 1 else 0))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s344173878
Runtime Error
p02759
Input is given from Standard Input in the following format: N
def make_label(x, y, a, b, label, m): h = False g = [] for i in range(m): if a[i] == x and label[b[i] - 1] == 0: label[b[i] - 1] = y g.append(b[i]) h = True elif b[i] == x and label[a[i] - 1] == 0: label[a[i] - 1] = y h = True g.append(a[i]) if h: for i in range(len(g)): return make_label(g[i], y, a, b, label, m) else: return label n, m, k = map(int, input().split()) a = [0] * m b = [0] * m c = [0] * k d = [0] * k label = [0] * n kosu_label = 1 friend = [0] * n block = [0] * n ans = [0] * n for i in range(m): a[i], b[i] = map(int, input().split()) for i in range(k): c[i], d[i] = map(int, input().split()) for i in range(n): if label[i] == 0: label[i] = kosu_label label = make_label(i + 1, kosu_label, a, b, label, m) kosu_label = kosu_label + 1 label_s = [0] * kosu_label for i in range(n): label_s[label[i]] = label_s[label[i]] + 1 for i in range(n): for j in range(m): if a[j] == i + 1 or b[j] == i + 1: friend[i] = friend[i] + 1 for w in range(k): if (c[w] == i + 1 or d[w] == i + 1) and label[c[w] - 1] == label[d[w] - 1]: block[i] = block[i] + 1 ans[i] = label_s[label[i]] - friend[i] - block[i] - 1 for i in range(n): print(ans[i], end="")
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s374476763
Runtime Error
p02759
Input is given from Standard Input in the following format: N
N, M = map(int, input().split()) S = [] C = [] for i in range(M): temp1, temp2 = map(int, input().split()) S.append(temp1) C.append(temp2) Flag = True temp = [-1, -1, -1] for i in range(M): if S[i] == 3: if temp[2] == -1: temp[2] = C[i] else: if temp[2] == C[i]: next else: Flag = False for i in range(M): if S[i] == 2: if temp[1] == -1: temp[1] = C[i] else: if temp[1] == C[i]: next else: Flag = False for i in range(M): if S[i] == 1: if temp[0] == -1: temp[0] = C[i] else: if temp[0] == C[i]: next else: Flag = False a = "" if Flag == False: print(-1) elif temp[0] == 0: print(-1) elif temp[2] == -1: if temp[1] == -1: print(temp[0]) elif temp[0] == -1: print(int(str(1) + str(temp[1]))) else: if temp[0] == 0: print(-1) else: print(int(str(temp[0]) + str(temp[1]))) else: if temp[0] == -1 and temp[1] == -1: print(temp[2]) elif temp[0] == -1 and temp[1] != -1: if temp[0] == 0: print(-1) else: print(int(str(temp[1]) + str(temp[2]))) elif temp[0] != -1 and temp[1] == -1: if temp[0] == 0: print(-1) else: print(int(str(temp[0]) + str(0) + str(temp[2]))) else: if temp[0] == 0: print(-1) else: print(int(str(temp[0]) + str(temp[1]) + str(temp[2])))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s703912015
Accepted
p02759
Input is given from Standard Input in the following format: N
p = int(input()) print((p + 1) // 2)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s647582154
Accepted
p02759
Input is given from Standard Input in the following format: N
a = int(input()) + 1 print(int(a / 2))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s653971513
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
print(-(-int(input())) // 2)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s306829682
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
print(int(input()) // 2 + 1)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s134422730
Runtime Error
p02759
Input is given from Standard Input in the following format: N
print((input() + 1) // 2)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s254961587
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
print(input())
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s497640527
Runtime Error
p02759
Input is given from Standard Input in the following format: N
N = input().split() Page = N % 2 print(Page)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s119646163
Accepted
p02759
Input is given from Standard Input in the following format: N
def s_in(): return input() def n_in(): return int(input()) def l_in(): return list(map(int, input().split())) class Interval: def __init__(self, li): self.li = li self.n = len(li) self.sum_li = [li[0]] for i in range(1, self.n): self.sum_li.append(self.sum_li[i - 1] + li[i]) def sum(self, a, b=None): if b is None: return self.sum(0, a) res = self.sum_li[min(self.n - 1, b - 1)] if a > 0: res -= self.sum_li[a - 1] return res import math N = n_in() print(math.ceil(N / 2))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s417540887
Runtime Error
p02759
Input is given from Standard Input in the following format: N
line_b = list(map(int, input().split(" "))) line = [] num = [] for i in range(line_b[0]): num += [0] for i in range(line_b[1]): line += [list(map(int, input().split(" ")))] for i in range(line_b[1]): if num[line[i][0] - 1] == 0: num[line[i][0] - 1] = line[i][1] elif num[line[i][0] - 1] != line[i][1]: num[0] = 0 break for i in range(line_b[1]): for j in range(line_b[1]): if line[i][0] == line[j][0] and line[i][1] != line[j][1]: num[0] = 0 if num[0] == 0: print(-1) else: number = 0 for i in range(line_b[0]): number += num[i] * 10 ** (line_b[0] - 1 - i) print("%d" % number)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s150617654
Runtime Error
p02759
Input is given from Standard Input in the following format: N
a, b, c = list(map(int, input().split())) d, e, f = list(map(int, input().split())) g, h, k = list(map(int, input().split())) N = int(input()) l = [] for i in range(N): e = int(input()) l.append(e) L1 = {a, d, g} L2 = {a, b, c} L3 = {a, e, k} L4 = {c, f, k} L5 = {g, h, k} L6 = {c, e, g} for i in range(N): for j in range(N): for k in range(N): s = set([l[i], l[j], l[k]]) if ( (s == L1) or (s == L2) or (s == L3) or (s == L4) or (s == L5) or (s == L6) ): print("Yes") exit(0) print("No")
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s947955545
Runtime Error
p02759
Input is given from Standard Input in the following format: N
import sys ar = [] x = sys.stdin.readline() x = x.split(" ") (n, m) = [int(str) for str in x] ret = 0 chk = [] for i in range(m): x = sys.stdin.readline() x = x.split(" ") (s, c) = [int(str) for str in x] if not (s in chk): if n - s >= 0: ret += c * 10 ** (n - s) chk.append(s) else: if c != int(ret / 10 ** (n - s)): print("-1") exit(0) if ret == 0 and n == 1: print("0") exit(0) if ret < 10 ** (n - 1): if not (n - 1 in chk): print(ret + 10 ** (n - 1)) else: print("-1") else: print(ret) sys.stdout.flush()
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s347974662
Runtime Error
p02759
Input is given from Standard Input in the following format: N
class SegmentTree: def __init__(self, orig, func, unit): _len = len(orig) self.func = func self.size = 1 << (_len - 1).bit_length() self.tree = [unit] * self.size + orig + [unit] * (self.size - _len) self.unit = unit for i in range(self.size - 1, 0, -1): self.tree[i] = func(self.tree[i * 2], self.tree[i * 2 + 1]) def update(self, i, v): i += self.size self.tree[i] = v while i: i //= 2 self.tree[i] = self.func(self.tree[i * 2], self.tree[i * 2 + 1]) def find(self, l, r): l += self.size r += self.size ret = self.unit while l < r: if l & 1: ret = self.func(ret, self.tree[l]) l += 1 if r & 1: r -= 1 ret = self.func(ret, self.tree[r]) l //= 2 r //= 2 return ret import sys input = sys.stdin.readline from operator import or_ input() seg = SegmentTree([1 << ord(x) - 97 for x in input()[:-1]], or_, 0) ans = [] for _ in range(int(input())): f, x, y = input().split() if f == "1": seg.update(int(x) - 1, 1 << ord(y) - 97) else: ans.append(bin(seg.find(int(x) - 1, int(y))).count("1")) print(*ans)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s164421042
Accepted
p02759
Input is given from Standard Input in the following format: N
print((int(input()) - 1) // 2 + 1)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s210667747
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
print(round(float(input()) / 2))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s882783487
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
int(int(input()) / 2 + 0.5)
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s436833045
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
print(round(int(input()) / 2 + 0.5))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s609337703
Accepted
p02759
Input is given from Standard Input in the following format: N
#!/usr/bin/env python3 n = int(open(0).read()) print(n // 2 + (n % 2 != 0))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s592150289
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
def main(N): if N % 2 == 0: return N / 2 else: return (N + 1) / 2
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s225200521
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
i = int(input()) j = i / 2 k = i / 2 + 1 if i == k or i == j: print(int(j))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s143943175
Wrong Answer
p02759
Input is given from Standard Input in the following format: N
pageNum = int(input()) print(int(round(pageNum / 2, 0)))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s584279068
Runtime Error
p02759
Input is given from Standard Input in the following format: N
A = [list(map(int, input().strip().split())) for n in range(3)] A_input = [] for n in range(3): for m in range(3): A_input.append(A[n][m]) N = int(input()) b = [int(input()) for n in range(N)] def bingo_judge(A_input, b): bingo = 0 judge_list = [0, 0, 0, 0, 0, 0, 0, 0, 0] for number in b: for i in range(9): if number == A_input[i]: judge_list[i] = 1 else: pass # horizonal for i in range(3): if judge_list[3 * i] * judge_list[3 * i + 1] * judge_list[3 * i + 2] == 1: bingo = 1 else: pass # vertical for i in range(3): if judge_list[i] * judge_list[i + 3] * judge_list[i + 6] == 1: bingo = 1 else: pass # diagonal if judge_list[0] * judge_list[4] * judge_list[8] == 1: bingo = 1 if judge_list[2] * judge_list[4] * judge_list[6] == 1: bingo = 1 # test display # judge_disp=[[judge_list[i+3*n] for i in range(3)] for n in range(3)] # print(*judge_disp,sep="\n") return bingo def main(): ans = bingo_judge(A_input, b) if ans == 1: print("yes") elif ans == 0: print("No") main()
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s211717751
Runtime Error
p02759
Input is given from Standard Input in the following format: N
A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) x = [[0 for i in range(3)] for j in range(3)] N = int(input()) if N >= 3: for i in range(N): b = int(input()) for j in range(3): if A[j] == b: x[0][j] = 1 elif B[j] == b: x[1][j] = 1 elif C[j] == b: x[2][j] = 1 flag = 0 if x[0][0] == 1: if x[0][1] == 1 and x[0][2] == 1: flag = 1 elif x[1][0] == 1 and x[2][0] == 1: flag = 1 elif x[1][1] == 1 and x[2][2] == 1: flag = 1 if x[1][1] == 1: if x[0][1] == 1 and x[2][1] == 1: flag = 1 elif x[1][0] == 1 and x[2][0] == 1: flag = 1 elif x[0][2] == 1 and x[2][0] == 1: flag = 1 if x[2][2] == 1: if x[2][0] == 1 and x[2][1] == 1: flag = 1 elif x[0][2] == 1 and x[1][2] == 1: flag = 1 if flag == 1: print("Yes") else: print("No") # print(x) else: print("No")
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s410517243
Runtime Error
p02759
Input is given from Standard Input in the following format: N
import sys lines = sys.stdin.readlines() line1 = lines.pop(0).split(" ") # print(line1) N = int(line1[0]) M = int(line1[1]) # print(N) # print(M) str = [0] * N ans = [] flg = 0 for i in range(M): line = lines.pop(0).split(" ") # print(line) s = int(line[0]) c = int(line[1]) # print(s) # print(c) str[s - 1] = c # print('str = ') # print(str) one = int(str[0]) if N == 3: ret = one * 100 + int(str[1]) * 10 + int(str[2]) if int(str[1]) > 0 or int(str[2]) > 0: flg = 1 elif N == 2: ret = one * 10 + int(str[1]) if int(str[1]) > 0: flg = 1 else: if one > 0: ret = one ans.append(ret) # print(ans) div = 1 if N == 3: div = 100 elif N == 2: div = 10 for obj in ans[:]: if (obj / (10 ** (N - 1))) < 1: ans.remove(obj) elif flg == 1: # print('リムーブ候補') # print(obj) # print(div) a = obj % div print(a) if a == 0: # print('リムーブ') ans.remove(obj) if not ans: print("-1") else: # print(ans) print(min(ans))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the answer. * * *
s374243265
Runtime Error
p02759
Input is given from Standard Input in the following format: N
a = input().split(" ") N = int(a[0]) M = int(a[1]) ans1 = 10 ans2 = 10 ans3 = 10 for i in range(M): b = input().split(" ") c = int(b[0]) d = int(b[1]) if c == 1: if d == 0: if N == 1: ans1 = d elif d < ans1: ans1 = d elif c == 2: if d < ans2: ans2 = d else: if d < ans3: ans3 = d if ans1 == 10: ans1 = 0 if ans2 == 10: ans2 = 0 if ans3 == 10: ans3 = 0 if N == 1: print(ans1) elif N == 2: if ans1 == 0: print(-1) else: print(str(ans1) + str(ans2)) else: if ans1 == 0: print(-1) else: print(str(ans1) + str(ans2) + str(ans3))
Statement Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need?
[{"input": "5", "output": "3\n \n\nBy printing the 1-st, 2-nd pages on the 1-st sheet, 3-rd and 4-th pages on the\n2-nd sheet, and 5-th page on the 3-rd sheet, we can print all the data on 3\nsheets of paper.\n\n* * *"}, {"input": "2", "output": "1\n \n\n* * *"}, {"input": "100", "output": "50"}]
Print the maximum satisfaction that you can obtain. * * *
s837911911
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
package main import ( "bufio" "os" "strings" "strconv" "fmt" "sort" "container/heap" "math" ) var sc = bufio.NewScanner(os.Stdin) func readLineToInt() []int { sc.Scan() line := strings.Split(sc.Text(), " ") var intLine []int for _, str := range line { n, _ := strconv.Atoi(str) intLine = append(intLine, n) } return intLine } /****************** Pair ********************/ type Pair struct { a int b int } type SortablePairs struct { arr []*Pair lessfunc []lessFunc } type lessFunc func(i, j *Pair) bool func (sp SortablePairs) Len() int { return len(sp.arr) } func (sp SortablePairs) Swap(i, j int) { sp.arr[i], sp.arr[j] = sp.arr[j], sp.arr[i] } func (sp SortablePairs) Less(i, j int) bool { p, q := sp.arr[i], sp.arr[j] for k := 0; k < len(sp.lessfunc); k++ { less := sp.lessfunc[k] if less(p, q) { return true } else if less(q, p) { return false } } return false } /***************** HeapQue *****************/ type PriorityQueue struct { arr []*Pair size int } /** sort **/ func (pq PriorityQueue) Len() int { return len(pq.arr) } func (pq PriorityQueue) Swap(i, j int) { pq.arr[i], pq.arr[j] = pq.arr[j], pq.arr[i] } func (pq PriorityQueue) Less(i, j int) bool{ return pq.arr[i].a < pq.arr[j].a } /**** pq ****/ func (pq *PriorityQueue) Push(x interface{}) { item := x.(*Pair) pq.arr = append(pq.arr, item) pq.size++ } func (pq *PriorityQueue) Pop() interface{} { n := pq.size item := pq.arr[n - 1] pq.arr = pq.arr[:n - 1] pq.size-- return item } func max(a, b int) int { return int(math.Max(float64(a), float64(b))) } func main() { nk := readLineToInt() n, k := nk[0], nk[1] var dic map[int][]int = map[int][]int{} var keys []int for i := 0; i < n; i++ { td := readLineToInt() t, d := td[0], td[1] _, ok := dic[t] if !ok { keys = append(keys, t) } dic[t] = append(dic[t], d) } var sp SortablePairs less := func(p, q *Pair) bool { return p.a >= q.a } sp.lessfunc = append(sp.lessfunc, less) for _, key := range keys { sort.Ints(dic[key]) length := len(dic[key]) sp.arr = append(sp.arr, &Pair{dic[key][length - 1], key}) dic[key] = dic[key][:length - 1] } sort.Sort(sp) var que PriorityQueue heap.Init(&que) queScore := 0 defaultScore := 0 cnt := 0 ans := 0 for _, p := range sp.arr { defaultScore += p.a + cnt * 2 + 1 cnt++ if cnt >= k { ans = max(ans, defaultScore) break } for _, add := range dic[p.b] { heap.Push(&que, &Pair{add, p.b}) queScore += add } for que.size > k - cnt { item := heap.Pop(&que).(*Pair) queScore -= item.a } ans = max(ans, defaultScore + queScore) } fmt.Println(ans) }
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s877661943
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_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(): a = LI() a.sort() print(a[0]*a[1]//2) return #B def B(): d = defaultdict(int) s = II() def f(n): if n % 2: return 3 * n + 1 return n // 2 i = 1 while not d[s]: d[s] = 1 s = f(s) i += 1 print(i) return #C def C(): n = II() h = LI() ans = h[0] for i in range(n - 1): ans += max(0, h[i + 1] - h[i]) print(ans) return # D # 解説AC # 大きいものからとっていった際にその種類数をn # としてi<=nの種類数においてこれを超えるものは無い # それより大きいものについて種類数が減らずかつとったものの中で # 一番小さいものを除き、種類数が増える一番大きいものをとってこれば # i+1番目の種類下でもっとも大きい数になる def D(): n, k = LI() ma = [] for _ in range(n): t, di = LI() ma.append((di, t)) ma.sort() ma = deque(ma) s = defaultdict(int) t = 0 ans = 0 q = [] for _ in range(k): di,ti = ma.pop() ans += di heappush(q, (di, ti)) if not s[ti]: t += 1 s[ti] += 1 ans += t ** 2 ans = [ans] while ma and q: di, ti = ma.pop() while s[ti] and ma: di, ti = ma.pop() if not ma and s[ti]: break d1, t1 = heappop(q) while s[t1] == 1 and q: d1, t1 = heappop(q) if not q and s[t1]] == 1: break s[t1] -= 1 tmp = ans[-1] tmp = tmp - d1 + di - t ** 2 t += 1 tmp += t ** 2 ans.append(tmp) heappush(q, (di, ti)) s[ti] += 1 print(max(ans)) return #Solve if __name__ == '__main__': D()
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s930824420
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
n,k=map(int,input().split()) td=sorted([list(map(int,input().split())) for i in range(n)],reverse=True,key=lambda x:x[1]) #print(td) ans=0 kinds=dict() for i in range(k): ans+=td[i][1] if td[i][0] in kinds: kinds[td[i][0]].append(td[i][1]) else: kinds[td[i][0]]=[td[i][1]] ans+=(len(kinds)**2) #kindsの中はソートされている状況 #print(kinds) ans_=[ans] for i in range(k,n): if td[i][0] not in kinds: mi=[1000000000,1000000000] for j in kinds: if len(kinds[j])>1: if mi[1]>kinds[j][-1]: mi=[j,kinds[j][-1]] if mi=[1000000000,1000000000]: break else: ans=ans-len(kinds)**2+(len(kinds)+1)**2-mi[1]+td[i][1] kinds[mi[0]].pop(-1) kinds[td[i][0]]=[td[i][1]] ans_.append(ans) #print(kinds) print(max(ans_))
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s727726805
Accepted
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
# 種類が同じ寿司であれば、最も美味しさが高い寿司を選ぶべき。 # 従い、 # (1)各種類の最も美味しさが高い寿司グループ # (2)それ以外の寿司グループ # をいずれも降順に並べて、(1)から幾つ取るか(最低でも1つは取る)を全探索する import sys readline = sys.stdin.readline N, K = map(int, readline().split()) from collections import defaultdict sushi = defaultdict(list) # 種類・おいしさ のdictionary for i in range(N): t, d = map(int, readline().split()) sushi[t].append(d) best_sushi = [] other_sushi = [] for value in sushi.values(): value = sorted(value, reverse=True) best_sushi.append(value[0]) other_sushi += value[1:] best_sushi = sorted(best_sushi, reverse=True) other_sushi = sorted(other_sushi, reverse=True) # print("best_sushi",best_sushi) # print("other_sushi",other_sushi) best_num = 1 # best_sushiから選ぶ個数 other_num = K - 1 # other_sushiから選ぶ個数 if len(other_sushi) < other_num: # 選べない場合 other_num = len(other_sushi) best_num = K - other_num # それぞれの寿司から選ぶ個数の開始値が決定 # other_sushiの後ろの要素は切り離して良い other_sushi = other_sushi[:other_num] sushi_point = sum(best_sushi[:best_num]) + sum(other_sushi) kind_point = best_num**2 ans = sushi_point + kind_point # print("初期値",ans,"sum(best_sushi[:best_num])",sum(best_sushi[:best_num]),"sum(other_sushi)",sum(other_sushi),"best_num ** 2",best_num ** 2) # best寿司のインデックスを進めていく for i in range(best_num, len(best_sushi)): sushi_point += best_sushi[i] # print("----best_sushi[i]",best_sushi[i],"を追加") if len(other_sushi) == 0: break rem = other_sushi.pop() # 取り除く寿司 sushi_point -= rem kind_point = (i + 1) ** 2 # print("sushi_point",sushi_point,"kind_point",kind_point,"合計",sushi_point + kind_point) if ans < sushi_point + kind_point: ans = sushi_point + kind_point print(ans)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s333944963
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
class sushi: def __init__(self, t, d): self.t = t self.d = d list = [] N, K = map(int, input().split()) for i in range(N): t, d = map(int, input().split()) list.append(sushi(t, d)) sorted_list = sorted(list, key=lambda sushi:sushi.d, reverse=True) t_list = [] rev_list = [] d_sum = 0 for i in range(K): if t_list.count(list[i].t) == 0: t_list.append(list[i].t) else: rev_list.append(i) d_sum += list[i].d tmp = pow(len(t_list), 2) + d_sum flag = 0 while len(rev_list) != 0: pointer = rev_list.pop() for i in range(K, N, 1): if t_list.count(list[i].t) == 0 l = len(t_list) key = pow(l + 1, 2) + list[i].d - pow(l, 2) - list[pointer].d if key > 0: tmp += key else: flag = 1 break if flag: break print(tmp)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s751133952
Accepted
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
def main(): N, K = list(map(int, input().split())) sushi_list = list() for _ in range(N): t, d = list(map(int, input().split())) t -= 1 sushi_list.append((t, d)) sushi_list.sort(key=lambda s: s[1], reverse=True) # おいしさの降順でソート # おいしさTop Kのすしをとるのを初期解とする neta_flag_list = [0] * N topk_extra_sushi_list = list() # Top Kのすしで、各ネタ最大のおいしさはないすし additional_sushi_list = ( list() ) # Top Kのすしのネタ以外で、各ネタの最大のおいしさのすし point_topk = 0 for k, sushi in enumerate(sushi_list): if k < K: if neta_flag_list[sushi[0]] == 1: topk_extra_sushi_list.append(sushi) point_topk += sushi[1] else: if neta_flag_list[sushi[0]] == 0: additional_sushi_list.append(sushi) neta_flag_list[sushi[0]] = 1 n_neta = K - len(topk_extra_sushi_list) point_topk += n_neta**2 # その他のネタをt種類追加する場合を考えて、初期解と比較していく d_extra, d_additional = 0, 0 ans = point_topk n_additional_neta = min( K - n_neta, len(topk_extra_sushi_list), len(additional_sushi_list) ) for t in range(1, n_additional_neta + 1): n_cur_neta = n_neta + t d_extra += topk_extra_sushi_list[-t][1] d_additional += additional_sushi_list[t - 1][1] point = point_topk - d_extra + d_additional + (n_cur_neta**2 - n_neta**2) ans = max(ans, point) print(ans) if __name__ == "__main__": main()
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s516706761
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
#include<iostream> #include<queue> #include<vector> #include<map> #include<algorithm> using namespace std; typedef long long ll; typedef pair<ll, int> P; int main(){ int N,K; cin >>N>>K; vector<pair<ll, ll>> list; for (int i=0;i<N;i++){ int t, d; cin >> t>> d; P p=make_pair(t,d); list.push_back(p); } //queue は,今使っている寿司番号を格納している。 priority_queue<pair<ll, int>> que; //countは,答えに,何が何個使われているかをcountしている。 map<ll, int> count; //初期化しておく for (int i=0;i<N;i++){ count[list[i][0]]=0; } ll bonus=0; ll delicious=0; //はじめの状態 for (int i=0;i<K;i++){ delicious+=list[i][1]; P r=make_pair(list[i][1], i); que.push(r); count[list[i][0]]++; if (count[list[i][0]==1){ bonus++; } } ll ans=pow(bonus, 2)+delicious; for (int i=K;i<N;i++){ if (count[list[i+1][0]]==0){ P r=que.top(); int k=r.second int ans_2=pow(bonus+1, 2)+delicious-list[k][1]+list[i][1]; if (ans_2>ans){ count[list[i][0]]++; r=make_pair(list[i][1], i); que.pop();que.push(r); bonus++; delicious+=list[i][1]-list[k][1]; count[list[k][0]]--; ans=pow(bonus, 2)+delicious; } } cout << ans; return 0; }
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s217585313
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
import numpy as np n, k = map(int, input().split()) mx = {} for _ in range(n): t, d = map(int, input().split()) if t not in mx: mx[t] = d elif mx[t] < d: mx[t] = d sushi.append((t,d)) # 美味しさでソート taste_sorted_sushi = sorted(sushi, key=lambda x:x[1], reverse=True) # 貪欲にK個選び分割する selected_sushi = taste_sorted_sushi[:k] # 貪欲なK個の種類の分布を調べる # K個の中で二つ以上あるものとそうでないものに分ける S = set() q = [] for s in selected_sushi: if s[0] in S: q.append(s) else: S.add(s[0]) q = sorted(q, key=lambda x:x[1], reverse=True) ans = sum(selected_sushi[:][1])+len(S)**2 S = set(selected_sushi[:][0]) for i in range(k,n): if taste_sorted_sushi[k] not in S: ans = max(ans, ans-q.pop()+taste_sorted_sushi[k]-len(S)**2 + (len(S)+1)**2 S.add(taste_sorted_sushi[k][0]) print(ans)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s028897446
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
import itertools import cython n,k = map(int,input().split()) l = [] for i in range(n): l.append(list(map(int,input().split()))) comb = list(itertools.combinations(l,k)) def calc_score(comb): t = set() cdef int d = 0 for i in comb: t.add(i[0]) d += i[1] return len(t) ** 2 + d print(max([calc_score(i) for i in comb]))
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s359994116
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
n, k = [int(x) for x in input().split()] td = [] for _ in [0] * n: ti, di = [int(x) for x in input().split()] td.append((ti, di)) td = sorted(td, key=lambda x: x[1]) t = [x[0] for x in td] d = [x[1] for x in td] ans = 0 for x in range(1, len(set(t)) + 1): tmpans = (x) ** 2 tmpt, tmpd = t.copy(), d.copy() tmpk = k - x neta = set() i = 0 while len(neta) != x: i -= 1 if tmpt[i] not in neta: neta.add(tmpt[i]) tmpans += tmpd[i] tmpt[i] = 0 for i in range(n): ti, di = tmpt[n - 1 - i], tmpd[n - 1 - i] if ti == 0: continue if tmpk == 0: break tmpk -= 1 tmpans += di ans = max(ans, tmpans) print(ans)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s607882970
Wrong Answer
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
import sys fin = sys.stdin.readline from heapq import heappop, heappush from collections import defaultdict N, K = [int(elem) for elem in fin().split()] sushi_info = sorted( tuple(tuple(int(elem) for elem in fin().split()) for _ in range(N)), key=lambda x: -x[1], ) cur_eaten = [] cur_rest = [] count = defaultdict(int) for t, d in sushi_info[:K]: heappush(cur_eaten, (d, t)) count[t] += 1 for t, d in sushi_info[K:]: heappush(cur_rest, (-d, t)) num_distinctive_kinds = sum(v >= 1 for v in count.values()) satisfactions = [sum(d for _, d in sushi_info[:K]) + num_distinctive_kinds**2] cur_num_kinds = num_distinctive_kinds for cur_num_kinds in range(num_distinctive_kinds + 1, K + 1): while cur_eaten and count[cur_eaten[0][1]] <= 1: heappop(cur_eaten) while cur_rest and count[cur_rest[0][1]] > 0: heappop(cur_rest) if (not cur_eaten) or (not cur_rest): break ditched_d, ditched_t = heappop(cur_eaten) added_d, added_t = heappop(cur_rest) added_d *= -1 count[ditched_t] -= 1 count[added_d] += 1 # cur_num_kinds += 1 satisfactions.append( satisfactions[-1] - ditched_d + added_d + cur_num_kinds * 2 - 1 ) # print(satisfactions) print(max(satisfactions))
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s528604019
Accepted
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
nk = input().split() n = int(nk[0]) k = int(nk[1]) dtlist = [] for i in range(n): td = input().split() t = int(td[0]) d = int(td[1]) dtlist.append((d, t)) dtlist.sort(reverse=True) t_to_maxidx = {} for idx, dt in enumerate(dtlist): d, t = dt if t not in t_to_maxidx: t_to_maxidx[t] = idx selected = [] count = 0 tcount = {} candidate = [(dtlist[idx][0], idx) for t, idx in t_to_maxidx.items()] candidate.sort(reverse=True) for d, idx in candidate: if count >= k: break d, t = dtlist[idx] selected.append(dtlist[idx]) count += 1 tcount[t] = 1 if t not in tcount else tcount[t] + 1 dtlist[idx] = None new_dtlist = [] for dt in dtlist: if dt is not None: new_dtlist.append(dt) dtlist = new_dtlist if k - count > 0: for i in range(k - count): dt = dtlist.pop(0) selected.append(dt) d, t = dt tcount[t] = 1 if t not in tcount else tcount[t] + 1 selected.sort() score = 0 for d, t in selected: score += d len_tcount = len(tcount) score += len_tcount * len_tcount for i in range(0, 2**32): next_score = score try: d_new, t_new = dtlist.pop(0) d_old, t_old = selected.pop(0) except IndexError: print(score) break next_score += d_new next_score -= d_old tcount[t_old] -= 1 if tcount[t_old] <= 1: next_score -= len_tcount * len_tcount len_tcount -= 1 next_score += len_tcount * len_tcount del tcount[t_old] if t_new not in tcount: next_score -= len_tcount * len_tcount len_tcount += 1 next_score += len_tcount * len_tcount tcount[t_new] = 1 else: tcount[t_new] += 1 if next_score <= score: print(score) break score = next_score
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s929831204
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
# -*- coding: utf-8 -*- n, k = map(int, input().split()) o = {} for _ in range(n): t, d = map(int, input().split()) if t not in o: o[t] = [] o[t].append(d) tl = list(o.keys()) tl.sort(reverse=True, key=lambda x: o[x]) # print(tl) for t in tl: o[t].sort(reverse=True) # print(o) res = -1 sel = {} for t in tl: if len(o[t]) <= k: sel[t] = len(o[t]) k -= sel[t] else: sel[t] = k k = 0 if k == 0: break # print(sel) def calc(sel): res = 0 cnt = 0 for t in sel: if sel[t] > 0: cnt += 1 for i in range(sel[t]): res += o[t][i] return res + cnt * cnt idx = None for i in range(len(tl) - 1): if tl[i + 1] not in sel: idx = i break if idx is None: print(calc(sel)) exit() # print(idx) res = calc(sel) for i in range(idx + 1, len(tl)): while sel[tl[idx]] == 1: idx -= 1 sel[tl[idx]] -= 1 sel[i] = 1 # res2 = res + o[i][0] - o[tl[idx]][-1] # res = max(res, res2) res = max(res, calc(sel)) print(res)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s472551238
Accepted
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
import heapq from collections import defaultdict N, K = map(int, input().split()) sushi = [] for _ in range(N): kind, value = map(int, input().split()) sushi.append((value, kind)) sushi.sort() choice = [] heapq.heapify(choice) current_sum = 0 kinds = set() count_nitems_bykind = defaultdict(int) # pick K items with highest value for _ in range(K): item = sushi.pop() count_nitems_bykind[item[1]] += 1 kinds.add(item[1]) current_sum += item[0] heapq.heappush(choice, item) # initialize a dict to store max value that can be achieved by selecting x kinds of sushi # key: x, value: max value max_value = {len(kinds): current_sum} def replace(): """ Returns a next sushi that is new in kind and has maximum value """ while sushi: candidate = sushi.pop() if candidate[1] not in kinds: kinds.add(candidate[1]) return candidate return None while sushi and choice: # pick a sushi that has min value sushi_min = heapq.heappop(choice) # check if that sushi is a duplicate then if yes replace with a new sushi whose kind is new and value is max among such if count_nitems_bykind[sushi_min[1]] > 1: # pick a candidate to replace sushi_new = replace() if sushi_new is None: break count_nitems_bykind[sushi_min[1]] -= 1 heapq.heappush(choice, sushi_new) # add a new result to dict current_sum = current_sum - sushi_min[0] + sushi_new[0] max_value[len(kinds)] = current_sum if len(kinds) == K: # already iterated enough to find answer break ans = -1 for key in max_value: ans = max(ans, max_value[key] + key**2) print(ans)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s999892176
Accepted
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
# 解説見て書く N, K = [int(x) for x in input().split()] td = [0] * (N) for i in range(N): td[i] = [int(x) for x in input().split()] # ネタ種類降順でソート # 同じネタの中ではおいしいものから順に並ぶ td = sorted(td, reverse=True) var_p1 = [0] * N # 種類数を増やす寿司のリスト var_p0 = [0] * N # 種類数を増やさない寿司のリスト n_p1 = 0 n_p0 = 0 for i in range(N): if i == 0 or (i > 0 and td[i][0] != td[i - 1][0]): # 種類が変わる var_p1[n_p1] = td[i][1] # おいしさを追加 n_p1 += 1 else: var_p0[n_p0] = td[i][1] # おいしさを追加 n_p0 += 1 var_p1.sort(reverse=True) var_p0.sort(reverse=True) val_taste = sum(var_p0[0:K]) val_vars = 0 ans = 0 for j in range(1, K + 1): # 種類数1〜Kを試す val = var_p1[j - 1] if val <= 0: break # これ以上種類を増やせない # var_p1からn_p1個選び、var_p0からK - n_p1個選ぶ val_taste = val_taste + val - var_p0[K - j] val_vars = j * j ans = max(ans, val_taste + val_vars) print(ans)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s505244615
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
n, k = map(int, input().split()) inputarray = [] for i in range(n): inputarray.append([int(i) for i in input().split()]) t = [i[0] for i in inputarray] d = [i[1] for i in inputarray] def combinationListRecursive(data, r): if r == 0 or r > len(data): return [] result = [] _combinationListRecursive(data, r, 0, [], result) return result def _combinationListRecursive(data, r, start, progress, result): if r == 0: result.append(progress) return for i in range(start, len(data)): _combinationListRecursive(data, r - 1, i + 1, progress + [data[i]], result) result = combinationListRecursive(range(len(d)), k) best = 0 for i in result: tarray = [] dtmp = 0 for k in range(k): dtmp += d[i[k]] tarray.append(t[i[k]]) tlist = list(set(tarray)) ttmp = len(tlist) ** 2 if best < dtmp + ttmp: best = dtmp + ttmp print(best)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s515810028
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
import itertools a = input().split() osu = [] for i in range(int(a[0])): osu.append(input().split()) im = [] for i in range(int(a[0])): im.append(i) ans_map_all = list(itertools.combinations(im, int(a[1]))) ans_lis = [] for i in ans_map_all: kind = [] pre = 0 for j in i: kind.append(int(osu[j][0])) pre += int(osu[j][1]) ans_lis.append(pre + len(list(set(kind)) * len(list(set(kind))))) ans_lis.sort() ans_lis.reverse() print(ans_lis[0])
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s728621776
Runtime Error
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
import collections class Sushi(object): def __init__(self, lines): neta, oishisa = map(int, lines.split()) self.neta = neta self.oishisa = oishisa def __str__(self): return "寿司:{0} 美味しさ:{1}".format(self.neta, self.oishisa) def score_out(eat_list): score = 0 items = list(collections.Counter([i.neta for i in eat_list]).items()) score += len(items) ** 2 basic_points = [i.oishisa for i in eat_list] score += sum(basic_points) return score N, K = map(int, input().split()) sushi_list = [Sushi(input()) for _ in range(N)] sushi_list = sorted(sushi_list, key=lambda x: x.oishisa) eat_list = [] neta_max = len(list(collections.Counter([i.neta for i in sushi_list]).items())) for i in range(K): eat_list.append(sushi_list.pop()) # print(eat_list[i]) eat_items = list(collections.Counter([i.neta for i in eat_list]).items()) if len(eat_items) == K: print(score_out(eat_list)) exit(0) low_band_types = len(eat_items) maxscore = score_out(eat_list) for i in range(N): # 寿司が全て独立しているか判断する。 # 独立してたら終了させる。 # 寿司屋のネタの最大種類==選択したネタが最大種類でも終了 eat_list = sorted(eat_list, key=lambda x: x.oishisa) # print ( '現在の寿司' ) for i in eat_list: # print(i) pass # print('\n') if len( list(collections.Counter([i.neta for i in eat_list]).items()) ) == K and maxscore <= score_out(eat_list): print(score_out(eat_list)) exit(0) elif len( list(collections.Counter([i.neta for i in eat_list]).items()) ) == neta_max and maxscore <= score_out(eat_list): print(score_out(eat_list)) exit(0) eat_items = list(collections.Counter([i.neta for i in eat_list]).items()) neta_kaburi_list = [i[0] for i in eat_items if i[1] > 1] # print(neta_kaburi_list) min_oishisa = -1 kick_avails = [] for kaburi_neta in neta_kaburi_list: kick_avails += [i for i in eat_list if i.neta == kaburi_neta] kick_avails = sorted(kick_avails, key=lambda x: x.oishisa, reverse=True) if not kick_avails: print(maxscore) exit(0) kick = kick_avails.pop() # print('kick as') # print(kick) eat_list.remove(kick) sushi_list = sorted(sushi_list, key=lambda x: x.oishisa) ef = True neta_list = [i[0] for i in eat_items] if not sushi_list: print(maxscore) exit(0) while ef: eat_list = sorted(eat_list, key=lambda x: x.oishisa, reverse=True) sushi = sushi_list.pop() # print('poped sushi is ') # print(sushi) if sushi.neta in neta_list: pass else: eat_list.append(sushi) ef = False if score_out(eat_list) > maxscore: maxscore = score_out(eat_list) print(maxscore)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s506697008
Accepted
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
num_lines, max_num = map(int, input().split()) inp_sorted = [[int(st) for st in input().split()] for _ in range(num_lines)] # print(inp_sorted) inp_sorted.sort(key=lambda x: x[1], reverse=True) inp_map = {} for t, d in inp_sorted: if not t in inp_map: inp_map[t] = d variety = set() score = 0 dup = [] for i in range(max_num): t, d = inp_sorted[i] if t in variety: dup.append((t, d)) variety.add(t) if t in inp_map: del inp_map[t] score += d var_value = len(variety) max_score = score + var_value * var_value for t, d in sorted(inp_map.items(), key=lambda x: x[1], reverse=True): if len(dup): t2, d2 = dup.pop() var_value += 1 score = score - d2 + d max_score = max(max_score, score + var_value * var_value) print(max_score)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
Print the maximum satisfaction that you can obtain. * * *
s655053102
Accepted
p03148
Input is given from Standard Input in the following format: N K t_1 d_1 t_2 d_2 . . . t_N d_N
# Greedyを一ひねり # 最初はGreedyに取る。それから種類を増やす。2個目以降を削除して、新たなネタの1個目を加える。 # あるネタの中でポイントが最高かどうかが重要。これを True / False で管理する n, k = list(map(int, input().split())) sushi = [list(map(int, input().split())) + [None] for _ in range(n)] sushi.sort(key=lambda s: s[1], reverse=True) # 値段の降順 # あるネタの中でポイントが最高なら、 Trueそうでなければ、 False neta_seen = set() for i in range(n): if sushi[i][0] in neta_seen: sushi[i][2] = False else: sushi[i][2] = True neta_seen.add(sushi[i][0]) # n_kind = len([s[1] for s in sushi[:k] if s[1] == True ]) # なんかうまくいかないので、最初からk番目までのTrueの数を愚直に書こう n_kind = 0 for i in range(k): if sushi[i][2]: n_kind += 1 ans = sum([s[1] for s in sushi[:k]]) + n_kind**2 # print(sushi, ans) now = ans adopt = k trash = k - 1 while True: while adopt < n and sushi[adopt][2] == False: adopt += 1 while trash >= 0 and sushi[trash][2] == True: trash -= 1 if not (adopt < n and trash >= 0): break now = now + sushi[adopt][1] - sushi[trash][1] now = now - n_kind**2 + (n_kind + 1) ** 2 # print(adopt, trash, now) n_kind += 1 adopt += 1 trash -= 1 if now > ans: ans = now print(ans)
Statement There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
[{"input": "5 3\n 1 9\n 1 7\n 2 6\n 2 5\n 3 1", "output": "26\n \n\nIf you eat Sushi 1,2 and 3:\n\n * The base total deliciousness is 9+7+6=22.\n * The variety bonus is 2*2=4.\n\nThus, your satisfaction will be 26, which is optimal.\n\n* * *"}, {"input": "7 4\n 1 1\n 2 1\n 3 1\n 4 6\n 4 5\n 4 5\n 4 5", "output": "25\n \n\nIt is optimal to eat Sushi 1,2,3 and 4.\n\n* * *"}, {"input": "6 5\n 5 1000000000\n 2 990000000\n 3 980000000\n 6 970000000\n 6 960000000\n 4 950000000", "output": "4900000016\n \n\nNote that the output may not fit into a 32-bit integer type."}]
On the first line, print the maximum value of the sum of the integers written on the chosen squares. On the next N lines, print a way that achieves the maximum. Precisely, output the strings t_1,t_2,\cdots,t_N, that satisfies t_{i,j}=`X` if you choose (i,j) and t_{i,j}=`.` otherwise. You may print any way to choose squares that maximizes the sum. * * *
s290357147
Accepted
p02562
Input is given from Standard Input in the following format: N K A_{1,1} A_{1,2} \cdots A_{1,N} A_{2,1} A_{2,2} \cdots A_{2,N} \vdots A_{N,1} A_{N,2} \cdots A_{N,N}
N, K = map(int, input().split()) MAP = [list(map(int, input().split())) for i in range(N)] start = 2 * N + 1 goal = 2 * N + 2 V = 2 * N + 5 EDGE = [[[0, 0] for j in range(V)] for i in range(V)] # 0 ~ N : 縦 # N+1 ~ 2*N : 横 # 2*N+1 : start # 2*N+2 : goal for i in range(N): EDGE[start][i] = [K, 0] EDGE[N + i][goal] = [K, 0] for i in range(N): for j in range(N): EDGE[i][N + j] = [1, -MAP[i][j]] EDGE[N + j][i] = [0, MAP[i][j]] EDGE[start][goal] = [float("inf"), 0] BACK = [-1] * V LA = 0 for flow in range(K * N): ANS = [float("inf")] * V ANS[start] = 0 for rep in range(V): flag = 0 for fr in range(V): for to in range(V): c, d = EDGE[fr][to] if c > 0 and ANS[to] > ANS[fr] + d: ANS[to] = ANS[fr] + d flag = 1 BACK[to] = fr if flag == 0: break if ANS[goal] == 0: break LA += ANS[goal] NOW = goal while NOW != start: fr = BACK[NOW] EDGE[fr][NOW][0] -= 1 EDGE[NOW][fr][0] += 1 NOW = fr print(-LA) ALIST = [["."] * N for i in range(N)] for i in range(N): for j in range(N): if EDGE[i][N + j][0] == 0: ALIST[i][j] = "X" for alist in ALIST: print("".join(alist))
Statement You are given a grid of N rows and M columns. The square at the i-th row and j-th column will be denoted as (i,j). A nonnegative integer A_{i,j} is written for each square (i,j). You choose some of the squares so that each row and column contains at most K chosen squares. Under this constraint, calculate the maximum value of the sum of the integers written on the chosen squares. Additionally, calculate a way to choose squares that acheives the maximum.
[{"input": "3 1\n 5 3 2\n 1 4 8\n 7 6 9", "output": "19\n X..\n ..X\n .X.\n \n\n* * *"}, {"input": "3 2\n 10 10 1\n 10 10 1\n 1 1 10", "output": "50\n XX.\n XX.\n ..X"}]
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests. * * *
s168768505
Wrong Answer
p02831
Input is given from Standard Input in the following format: A B
import math def resolve(): A, B = [int(i) for i in input().split()] answer = greatest_common_divisor(A, B) print(answer) def trial_division(n): prime_factors = [] if n < 2: prime_factors.append(n) return prime_factors for i in (1, math.ceil(int(n / 2)), 1): if (n % i) == 0: prime_factors.append(i) prime_factors.append(n) return prime_factors def least_common_multiple(a, b): a_list = trial_division(a) b_list = trial_division(b) a_b_and_list = set(a_list) & set(b_list) lcm = 1 if a_b_and_list: for i in a_b_and_list: lcm = lcm * i return lcm def greatest_common_divisor(a, b): a_list = trial_division(a) b_list = trial_division(b) a_b_and_list = set(a_list) ^ set(b_list) gcd = 1 if a_b_and_list: for i in a_b_and_list: gcd = gcd * i return gcd if __name__ == "__main__": resolve()
Statement Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
[{"input": "2 3", "output": "6\n \n\nWhen we have six snack pieces, each guest can take three pieces if we have two\nguests, and each guest can take two if we have three guests.\n\n* * *"}, {"input": "123 456", "output": "18696\n \n\n* * *"}, {"input": "100000 99999", "output": "9999900000"}]
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests. * * *
s204711387
Runtime Error
p02831
Input is given from Standard Input in the following format: A B
N = int(input()) AB = [] for _ in range(N): AB.append([int(i) for i in input().split()]) colors = 10**6 + 2 E = [0] * colors for ab in AB: E[ab[0]] += 1 E[ab[1] + 1] -= 1 max_E = 0 for c in range(1, 10**6 + 1): E[c] = E[c - 1] + E[c] if E[c] > max_E: max_E = E[c] print(max(E))
Statement Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
[{"input": "2 3", "output": "6\n \n\nWhen we have six snack pieces, each guest can take three pieces if we have two\nguests, and each guest can take two if we have three guests.\n\n* * *"}, {"input": "123 456", "output": "18696\n \n\n* * *"}, {"input": "100000 99999", "output": "9999900000"}]
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests. * * *
s137877333
Accepted
p02831
Input is given from Standard Input in the following format: A B
N, M = map(int, input().split()) n, m = N, M if n < m: t = n n = m m = t while n % m: t = n % m n = m m = t print(int(N * M / m))
Statement Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
[{"input": "2 3", "output": "6\n \n\nWhen we have six snack pieces, each guest can take three pieces if we have two\nguests, and each guest can take two if we have three guests.\n\n* * *"}, {"input": "123 456", "output": "18696\n \n\n* * *"}, {"input": "100000 99999", "output": "9999900000"}]
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests. * * *
s303680364
Runtime Error
p02831
Input is given from Standard Input in the following format: A B
A, B = (int(x) for x in input().split()) a = A // 2 d = 1 s = 0 d = int(d) for i in range(a): if A % d == 0 and B % d == 0: s = d d += 1 print(int(A * (B / s)))
Statement Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
[{"input": "2 3", "output": "6\n \n\nWhen we have six snack pieces, each guest can take three pieces if we have two\nguests, and each guest can take two if we have three guests.\n\n* * *"}, {"input": "123 456", "output": "18696\n \n\n* * *"}, {"input": "100000 99999", "output": "9999900000"}]
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests. * * *
s757406500
Wrong Answer
p02831
Input is given from Standard Input in the following format: A B
num = [int(i) for i in input().split()] kou = [min(num)] for i in range(2, min(num)): if min(num) % i == 0: kou.append(i) a = 1 for j in kou: if max(num) % j == 0: a = a * j print(int(num[0] * num[1] / a))
Statement Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
[{"input": "2 3", "output": "6\n \n\nWhen we have six snack pieces, each guest can take three pieces if we have two\nguests, and each guest can take two if we have three guests.\n\n* * *"}, {"input": "123 456", "output": "18696\n \n\n* * *"}, {"input": "100000 99999", "output": "9999900000"}]
Print the minimum number of pieces that can be evenly distributed to the guests in both of the cases with A guests and B guests. * * *
s178878571
Wrong Answer
p02831
Input is given from Standard Input in the following format: A B
num = input().split() num[0] = int(num[0]) num[1] = int(num[1]) min1 = 0 if num[0] >= num[1]: min1 = num[1] elif num[0] < num[1]: min1 = num[0] great_common = 1 min2 = min1 // 2 while min1 != 1: for i in range(min2): while min1 % (i + 2) == 0: if min1 % (i + 2) == 0: min1 /= i + 2 great_common *= i + 2 print(int(num[0] * num[1] / great_common))
Statement Takahashi is organizing a party. At the party, each guest will receive one or more snack pieces. Takahashi predicts that the number of guests at this party will be A or B. Find the minimum number of pieces that can be evenly distributed to the guests in both of the cases predicted. We assume that a piece cannot be divided and distributed to multiple guests.
[{"input": "2 3", "output": "6\n \n\nWhen we have six snack pieces, each guest can take three pieces if we have two\nguests, and each guest can take two if we have three guests.\n\n* * *"}, {"input": "123 456", "output": "18696\n \n\n* * *"}, {"input": "100000 99999", "output": "9999900000"}]