output_description stringlengths 15 956 | submission_id stringlengths 10 10 | status stringclasses 3 values | problem_id stringlengths 6 6 | input_description stringlengths 9 2.55k | attempt stringlengths 1 13.7k | problem_description stringlengths 7 5.24k | samples stringlengths 2 2.72k |
|---|---|---|---|---|---|---|---|
Print the minimum total cost to decrease Takahashi's expected profit by at
least 1 yen.
* * * | s571183108 | Runtime Error | p03948 | The input is given from Standard Input in the following format:
N T
A_1 A_2 ... A_N | n, t = map(int, input().split()))
A = list(map(int, input().split()))
ans = 0
max_diff = 0
min_a = A[0]
for a in A:
min_a = min(min_a, a)
if (a - min_a) == max_diff:
ans += 1
elif (a - min_a) > max_diff:
ans = 1
max_diff = (a - min_a)
print(ans)
| Statement
There are N towns located in a line, conveniently numbered 1 through N.
Takahashi the merchant is going on a travel from town 1 to town N, buying and
selling apples.
Takahashi will begin the travel at town 1, with no apple in his possession.
The actions that can be performed during the travel are as follows:
* _Move_ : When at town i (i < N), move to town i + 1.
* _Merchandise_ : Buy or sell an arbitrary number of apples at the current town. Here, it is assumed that one apple can always be bought and sold for A_i yen (the currency of Japan) at town i (1 ≦ i ≦ N), where A_i are distinct integers. Also, you can assume that he has an infinite supply of money.
For some reason, there is a constraint on merchandising apple during the
travel: the sum of the number of apples bought and the number of apples sold
during the whole travel, must be at most T. (Note that a single apple can be
counted in both.)
During the travel, Takahashi will perform actions so that the _profit_ of the
travel is maximized. Here, the profit of the travel is the amount of money
that is gained by selling apples, minus the amount of money that is spent on
buying apples. Note that we are not interested in apples in his possession at
the end of the travel.
Aoki, a business rival of Takahashi, wants to trouble Takahashi by
manipulating the market price of apples. Prior to the beginning of Takahashi's
travel, Aoki can change A_i into another arbitrary non-negative integer A_i'
for any town i, any number of times. The cost of performing this operation is
|A_i - A_i'|. After performing this operation, different towns may have equal
values of A_i.
Aoki's objective is to decrease Takahashi's expected profit by at least 1 yen.
Find the minimum total cost to achieve it. You may assume that Takahashi's
expected profit is initially at least 1 yen. | [{"input": "3 2\n 100 50 200", "output": "1\n \n\nIn the initial state, Takahashi can achieve the maximum profit of 150 yen as\nfollows:\n\n 1. Move from town 1 to town 2.\n 2. Buy one apple for 50 yen at town 2.\n 3. Move from town 2 to town 3.\n 4. Sell one apple for 200 yen at town 3.\n\nIf, for example, Aoki changes the price of an apple at town 2 from 50 yen to\n51 yen, Takahashi will not be able to achieve the profit of 150 yen. The cost\nof performing this operation is 1, thus the answer is 1.\n\nThere are other ways to decrease Takahashi's expected profit, such as changing\nthe price of an apple at town 3 from 200 yen to 199 yen.\n\n* * *"}, {"input": "5 8\n 50 30 40 10 20", "output": "2\n \n\n* * *"}, {"input": "10 100\n 7 10 4 5 9 3 6 8 2 1", "output": "2"}] |
Print the answer.
* * * | s221312548 | Runtime Error | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | import collections
def connected(adj,v,visited,f):
visited[v]=True
f.append(v)
for i in adj[v]:
if not visited[i]:
connected(adj,i,visited,f)
adj=collections.defaultdict(int)
n,m=map(int,input().split())
f={}
for i in range(m):
u,v=map(int,input().split())
if u<=v:f[(u,v)]=1
else:f[(v,u)]=1
for x in f:
adj[x[0]]+=1
adj[x[1]]+=1
#print(adj)
print(max(list(adj.values()))+1)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s760281142 | Runtime Error | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | import numpy as np
N,M=map(int,input().split())
mat=np.zeros((N,N))
for _ in range(M):
a,b=map(int,input().split())
mat[a-1][b-1]=1
mat[b-1][a-1]=1
mat2=[[j for j in i] for i in mat]
for i in range(N-1):
for j in range(i+1,N):
for k in range(j+1,N):
if (mat[i][j]==1)&(mat[i][k]==1):
mat[j][k]=1
mat[k][j]=1
print(str(int(np.max(np.sum(mat,axis=1))+1))) | Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s386348195 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | # abc177_D_2_特定のnが特定のlistに含まれることを確認するまで、iter
int_n, int_m = map(int, input().split())
list_agg = list()
for i in range(int_m):
list_tmp = list(map(int, input().split()))
list_agg.append(list_tmp)
def get_unique_list(seq):
seen = []
return [x for x in seq if x not in seen and not seen.append(x)]
flag = 100
list_agg_tmp = list_agg
while flag <= 1:
list_set_agg = list()
flag = 0
for iter_n in range(1, int_n + 1):
list_tmp_add = list()
n_flag = 0
for i_list in list_agg_tmp:
if iter_n in i_list:
list_tmp_add = list_tmp_add + i_list
n_flag = n_flag + 1
if n_flag > flag:
flag = n_flag
list_set_agg.append(list(set(list_tmp_add)))
list_agg_tmp = get_unique_list(list_set_agg)
int_max_len = 0
for i in list_agg_tmp:
if len(i) > int_max_len:
int_max_len = len(i)
print(int_max_len)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s452988094 | Accepted | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | # def friends(arr):
# table = [{}]
# for a in arr:
# seted = False
# for t in table:
# if a[0] in t or a[1] in t:
# seted = True
# t.add(a[0])
# t.add(a[1])
# if not seted:
# table.append({a[0], a[1]})
#
# return max(table, key=len)
# def start():
# n, m = [int(x) for x in input().split(" ")]
# arr = []
# while m:
# arr.append([int(x) for x in input().split(" ")])
# m -= 1
# print(len(friends(arr)))
# start()
def friends(n,arr):
import collections
graph = collections.defaultdict(list)
for i in range(len(arr)):
graph[arr[i][0]].append(arr[i][1])
graph[arr[i][1]].append(arr[i][0])
visited = [False]*(n+1)
maxi = 0
for i in range(1,n+1):
if not visited[i]:
queue = collections.deque()
queue.append(i)
visited[i] = True
temp = 0
while queue:
temp += 1
s = queue.popleft()
for t in graph[s]:
if not visited[t]:
queue.append(t)
visited[t] = True
maxi = max(maxi, temp)
return maxi
def start():
n, m = [int(x) for x in input().split(" ")]
arr = []
while m:
arr.append([int(x) for x in input().split(" ")])
m -= 1
print((friends(n,arr)))
start() | Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s208999102 | Runtime Error | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | class Graph:
def __init__(self, n, m, side):
self.side = side
self.neighbor = [set() for i in range(n + 1)]
self.visited = [False] * (n + 1)
self.product()
self.group = [0] * (n + 1)
def product(self):
for a, b in self.side:
self.neighbor[a].add(b)
self.neighbor[b].add(a)
def dfs(self, x, a):
self.group[a] += 1
self.visited[x] = True
for i in self.neighbor[x]:
if self.visited[i]:
continue
self.dfs(i, a)
def all_dfs(self):
a = 0
for i in range(1, n + 1):
if not self.visited[i]:
self.dfs(i, a)
a += 1
n, m = map(int, input().split())
side = list(tuple(map(int, input().split())) for i in range(m))
graph1 = Graph(n, m, side)
graph1.all_dfs()
print(max(graph1.group))
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s518045212 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n, m = map(int, input().split())
ex = [0 for i in range(n)]
fri = {}
for i in range(m):
a, b = map(int, input().split())
if ex[a - 1] == 0 and ex[b - 1] == 0:
if a > b:
a, b = b, a
ex[a - 1] = a
ex[b - 1] = a
fri[a] = [a, b]
elif ex[a - 1] == 0:
ex[a - 1] = ex[b - 1]
fri[ex[b - 1]].append(a)
elif ex[b - 1] == 0:
ex[b - 1] = ex[a - 1]
fri[ex[a - 1]].append(b)
elif ex[a - 1] == ex[b - 1]:
continue
else:
shozoku = min(ex[a - 1], ex[b - 1])
mu = max(ex[a - 1], ex[b - 1])
for j in range(len(fri[mu])):
ex[fri[mu][j] - 1] = shozoku
fri[shozoku].extend(fri.pop(mu))
ans = 0
for key in fri:
ans = max(ans, len(fri[key]))
print(ans)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s493954764 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | from collections import Counter
n, m = map(int, input().split())
if m == 0:
print("0")
else:
ab = [map(int, input().split()) for _ in range(m)]
a, b = [list(i) for i in zip(*ab)]
a.extend(b)
c = Counter(a)
most = c.most_common(1)[0][0]
temp = []
for i in range(m):
if a[i] == most or b[i] == most:
if a[i] == b[i]:
continue
temp.append(a[i])
temp.append(b[i])
temp = list(set(temp))
print(len(temp))
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s572358340 | Accepted | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n, m = map(int, input().split())
f = lambda x: int(x) - 1
l = [[] for _ in range(n)]
for i in range(m):
a, b = map(f, input().split())
l[a].append(b)
l[b].append(a)
m = 0
visit = set()
for i in range(n):
if i in visit:
continue
queue = [i]
visit.add(i)
cnt = 1
while len(queue) > 0:
now = queue.pop(0)
for j in l[now]:
if j not in visit:
visit.add(j)
queue.append(j)
cnt += 1
m = max(m, cnt)
print(m)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s467240108 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | N, M = map(int, input().split())
mInfos = [list(map(int, input().split())) for _ in range(M)]
gl = [0] * N
mc = [0] * N
gc = 0
guru = []
for i in range(M):
mInfo = mInfos[i]
p1 = mInfo[0]
p2 = mInfo[1]
naiflag = True
if gl[p1 - 1] == 0 and gl[p2 - 1] == 0:
gl[p1 - 1] = gc + 1
gl[p2 - 1] = gc + 1
mc[gc] = 2
gc += 1
elif gl[p1 - 1] != 0:
gl[p2 - 1] = gl[p1 - 1]
mc[p1 - 1] += 1
elif gl[p2 - 1] != 0:
gl[p1 - 1] = gl[p2 - 1]
mc[p2 - 1] += 1
else:
gl = [gl[p1 - 1] if j == gl[p2 - 1] else j for j in gl]
mc[p2 - 1] = 0
gc -= 1
mi = 0
for i in range(1, gc + 1):
dd = gl.count(i)
mi = max(mi, dd)
print(mi)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s614450005 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | # -*- coding: utf-8 -*-
def popcount(x):
"""xの立っているビット数をカウントする関数
(xは64bit整数)"""
# 2bitごとの組に分け、立っているビット数を2bitで表現する
x = x - ((x >> 1) & 0x5555555555555555)
# 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
x = (x + (x >> 4)) & 0x0F0F0F0F0F0F0F0F # 8bitごと
x = x + (x >> 8) # 16bitごと
x = x + (x >> 16) # 32bitごと
x = x + (x >> 32) # 64bitごと = 全部の合計
return x & 0x0000007F
N, M = map(int, input().split())
ans_list = []
for i in range(M):
X, Y = map(int, input().split())
X_bin = bin(1 << (X - 1))
Y_bin = bin(1 << (Y - 1))
com_bin = bin(int(X_bin, 2) | int(Y_bin, 2))
flag = False
for j in range(len(ans_list)):
if (
bin((int(X_bin, 2) & int(ans_list[j], 2))) == X_bin
or bin((int(Y_bin, 2) & int(ans_list[j], 2))) == Y_bin
):
ans_list[j] = bin(int(ans_list[j], 2) | int(com_bin, 2))
flag = True
if not flag:
ans_list.append(com_bin)
max_count = 0
for j in range(len(ans_list)):
count = popcount(int(ans_list[j], 2))
if max_count < count:
max_count = count
print(max_count)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s271805546 | Runtime Error | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n, m = list(map(int, input().rstrip().split(" ")))
members = [1 for i in range(n)]
max_idx = 0
for mm in range(m):
a0, b0 = list(map(int, input().rstrip().split(" ")))
a = a0
b = b0
while members[a - 1] < 0:
a = -members[a - 1]
while members[b - 1] < 0:
b = -members[b - 1]
members[a0 - 1] = -a
members[b0 - 1] = -b
if a != b:
members[a - 1] += members[b - 1]
members[b - 1] = -a
if members[a - 1] > members[max_idx]:
max_idx = a - 1
print(members[max_idx])
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s202183261 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n = list(map(int, input().split()))
kankei = [[]] * (n[0] + 1)
group = [1] * (n[0] + 1)
for i in range(n[1]):
j = list(map(int, input().split()))
j1 = max(j)
j2 = min(j)
if j1 not in kankei[j2]:
kankei[j2].append(j1)
group[j2] += 1
group[j1] += 1
print(max(group))
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s996871493 | Runtime Error | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n, m = list(map(int, input().rstrip().split(" ")))
friendships = []
l = 0
for mm in range(m):
a, b = list(map(int, input().rstrip().split(" ")))
i_a = -1
i_b = -1
j_a = -1
j_b = -1
for ll in range(l):
if a in friendships[ll]:
j_a = friendships[ll].index(a)
i_a = ll
break
for ll in range(l):
if b in friendships[ll]:
j_b = friendships[ll].index(b)
i_b = ll
break
if i_a != -1 and i_b != -1:
if i_a != i_b:
fb_ls = friendships[i_b]
for fb in fb_ls:
friendships[i_a].append(fb)
del friendships[i_b]
l -= 1
elif i_a != -1:
friendships[i_a].append(b)
elif i_b != -1:
friendships[i_b].append(a)
else:
l += 1
friendships.append([a, b])
print(max([len(friendship) for friendship in friendships]))
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s885216645 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n, m = map(int, input().split())
con = []
ans = 0
for i in range(m):
check = True
b, c = map(int, input().split())
if i == 0:
con.append([b, c])
else:
for i in range(len(con)):
if b in con[i]:
check = False
if c in con[i]:
break
else:
con[i].append(c)
break
elif c in con[i]:
check = False
con[i].append(b)
break
if check:
con.append([b, c])
ans = max(ans, len(con[i]))
print(ans)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s844567746 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n, m = list(map(int, input().split()))
abm = [list(map(int, input().split())) for _ in range(m)]
abm = set(tuple(sorted(item)) for item in abm)
edges = {}
for a, b in abm:
if a not in edges:
edges[a] = [b]
else:
edges[a].append(b)
if b not in edges:
edges[b] = [a]
else:
edges[b].append(a)
import collections
vis = [False for _ in range(n + 1)]
gr = {}
def create_group(s):
if vis[s]:
return None
deq = collections.deque()
deq.append(s)
group = []
while len(deq):
node = deq.popleft()
if vis[node]:
continue
group.append(node)
vis[node] = True
for e in edges.get(node, []):
deq.append(e)
for g in group:
gr[g] = s
return group
groups = [create_group(i) for i in range(1, n + 1)]
# print(groups)
groups = list(filter(lambda x: x, groups))
# print(groups)
groupmap = {g[0]: g for g in groups}
# print(gr)
# print(groupmap)
class Cluster:
def __init__(self, s):
self.node_list = [s]
self.group_set = set([gr[s]])
def __str__(self):
return "Cluster(node_list={}, group_set={})".format(
self.node_list, self.group_set
)
clusters = [Cluster(i) for i in range(1, n + 1)]
nc = len(clusters)
while True:
merged = set()
new_clusters = []
for i in range(len(clusters)):
if i in merged:
continue
c1 = clusters[i]
for j in range(i + 1, len(clusters)):
c2 = clusters[j]
if c1 == c2:
continue
# マージ可能か = グループが重なっていない
intersect = c1.group_set.intersection(c2.group_set)
if len(intersect) == 0:
# print(i, j, "をマージ")
# マージ可能
union = c1.group_set.union(c2.group_set)
new_cluster = Cluster(1)
new_cluster.node_list = c1.node_list + c2.node_list
new_cluster.group_set = union
new_clusters.append(new_cluster)
merged.add(j)
break
else:
new_clusters.append(c1)
nc_new = len(new_clusters)
if nc == nc_new:
break
nc = nc_new
clusters = new_clusters
print(nc)
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s617010197 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | import sys
from io import StringIO
import unittest
def resolve():
N, M = map(int, input().split())
l = []
for _ in range(M):
i, j = map(int, input().split())
gi = find_group(l, i)
if not gi:
gi = {i}
l.append(gi)
gj = find_group(l, j)
if not gj:
gj = {j}
l.append(gj)
l.remove(gi)
if gi != gj:
l.remove(gj)
gi = gi | gj
l.append(gi)
max_size = 0
for s in l:
max_size = max(max_size, len(s))
print(max_size)
def find_group(l, i):
for s in l:
if i in s:
return s
return None
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """5 3
1 2
3 4
5 1"""
output = """3"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """4 10
1 2
2 1
1 2
2 1
1 2
1 3
1 4
2 3
2 4
3 4"""
output = """4"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """10 4
3 1
4 1
5 9
2 6"""
output = """3"""
self.assertIO(input, output)
if __name__ == "__main__":
resolve()
| Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
Print the answer.
* * * | s308367160 | Wrong Answer | p02573 | Input is given from Standard Input in the following format:
N M
A_1 B_1
\vdots
A_M B_M | n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
f=[[] for i in range(n)]
j=1
shozoku=[0]*n
for i in range(m):
if shozoku[ab[i][0]-1]==0:
if shozoku[ab[i][1]-1]==0:
shozoku[ab[i][0]-1]+=j
shozoku[ab[i][1]-1]+=j
f[j-1].append(ab[i][0])
f[j-1].append(ab[i][1])
j+=1
else:
shozoku[ab[i][0]-1]+=shozoku[ab[i][1]-1]
f[shozoku[ab[i][1]-1]-1].append(ab[i][0])
else:
if shozoku[ab[i][1]-1]==0:
shozoku[ab[i][1]-1]+=shozoku[ab[i][0]-1]
f[shozoku[ab[i][0]-1]-1].append(ab[i][1])
else:
if shozoku[ab[i][1]-1]!=shozoku[ab[i][0]-1]:
f[shozoku[ab[i][0]-1]-1].extend(f[shozoku[ab[i][1]-1]-1])
f[shozoku[ab[i][1]-1]-1]=f[shozoku[ab[i][0]-1]-1]
ans=1
for i in range(n):
ans=max(len(f[i]),ans)
print(ans) | Statement
There are N persons called Person 1 through Person N.
You are given M facts that "Person A_i and Person B_i are friends." The same
fact may be given multiple times.
If X and Y are friends, and Y and Z are friends, then X and Z are also
friends. There is no friendship that cannot be derived from the M given facts.
Takahashi the evil wants to divide the N persons into some number of groups so
that every person has no friend in his/her group.
At least how many groups does he need to make? | [{"input": "5 3\n 1 2\n 3 4\n 5 1", "output": "3\n \n\nDividing them into three groups such as \\\\{1,3\\\\}, \\\\{2,4\\\\}, and \\\\{5\\\\}\nachieves the goal.\n\n* * *"}, {"input": "4 10\n 1 2\n 2 1\n 1 2\n 2 1\n 1 2\n 1 3\n 1 4\n 2 3\n 2 4\n 3 4", "output": "4\n \n\n* * *"}, {"input": "10 4\n 3 1\n 4 1\n 5 9\n 2 6", "output": "3"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s484928009 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s=input()
print("yes" if len(s)==len(set(s) else "no") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s484288012 | Accepted | p03698 | Input is given from Standard Input in the following format:
S | import sys
input_methods = ["clipboard", "file", "key"]
using_method = 0
input_method = input_methods[using_method]
IN = lambda: map(int, input().split())
mod = 1000000007
# +++++
def main():
s = input()
ii = len(s) == len(list(set(list(s))))
return "yes" if ii else "no"
# +++++
isTest = False
def pa(v):
if isTest:
print(v)
def input_clipboard():
import clipboard
input_text = clipboard.get()
input_l = input_text.splitlines()
for l in input_l:
yield l
if __name__ == "__main__":
if sys.platform == "ios":
if input_method == input_methods[0]:
ic = input_clipboard()
input = lambda: ic.__next__()
elif input_method == input_methods[1]:
sys.stdin = open("inputFile.txt")
else:
pass
isTest = True
else:
pass
# input = sys.stdin.readline
ret = main()
if ret is not None:
print(ret)
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s416648989 | Accepted | p03698 | Input is given from Standard Input in the following format:
S | import math
from collections import deque
from collections import defaultdict
# 自作関数群
def readInt():
return int(input())
def readInts():
return list(map(int, input().split()))
def readChar():
return input()
def readChars():
return input().split()
def factorization(n):
res = []
if n % 2 == 0:
res.append(2)
for i in range(3, math.floor(n // 2) + 1, 2):
if n % i == 0:
c = 0
for j in res:
if i % j == 0:
c = 1
if c == 0:
res.append(i)
return res
def fact2(n):
p = factorization(n)
res = []
for i in p:
c = 0
z = n
while 1:
if z % i == 0:
c += 1
z /= i
else:
break
res.append([i, c])
return res
def fact(n): # 階乗
ans = 1
m = n
for _i in range(n - 1):
ans *= m
m -= 1
return ans
def comb(n, r): # コンビネーション
if n < r:
return 0
l = min(r, n - r)
m = n
u = 1
for _i in range(l):
u *= m
m -= 1
return u // fact(l)
def combmod(n, r, mod):
return (fact(n) / fact(n - r) * pow(fact(r), mod - 2, mod)) % mod
def printQueue(q):
r = copyQueue(q)
ans = [0] * r.qsize()
for i in range(r.qsize() - 1, -1, -1):
ans[i] = r.get()
print(ans)
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x): # root
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -1 * self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x): # much time
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n): # ビット全探索
x = 1
zero = "0" * n
ans = []
ans.append([0] * n)
for i in range(2**n - 1):
ans.append(list(map(lambda x: int(x), list((zero + bin(x)[2:])[-1 * n :]))))
x += 1
return ans
def arrsSum(a1, a2):
for i in range(len(a1)):
a1[i] += a2[i]
return a1
def maxValue(a, b, v):
v2 = v
for i in range(v2, -1, -1):
for j in range(v2 // a + 1): # j:aの個数
k = i - a * j
if k % b == 0:
return i
return -1
def copyQueue(q):
nq = queue.Queue()
n = q.qsize()
for i in range(n):
x = q.get()
q.put(x)
nq.put(x)
return nq
s = readChar()
d = defaultdict(int)
for i in s:
d[i] += 1
for i in d.values():
if i != 1:
print("no")
exit()
print("yes")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s688399732 | Accepted | p03698 | Input is given from Standard Input in the following format:
S | #!/usr/bin/env python3
import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random # random, uniform, randint, randrange, shuffle, sample
# import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate # accumulate(iter[, f])
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)
def main():
mod = 1000000007 # 10^9+7
inf = float("inf") # sys.float_info.max = 1.79...e+308
# inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input():
return sys.stdin.readline().rstrip()
def ii():
return int(input())
def mi():
return map(int, input().split())
def mi_0():
return map(lambda x: int(x) - 1, input().split())
def lmi():
return list(map(int, input().split()))
def lmi_0():
return list(map(lambda x: int(x) - 1, input().split()))
def li():
return list(input())
s = input()
n = len(s)
print("yes") if len(list(set(list(s)))) == n else print("no")
if __name__ == "__main__":
main()
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s953384259 | Accepted | p03698 | Input is given from Standard Input in the following format:
S | from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def main():
S = input()
if len(S) == len(set(S)):
print(yes)
else:
print(no)
if __name__ == "__main__":
main()
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s618810318 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S |
S= input()
B=set(S)
if len(S)==len(B):
print("yes")
else:
print("no")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s109555521 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s=input()
S=[]
for i in range(len(s)):
S.append(s[i])
print("yes" if len(setS))==len(s) else "No") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s075288145 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | a=input()
print("yes" if len(set(a))=len(a) else "no") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s428729617 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = input()
if len(s)==set(s):
print('yes')
else:
print('no) | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s359658664 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | S=[for i in input()]
print('yes' if len(S)==len(set(S)) else 'no')
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s949567425 | Accepted | p03698 | Input is given from Standard Input in the following format:
S | import math
import sys
def getinputdata():
# 配列初期化
array_result = []
data = input()
array_result.append(data.split(" "))
flg = 1
try:
while flg:
data = input()
array_temp = []
if data != "":
array_result.append(data.split(" "))
flg = 1
else:
flg = 0
finally:
return array_result
arr_data = getinputdata()
s = arr_data[0][0]
arr = []
for v in s:
arr.append(v)
arr02 = sorted(arr)
# print(arr02)
chkflg = True
for i in range(0, len(arr02) - 1):
# print(arr02[i])
if arr02[i] == arr02[i + 1]:
chkflg = False
break
if chkflg:
print("yes")
else:
print("no")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s809270253 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = str(input())
if len(s)==(len(set(s)):
ans = "yes"
else:
ans = "no"
print(ans) | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s247541825 | Accepted | p03698 | Input is given from Standard Input in the following format:
S | n = input()
print(("yes", "no")[len(set(n)) < len(n)])
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s352291066 | Wrong Answer | p03698 | Input is given from Standard Input in the following format:
S | print("yes" if len(set(input())) != 26 else "no")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s570071138 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | S=input()
if len(S)==len(set(list(S))):
print('yes'):
else:
print('no') | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s851972549 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = list(input())
if("yes" if len(s) == len(set(s)) else "no") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s190338542 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | a, b = map(int, input().split())
print(a + b if a + b < 10 else "error")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s236631059 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = input()
if len(s)==len(set(s)):
print('yes')
else:
print('no) | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s349148560 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = [i for i in input()]
print("yes" len(s) == len(set(s)) else "no") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s475174323 | Wrong Answer | p03698 | Input is given from Standard Input in the following format:
S | print("yes" if len(set(input())) == 26 else "no")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s719028781 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = list(input())
print("yes" is len(s) == len(set(s)) else "no")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s563989095 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = input()
print("yes" if len(s) = len(set(s))) else "not") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s639512279 | Accepted | p03698 | Input is given from Standard Input in the following format:
S | def ri():
return int(input())
def rli():
return list(map(int, input().split()))
def rls():
return list(input())
def pli(a):
return "".join(list(map(str, a)))
S = rls()
print("yes" if len(S) == len(set(S)) else "no")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s639845567 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | 文字列を取り込む。
文字数を数える。
文字列をソートする。
最初の文字と二番目の文字が同じかどうか確認する。
同じならば'NO'を出力する。
違うならば二番目の文字列と三番目の文字列が同じかどうか確認する。
同じならば'NO'を出力する。
・
・
・
最後から一つ前の文字と最後の文字を確認して違うならば
'YES'を出力する。 | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s330476747 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s=list(input())
s.sort()
j=0
if len(s) == 1:j=0
else: j=1
for i in s:
if j == len(s)-1:print("yes")
break
if i == s[j]:print("no")
break
j+=1 | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s324591980 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = input()
a = [i for i in s]
s = sorted(a)
b = 1
for i in range(len(s)-1):
if s[i] == s[i+1]:
b = 0
print("yes") if b = 1 else print("no")
| Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s041170246 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | import sys
s = sys.stdin.read().rstrip()
if len(s) == len(set(list(s))):
print(“yes”)
else:
print(“no”) | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s953083584 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | import sys
s = input().rstrip()
if len(s) == len(set(list(s))):
print(“yes\n”)
else:
print(“no\n”) | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s040331377 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = input()
a = 0
for i in range(len(s)):
a = a + s.count(s[i])
if a = len(s):
print("yes")
else:
print("no") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s041411071 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | import sys
s = sys.stdin.read().rstrip()
if len(s) == len(set(list(s))):
print(“yes\n”)
else:
print(“no\n”) | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
If all the characters in S are different, print `yes` (case-sensitive);
otherwise, print `no`.
* * * | s560051131 | Runtime Error | p03698 | Input is given from Standard Input in the following format:
S | s = input()
ss = set(s)s = input()
li_s = list(s)
li_ss= list(set(s))
if len(li_s)==len(li_ss):
print("yes")
else:
print("no") | Statement
You are given a string S consisting of lowercase English letters. Determine
whether all the characters in S are different. | [{"input": "uncopyrightable", "output": "yes\n \n\n* * *"}, {"input": "different", "output": "no\n \n\n* * *"}, {"input": "no", "output": "yes"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s754006307 | Accepted | p03362 | Input is given from Standard Input in the following format:
N | # -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
AZ = "abcdefghijklmnopqrstuvwxyz"
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####MakePrimes######
def make_primes(N):
max = int(math.sqrt(N))
seachList = [i for i in range(2, N + 1)]
primeNum = []
while seachList[0] <= max:
primeNum.append(seachList[0])
tmp = seachList[0]
seachList = [i for i in seachList if i % tmp != 0]
primeNum.extend(seachList)
return primeNum
#####GCD#####
def gcd(a, b):
while b:
a, b = b, a % b
return a
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i - 1]) * n**i for i in range(len(str(X))))
def base_10_to_n_without_0(X, n):
X -= 1
if X // n:
return base_10_to_n_without_0(X // n, n) + [X % n]
return [X % n]
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N = I()
P = []
for p in make_primes(55555):
if p % 5 == 1:
P.append(p)
print(*P[:N])
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s429609910 | Wrong Answer | p03362 | Input is given from Standard Input in the following format:
N | x = int(input())
a = [0] * x
k = 0
t = 0
for i in range(11, 55555, 10):
t = 0
for j in range(2, round(i**0.5)):
if i % j == 0:
t = 1
if t == 0 and k < x:
a[k] = i
k = k + 1
print(*a)
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s272909319 | Accepted | p03362 | Input is given from Standard Input in the following format:
N | N = int(input())
dp = [True] * 55556
dp[0] = False
dp[1] = False
for i in range(2, 55556):
if dp[i]:
h = i + i
while h < 55556:
dp[h] = False
h += i
ans = []
for i in range(55556):
if dp[i] and i % 5 == 1:
ans.append(i)
for a in ans[:N]:
print(a, end=" ")
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s322724957 | Accepted | p03362 | Input is given from Standard Input in the following format:
N | p = 55555
l = [1] * p
i = 2
while i * i <= p:
if l[i]:
for j in range(i * i, p, i):
l[j] = 0
i += 1
l[0] = l[1] = 0
prms = [i for i in range(p) if l[i]]
n = int(input())
mod1 = [i for i in prms if i % 5 == 1]
if len(mod1) >= n:
print(*(mod1[:n]))
exit()
mod2 = [i for i in prms if i % 5 == 2]
if len(mod2) >= n:
print(*(mod2[:n]))
exit()
mod3 = [i for i in prms if i % 5 == 3]
if len(mod3) >= n:
print(*(mod2[:n]))
exit()
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s121231607 | Accepted | p03362 | Input is given from Standard Input in the following format:
N | import sys
stdin = sys.stdin
sys.setrecursionlimit(10**5)
def li():
return map(int, stdin.readline().split())
def li_():
return map(lambda x: int(x) - 1, stdin.readline().split())
def lf():
return map(float, stdin.readline().split())
def ls():
return stdin.readline().split()
def ns():
return stdin.readline().rstrip()
def lc():
return list(ns())
def ni():
return int(stdin.readline())
def nf():
return float(stdin.readline())
# 半開区間[lower, upper)の素数のリストを作成する
def make_prime_list(lower: int, upper: int) -> list:
# 変数のバリデーション
if lower < 0:
raise ValueError("lowerは0以上でなければいけません。(lower:{})".format(lower))
elif upper <= lower:
raise ValueError(
"upperはlowerより大きい数でなければいけません。\
(lower:{}, upper:{})".format(
lower, upper
)
)
# 素数リストの初期化
isPrime = [True] * upper
primeList = []
# 区間内の数字が0,1のみならここで終了
if upper <= 2:
return primeList
# 区間内の数字に2以上のものがあるとき
isPrime[0] = False
isPrime[1] = False
# エラトステネスの篩の処理
n = 2
while n**2 <= upper:
if isPrime[n]:
res = 2 * n
while res < upper:
isPrime[res] = False
res += n
n += 1
# 区間内の素数を抽出
for n in range(lower, upper):
if isPrime[n]:
primeList.append(n)
return primeList
n = ni()
prime_list = make_prime_list(0, 55555)
ans = []
for prime in prime_list:
if prime % 5 == 1:
ans.append(prime)
if len(ans) == n:
break
print(*ans)
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s607125803 | Runtime Error | p03362 | Input is given from Standard Input in the following format:
N | import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input()
def read_str_n():
return list(map(str, input().split()))
def mt(f):
import time
import sys
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
print(e - s, 'sec', file=sys.stderr)
return ret
return wrap
def make_p():
P = []
m = (55555 + 1) * 5
mask = [0] * m
for i in range(2, m):
# print(i)
if mask[i] == 0:
for j in range(m):
if i * j >= m:
break
mask[i * j] = 1
P.append(i)
return P
@mt
def slv(N):
p = [
import math
import random
import heapq
from collections import Counter, defaultdict
from decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING
from functools import lru_cache, reduce
from itertools import combinations_with_replacement, product, combinations
def read_int():
return int(input())
def read_int_n():
return list(map(int, input().split()))
def read_float():
return float(input())
def read_float_n():
return list(map(float, input().split()))
def read_str():
return input()
def read_str_n():
return list(map(str, input().split()))
def mt(f):
import time
import sys
def wrap(*args, **kwargs):
s = time.time()
ret = f(*args, **kwargs)
e = time.time()
print(e - s, 'sec', file=sys.stderr)
return ret
return wrap
def make_p():
P = []
m = 55555 + 1
mask = [0] * m
for i in range(2, m):
# print(i)
if mask[i] == 0:
for j in range(m):
if i * j >= m:
break
mask[i * j] = 1
P.append(i)
return P
@mt
def slv(N):
p = [
2, 44497, 51577, 49871, 45631, 48299, 45827, 55061, 52859, 53857, 43499, 44383, 41681, 26701, 48799, 42101, 49549, 46573, 37223, 54829, 44771, 44507, 38201,
45319, 51511, 52051, 55001, 44089, 55207, 45263, 14173, 49033, 45179, 50291, 47051, 45131, 54629, 34537, 51031, 49459, 49787, 55243, 1009, 44909, 45613, 52999, 47881, 52709, 48571, 41593, 41843, 48371, 34819, 55219, 52369
]
return ' '.join(map(str, p[:N]))
def main():
N = read_int()
print(slv(N))
if __name__ == '__main__':
main()
]
return ' '.join(map(str, p[:N]))
def main():
N = read_int()
print(slv(N))
if __name__ == '__main__':
main() | Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s680227329 | Accepted | p03362 | Input is given from Standard Input in the following format:
N | n = int(input())
prime = [2]
no = 3
mod1 = []
mod2 = [2]
mod3 = []
mod4 = []
while len(mod1) < n and len(mod2) < n and len(mod3) < n and len(mod4) < n:
for i in prime:
if no % i == 0:
no += 1
break
else:
prime.append(no)
if no % 5 == 1:
mod1 += [no]
elif no % 5 == 2:
mod2 += [no]
elif no % 5 == 3:
mod3 += [no]
elif no % 5 == 4:
mod4 += [no]
no += 1
if len(mod1) == n:
ans = mod1
elif len(mod2) == n:
ans = mod2
elif len(mod3) == n:
ans = mod3
elif len(mod4) == n:
ans = mod4
for i in ans:
print(i, end=" ")
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s046288481 | Accepted | p03362 | Input is given from Standard Input in the following format:
N | ###############################################################################
from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
mod = 1
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def combination(x, y):
assert x >= y
if y > x // 2:
y = x - y
ret = 1
for i in range(0, y):
j = x - i
i = i + 1
ret = ret * j
ret = ret // i
return ret
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def get_factors(x):
retlist = [1]
for i in range(2, int(x**0.5) + 3):
while x % i == 0:
retlist.append(i)
x = x // i
retlist.append(x)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
class UnionFind:
def __init__(self, n):
self.parent = [i for i in range(n)]
def root(self, i):
if self.parent[i] == i:
return i
self.parent[i] = self.root(self.parent[i])
return self.parent[i]
def unite(self, i, j):
rooti = self.root(i)
rootj = self.root(j)
if rooti == rootj:
return
if i < j:
self.parent[rootj] = rooti
else:
self.parent[rooti] = rootj
def same(self, i, j):
return self.root(i) == self.root(j)
###############################################################################
def main():
n = intin()
ans = [
11,
31,
41,
61,
71,
101,
131,
151,
181,
191,
211,
241,
251,
271,
281,
311,
331,
401,
421,
431,
461,
491,
521,
541,
571,
601,
631,
641,
661,
691,
701,
751,
761,
811,
821,
881,
911,
941,
971,
991,
1021,
1031,
1051,
1061,
1091,
1151,
1171,
1181,
1201,
1231,
1291,
1301,
1321,
1361,
1381,
]
ans = [str(i) for i in ans]
print(" ".join(ans[:n]))
if __name__ == "__main__":
main()
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s582252704 | Wrong Answer | p03362 | Input is given from Standard Input in the following format:
N | print(" ".join(str(i * 10 + 1) for i in range(int(input()))))
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s554860547 | Wrong Answer | p03362 | Input is given from Standard Input in the following format:
N | print(2, 3, 5, 7, 11, 13, 17, 19)
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s401133463 | Runtime Error | p03362 | Input is given from Standard Input in the following format:
N | n = int(input())
prime5 = []
for i in range(1,5600):
a = i * 10 + 1
# flag = True
for j in range(3,int(a**0.5) + 1):
if a % j == 0:
# flag = False
else: prime5.append(a)
print(*prime5[:n]) | Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s453252071 | Wrong Answer | p03362 | Input is given from Standard Input in the following format:
N | # 5で割った余りが1になる素数群を適当にN個並べればいいことに気付いたがそれを実装するには残りの時間が少なすぎる
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s838425502 | Wrong Answer | p03362 | Input is given from Standard Input in the following format:
N | a = [
"2",
"3",
"5",
"7",
"11",
"13",
"17",
"19",
"23",
"29",
"31",
"37",
"41",
"43",
"47",
"53",
"59",
"61",
"67",
"71",
"73",
"79",
"83",
"89",
"97",
"101",
"103",
"107",
"109",
"113",
"127",
"131",
"137",
"139",
"149",
"151",
"157",
"163",
"167",
"173",
"179",
"181",
"191",
"193",
"197",
"199",
"211",
"223",
"227",
"229",
"233",
"239",
"241",
"251",
"257",
"263",
]
n = int(input())
a = " ".join(a[:n])
print(a)
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s437006009 | Runtime Error | p03362 | Input is given from Standard Input in the following format:
N | n=int(input())
a=[]
a.append(2)
k=2
for i in range(55):
while k < 55555 :
k += 1
b = k
for j in a:
if k % j == 0:
b = 0
if b == k:
a.append(k)
break
anss=[]
for j in range(len(a)):
if len(anss) < n:
if a[j] % 5 == 1:
anss.append(a[j])
print(*anss) | Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s346954741 | Wrong Answer | p03362 | Input is given from Standard Input in the following format:
N | N = int(input())
import math
import itertools
def is_prime(n):
answer = "prime"
if n < 2:
answer = "not prime"
elif n == 2 or n == 3:
answer = "prime"
else:
k = math.ceil(math.sqrt(n))
for i in range(2, k + 1, 1):
if n % i == 0:
answer = "not prime"
break
return answer
def any5sum_is_nonprime(N):
if N == 5:
return [2, 3, 5, 7, 11]
else:
prev_lst = any5sum_is_nonprime(N - 1)
k = max(prev_lst) + 2
while len(prev_lst) != N:
if is_prime(k) != "prime":
k = k + 2
else:
c = list(itertools.combinations(prev_lst, 4))
i = 0
n = len(c)
while i < n:
answer = "true"
if is_prime(k + sum(c[i])) == "prime":
answer = "false"
i = i + 1
if answer == "true":
prev_lst.append(k)
return prev_lst
else:
k = k + 2
| Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s689145520 | Runtime Error | p03362 | Input is given from Standard Input in the following format:
N | import random
import itertools
N = int(input())
primes = []
def primesmaker():
global x
x = 0
while x != N:
i = random.randrange(2,55556)
for j in range(i):
if j >= 2 and i%j == 0:
break
else:
primes.append(i)
x = len(primes)
return primes
primes = primesmaker()
y = 0
while y != 1:
for k in itertools.combinations(primes,5):
ks = sum(k)
for l in range(ks):
if l >= 2 and ks%l == 0:
y = 1
primes = primesmaker
print(' '.join(map(str, k))) | Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print N numbers a_1, a_2, a_3, ..., a_N in a line, with spaces in between.
* * * | s973217415 | Runtime Error | p03362 | Input is given from Standard Input in the following format:
N | import math
from itertools import combinations
import sys
def primes(x):
if x < 2: return []
primes = [i for i in range(x)]
primes[1] = 0 # 1は素数ではない
# エラトステネスのふるい
for prime in primes:
if prime > math.sqrt(x): break
if prime == 0: continue
for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0
return [prime for prime in primes if prime != 0]
def is_prime(x):
if x < 2: return False # 2未満に素数はない
if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数
# ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
prime = 7
step = 4
while prime <= math.sqrt(x):
if x % prime == 0: return False
prime += step
step = 6 - step
return True
prime_nums = primes(55555)
prime_list = prime_nums[:5]
prime_remain = prime_nums[5:]
N = int(input())
for p in prime_remain:
prime_l = prime_list + [p]
combs = list(combinations(prime_l, 5))
if not True in [is_prime(sum(c)) for c in combs]:
prime_list = [p for p in prime_l]
# print(len(prime_list), p)
if len(prime_list) == N:
for p in prime_list:
print(p, end = ' ')
break
# sys.exit()
import math
from itertools import combinations
import sys
def primes(x):
if x < 2: return []
primes = [i for i in range(x)]
primes[1] = 0 # 1は素数ではない
# エラトステネスのふるい
for prime in primes:
if prime > math.sqrt(x): break
if prime == 0: continue
for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0
return [prime for prime in primes if prime != 0]
def is_prime(x):
if x < 2: return False # 2未満に素数はない
if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数
# ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
prime = 7
step = 4
while prime <= math.sqrt(x):
if x % prime == 0: return False
prime += step
step = 6 - step
return True
prime_nums = primes(55555)
ans = ''
for p in prime_nums:
if str(p)[-1] == '1':
ans += str(p) + ' '
print(ans)
'''
prime_list = prime_nums[:5]
prime_remain = prime_nums[5:]
N = int(input())
for p in prime_remain:
prime_l = prime_list + [p]
combs = list(combinations(prime_l, 5))
if not True in [is_prime(sum(c)) for c in combs]:
prime_list = [p for p in prime_l]
# print(len(prime_list), p)
if len(prime_list) == N:
for p in prime_list:
print(p, end = ' ')
break
# sys.exit() | Statement
Print a sequence a_1, a_2, ..., a_N whose length is N that satisfies the
following conditions:
* a_i (1 \leq i \leq N) is a prime number at most 55 555.
* The values of a_1, a_2, ..., a_N are all different.
* In every choice of five different integers from a_1, a_2, ..., a_N, the sum of those integers is a composite number.
If there are multiple such sequences, printing any of them is accepted. | [{"input": "5", "output": "3 5 7 11 31\n \n\nLet us see if this output actually satisfies the conditions. \nFirst, 3, 5, 7, 11 and 31 are all different, and all of them are prime\nnumbers. \nThe only way to choose five among them is to choose all of them, whose sum is\na_1+a_2+a_3+a_4+a_5=57, which is a composite number. \nThere are also other possible outputs, such as `2 3 5 7 13`, `11 13 17 19 31`\nand `7 11 5 31 3`.\n\n* * *"}, {"input": "6", "output": "2 3 5 7 11 13\n \n\n * 2, 3, 5, 7, 11, 13 are all different prime numbers.\n * 2+3+5+7+11=28 is a composite number.\n * 2+3+5+7+13=30 is a composite number.\n * 2+3+5+11+13=34 is a composite number.\n * 2+3+7+11+13=36 is a composite number.\n * 2+5+7+11+13=38 is a composite number.\n * 3+5+7+11+13=39 is a composite number.\n\nThus, the sequence `2 3 5 7 11 13` satisfies the conditions.\n\n* * *"}, {"input": "8", "output": "2 5 7 13 19 37 67 79"}] |
Print the maximum possible total value of the selected items.
* * * | s203879619 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | #!/usr/bin/env python3
import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random # random, uniform, randint, randrange, shuffle, sample
# import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce # reduce(f, iter[, init])
# from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
from itertools import accumulate # accumulate(iter[, f])
# from operator import itemgetter # itemgetter(1), itemgetter('key')
# from fractions import gcd # for Python 3.4 (previous contest @AtCoder)
def main():
mod = 1000000007 # 10^9+7
inf = float("inf") # sys.float_info.max = 1.79...e+308
# inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def input():
return sys.stdin.readline().rstrip()
def ii():
return int(input())
def mi():
return map(int, input().split())
def mi_0():
return map(lambda x: int(x) - 1, input().split())
def lmi():
return list(map(int, input().split()))
def lmi_0():
return list(map(lambda x: int(x) - 1, input().split()))
def li():
return list(input())
n, w = mi()
L = [lmi() for _ in range(n)]
w1 = L[0][0]
if n * (w1 + 3) <= w:
print(sum(map(lambda x: x[1], L)))
elif n * w <= 10**6:
# 普通の dp 戦略
dp = [0 for _ in range(w + 1)]
for i in range(n):
weight, value = L[i]
for j in range(w, 0, -1):
if j - weight >= 0:
dp[j] = max(dp[j], dp[j - weight] + value)
print(dp[w])
else:
group_by_weight = [[] for _ in range(4)]
for weight, value in L:
group_by_weight[weight - w1].append(value)
w1_0 = sorted(group_by_weight[0], reverse=True)
w1_1 = sorted(group_by_weight[1], reverse=True)
w1_2 = sorted(group_by_weight[2], reverse=True)
w1_3 = sorted(group_by_weight[3], reverse=True)
accum_0, accum_1, accum_2, accum_3 = map(
lambda x: [0] + list(accumulate(x)), [w1_0, w1_1, w1_2, w1_3]
)
ans = -1
for i in range(len(w1_0) + 1):
for j in range(len(w1_1) + 1):
for k in range(len(w1_2) + 1):
for l in range(len(w1_3) + 1):
if (i + j + k + l) * w1 + j + 2 * k + 3 * l <= w:
ans = max(
ans, accum_0[i] + accum_1[j] + accum_2[k] + accum_3[l]
)
print(ans)
if __name__ == "__main__":
main()
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s038866457 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | N, W = [int(it) for it in input().split()]
li = [[int(it) for it in input().split()] for i in range(N)]
lic = [[], [], [], []]
mi = li[0][0]
for w, v in li:
lic[w - mi].append(v)
[lis.sort() for lis in lic]
[lis.reverse() for lis in lic]
for j in range(4):
pli = lic[j]
for i in range(len(pli) - 1):
pli[i + 1] += pli[i]
for i in range(4):
tmp = [0]
tmp.extend(lic[i])
lic[i] = tmp
sm = 0
for i in range(len(lic[0])):
for j in range(len(lic[1])):
for k in range(len(lic[2])):
for l in range(len(lic[3])):
w = (mi) * (i) + (mi + 1) * (j) + (mi + 2) * (k) + (mi + 3) * (l)
v = lic[0][i] + lic[1][j] + lic[2][k] + lic[3][l]
if w <= W:
sm = max(sm, v)
print(sm)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s613852191 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
x = [[] for _ in range(4)]
w0 = wv[0][0]
for w, v in wv:
x[w - w0].append(v)
for i in range(4):
x[i].sort()
x[i] = x[i][::-1]
y = [[0] for i in range(4)]
for i in range(4):
if len(x[i]) > 0:
y[i].append(x[i][0])
for i in range(4):
for j in range(1, len(x[i])):
y[i].append(y[i][-1] + x[i][j])
res = []
for a in range(len(x[0]) + 1):
for b in range(len(x[1]) + 1):
for c in range(len(x[2]) + 1):
for d in range(len(x[3]) + 1):
if w0 * a + (w0 + 1) * b + (w0 + 2) * c + (w0 + 3) * d <= W:
res.append(y[0][a] + y[1][b] + y[2][c] + y[3][d])
print(max(res))
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s262339383 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | N, W = map(int, input().split())
w = []
v = []
for i in range(N):
a, b = map(int, input().split())
w.append(a)
v.append(b)
w_adjust = []
for i in range(N):
w_adjust.append(w[i]-w[0])
a = w[0]
dp = [[[0 for i in range(N+1)] for j in range(N*3+10)] for k in range(N+1)]
#i個目までの物のうちk個選んで重さの和がjになる中での最大価値
for i in range(N):
for j in range(3*N):
for k in range(N):
dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k])
dp[i+1][j+w_adjust[i]][k+1] = max(dp[i+1][j+w_adjust[i]][k+1], dp[i][j][k] + v[i])
ans = []
for i in range(N+1):
if W - a*i >= 0 and W - a*i <= N*3 + 5
ans.append(dp[N][W-a*i][i])
else:
ans.append(0)
print(max(ans))
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s196058178 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | n,w=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])#reverse
wv.sort(key=lambda x:x[0])
#print(wv)
w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
if wv[i][0]==w0:
k=wv[i][1]+x[0][-1]
l=len(x[0])
if l*w0<=w:x[0].append(k)
elif wv[i][0]==w0+1:
k=wv[i][1]+x[1][-1]
l=len(x[1])
if l*(w0+1)<=w:x[1].append(k)
elif wv[i][0]==w0+2:
k=wv[i][1]+x[2][-1]
l=len(x[2])
if l*(w0+2)<=w:x[2].append(k)
else:
k=wv[i][1]+x[3][-1]
l=len(x[3])
if l*(w0+3)<=w:x[3].append(k)
ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
for i in range(l3):
for j in range(l2)):
for k in range(l1):
d=w-(i*(w0+3)+j*(w0+2)+k*(w0+1))
if d>=0:
ma_sub=x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,len(x[0])-1)]
ma=max(ma,ma_sub)
print(ma)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s397917007 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N |
N,W = map(int, input().split())
w = [0 for i in range(N+1)]
v = [0 for i in range(N+1)]
Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]
#品物、重み→1〜N番目
for i in range(N):
w[i+1],v[i+1] = map(int, input().split())
for i in range(N):
Wsum[i+1] = Wsum[i] + w[i+1]
Vsum[i+1] = Vsum[i] + v[i+1]
#i番目の品物まで含み制約W2のナップサック問題の最適解
def nap(i,W2):
#品物0個のときは価値は0
if i == 0:
return 0
#制約0のときも価値は0
if W == 0:
return 0
#w[i]がW2を超えるときはi番目の品物は不必要
if W2 < w[i]:
return nap(i-1,W2)
#品物の重さ全部足して制約以下なら全部足したものが価値で良い
if Wsum[i] <= W2:
return Vsum[i]
#i番目の品物をナップサックに入れるか入れないか
return max( nap(i-1,W2-w[i])+v[i] , nap(i-1,W2) )
print(nap(N,W), flush = True))
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s928915719 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | # coding=UTF-8
mozir = input()
hyo = mozir.split(" ")
N = int(hyo[0])
W = int(hyo[1])
weight = []
values = []
for idx in range(0, N, 1):
mozir = input()
hyo = mozir.split(" ")
weight.append(int(hyo[0]))
values.append(int(hyo[1]))
minimum_weight = min(weight)
weight_values = list(range(0, 4, 1))
for idx in range(0, 4, 1):
weight_values[idx] = []
for idx in range(0, N, 1):
weight_values[weight[idx] - minimum_weight].append(values[idx])
for idx in range(0, 4, 1):
weight_values[idx].sort(reverse=True)
# print(weight_values)
jogen = min(W // minimum_weight, len(weight_values[0]))
tmpten = [0, 0, 0]
tmpomo = [0, 0, 0]
ans = 0
for idx in range(0, jogen + 1, 1):
tmpten[0] = sum(weight_values[0][0:idx])
tmpomo[0] = minimum_weight * idx
jogen = min((W - tmpomo[0]) // (minimum_weight + 1), len(weight_values[1]))
for idy in range(0, jogen + 1, 1):
tmpten[1] = tmpten[0] + sum(weight_values[1][0:idy])
tmpomo[1] = tmpomo[0] + (minimum_weight + 1) * idy
jogen = min((W - tmpomo[1]) // (minimum_weight + 2), len(weight_values[2]))
for idz in range(0, jogen + 1, 1):
tmpten[2] = tmpten[1] + sum(weight_values[2][0:idz])
tmpomo[2] = tmpomo[1] + (minimum_weight + 2) * idz
kosuu = min((W - tmpomo[2]) // (minimum_weight + 3), len(weight_values[3]))
tmpans = tmpten[2] + sum(weight_values[3][0:kosuu])
# print(tmpans)
ans = max(ans, tmpans)
print(ans)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s744402047 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | #include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x) cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; }
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
int main(void){
long N,W;
cin >> N >> W;
VI w(N),v(N);
REP(i,N){
cin >> w[i] >> v[i];
}
VVI dp(N+1,VI(W+1,0));
FOR(i,1,N+1){
FOR(j,1,W+1){
if (j - w[i-1] < 0) dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
else dp[i][j] = max({dp[i-1][j - w[i-1]] + v[i-1],dp[i][j-1],dp[i-1][j]});
}
}
//dump2d_arr(dp);
cout << dp[N][W] << endl;
return 0;
} | Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s404578582 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
int main(){
ll ans = 0LL;
int N, W;
cin >> N >> W;
vl w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
deque<ll> V[4];
rep(i, N) V[w[i]-w[0]].push_back(v[i]);
rep(i, 4) sort(rall(V[i]));
rep(i, 4) REP(j, 1, V[i].size()) V[i][j] += V[i][j-1];
rep(i, 4) V[i].push_front(0LL);
rep(i, V[0].size()) rep(j, V[1].size()) rep(k, V[2].size()) rep(l, V[3].size()) {
ll now_W = 0LL;
now_W += (ll)w[0]*(i);
now_W += (ll)(w[0]+1)*(j);
now_W += (ll)(w[0]+2)*(k);
now_W += (ll)(w[0]+3)*(l);
//cout << " i: " << i << " j: " << j <<" k: " << k << " l: " << l << " w: " << now_W << " v: " << V[0][i] + V[1][j] + V[2][k] + V[3][l] <<endl;
if(now_W <= W) ans = max(ans, V[0][i] + V[1][j] + V[2][k] + V[3][l]);
}
cout << ans << endl;
}
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s005544893 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | a, b, c = input().split()
if a[-1] == b[0] and b[-1] == c[0]:
print("YES")
else:
print("NO")
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s540231784 | Wrong Answer | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | n, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in [0] * n]
d = {0: 0}
for w, v in wv:
temp = dict()
for k, i in d.items():
if k + w in d.keys():
d[k + w] = max(d[k + w], i + v)
else:
temp[k + w] = i + v
d.update(temp)
s = sorted(d.keys())
m = -1
for i in s:
if d[i] <= m:
del d[i]
else:
m = d[i]
print(max([v for w, v in d.items() if w <= W] + [0]))
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s059319129 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | 4 1
10 100
10 100
10 100
10 100 | Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s914268464 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | N,W=map(int,input().split())
2.dp=[0]*(W+1)
3.for i in range(N):
4. w,v=map(int,input().split())
5. for p,q in enumerate(dp):
6. if p+w<=W:
7. dp[p+w]=max(dp[p+w],q+v)
8.print(max(dp))
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s294289706 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10**7)
# UnionFind
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
return {r: self.members(r) for r in self.roots()}
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def is_prime(n):
if n == 1:
return False
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
# ワーシャルフロイド (任意の2頂点の対に対して最短経路を求める)
# 計算量n^3 (nは頂点の数)
def warshall_floyd(d, n):
# d[i][j]: iからjへの最短距離
for k in range(n):
for i in range(n):
for j in range(n):
d[i][j] = min(d[i][j], d[i][k] + d[k][j])
return d
# ダイクストラ
def dijkstra_heap(s, edge, n):
# 始点sから各頂点への最短距離
d = [10**20] * n
used = [True] * n # True:未確定
d[s] = 0
used[s] = False
edgelist = []
for a, b in edge[s]:
heapq.heappush(edgelist, a * (10**6) + b)
while len(edgelist):
minedge = heapq.heappop(edgelist)
# まだ使われてない頂点の中から最小の距離のものを探す
if not used[minedge % (10**6)]:
continue
v = minedge % (10**6)
d[v] = minedge // (10**6)
used[v] = False
for e in edge[v]:
if used[e[1]]:
heapq.heappush(edgelist, (e[0] + d[v]) * (10**6) + e[1])
return d
# 素因数分解
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
# 2数の最小公倍数
def lcm(x, y):
return (x * y) // gcd(x, y)
# リストの要素の最小公倍数
def lcm_list(numbers):
return reduce(lcm, numbers, 1)
# リストの要素の最大公約数
def gcd_list(numbers):
return reduce(gcd, numbers)
# 素数判定
# limit以下の素数を列挙
def eratosthenes(limit):
A = [i for i in range(2, limit + 1)]
P = []
while True:
prime = min(A)
if prime > sqrt(limit):
break
P.append(prime)
i = 0
while i < len(A):
if A[i] % prime == 0:
A.pop(i)
continue
i += 1
for a in A:
P.append(a)
return P
# 同じものを含む順列
def permutation_with_duplicates(L):
if L == []:
return [[]]
else:
ret = []
# set(集合)型で重複を削除、ソート
S = sorted(set(L))
for i in S:
data = L[:]
data.remove(i)
for j in permutation_with_duplicates(data):
ret.append([i] + j)
return ret
# ここから書き始める
N, W = map(int, input().split())
v = [[] for i in range(4)]
w1 = 0
for i in range(N):
a, b = map(int, input().split())
if i == 0:
w1 = a
v[a - w1].append(b)
for i in range(4):
v[i].sort(reverse=True)
# print(v)
ans = 0
for i in range(N + 1):
for j in range(N - i + 1):
for k in range(N - i - j + 1):
for l in range(N - i - j - k + 1):
if w1 * (i + j + k + l) + j + 2 * k + 3 * l > W:
continue
ans = max(
ans, sum(v[0][:i]) + sum(v[1][:j]) + sum(v[2][:k]) + sum(v[3][:l])
)
print(ans)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s725756997 | Wrong Answer | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | class Data:
def __init__(self):
self.weight = 0
self.value = 0
n, w = list(map(int, input().split(" ")))
value_list = []
for i in range(n):
data = Data()
data_w, data_v = map(int, input().split(" "))
data.weight = data_w
data.value = data_v
value_list.append(data)
datalist = []
for i in range(2**n):
data = Data()
bit_str = bin(i)[2:]
for j in range(len(bit_str)):
if bit_str[j] == "1":
data.weight += value_list[j].weight
data.value += value_list[j].value
datalist.append(data)
oklist = [x for x in datalist if x.weight <= w]
print(max([x.value for x in oklist])) if len(oklist) != 0 else print(0)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s759784591 | Runtime Error | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | from collections import deque
N, W = map(int, input().split())
a = []
b = []
c = []
d = []
w1, v = map(int, input().split())
w2 = w1 + 1
w3 = w2 + 1
w4 = w3 + 1
a.append(v)
for i in range(N - 1):
w, v = map(int, input().split())
if w == w1:
a.append(v)
elif w == w2:
b.append(v)
elif w == w3:
c.append(v)
elif w == w4:
d.append(v)
print(a, b, c, d)
a.sort()
b.sort()
c.sort()
d.sort()
pa = deque(a)
pb = deque(b)
pc = deque(c)
pd = deque(d)
qa = deque()
qb = deque()
qc = deque()
qd = deque()
bw = 0
while pa and bw + w1 <= W:
qa.appendleft(pa.pop())
bw += w1
while pb and bw + w2 <= W:
qb.appendleft(pb.pop())
bw += w2
while qa and pb and bw + 1 <= W and qa[0] < pb[-1]:
qa.popleft()
qb.appendleft(pb.pop())
bw += 1
while pc and bw + w3 <= W:
qc.appendleft(pc.pop())
bw += w3
while pc:
if qa and bw + 2 <= W and (not qb or qa[0] <= qb[0]) and qa[0] < pc[-1]:
qa.popleft()
qc.appendleft(pc.pop())
bw += 2
elif qb and bw + 1 <= W and qb[0] < pc[-1]:
qb.popleft()
qc.appendleft(pc.pop())
bw += 1
while pd and bw + w4 <= W:
qd.appendleft(pd.pop())
bw += w4
while pd:
if (
qa
and bw + 3 <= W
and (not qb or qa[0] <= qb[0])
and (not qc or qa[0] <= qc[0])
and qa[0] < pd[-1]
):
qa.popleft()
qd.appendleft(pd.pop())
bw += 3
elif qb and bw + 2 <= W and (not qc or qb[0] <= qc[0]) and qb[0] < pd[-1]:
qb.popleft()
qd.appendleft(pd.pop())
bw += 2
elif qc and bw + 1 <= W and qc[0] < pd[-1]:
qc.popleft()
qd.appendleft(pd.pop())
bw += 1
print(sum(qa + qb + qc + qd))
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s978288844 | Wrong Answer | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | N, W = [int(x) for x in input().split()]
item = list()
for i in range(N):
item.append([int(x) for x in input().split()])
w1 = item[0][0]
class1 = list()
class2 = list()
class3 = list()
class4 = list()
for i in range(N):
if item[i][0] - w1 == 0:
class1.append(item[i][1])
elif item[i][0] - w1 == 1:
class2.append(item[i][1])
elif item[i][0] - w1 == 2:
class3.append(item[i][1])
else:
class4.append(item[i][1])
class1.sort(reverse=True)
class2.sort(reverse=True)
class3.sort(reverse=True)
class4.sort(reverse=True)
class1.insert(0, 0)
class2.insert(0, 0)
class3.insert(0, 0)
class4.insert(0, 0)
value = 0
weight = 0
maxvalue = 0
for i in range(len(class1) + 1):
for j in range(len(class2) + 1):
for k in range(len(class3) + 1):
for l in range(len(class4) + 1):
for x in range(i):
value += class1[x]
for y in range(j):
value += class2[y]
for z in range(k):
value += class3[z]
for w in range(l):
value += class4[w]
weight = w1 * (i + j + k + l) + j + 2 * k + 3 * l
if weight > W:
weight = 0
value = 0
elif value > maxvalue:
maxvalue = value
weight = 0
value = 0
print(maxvalue)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s578945435 | Wrong Answer | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | n, m = input().split()
N = int(n)
M = int(m)
w_list = []
v_list = []
w1_values = []
w2_values = []
w3_values = []
w4_values = []
sum_w1_values = []
sum_w2_values = []
sum_w3_values = []
sum_w4_values = []
sum_v1 = 0
sum_v2 = 0
sum_v3 = 0
sum_v4 = 0
for i in range(N):
w, v = input().split()
w = int(w)
v = int(v)
w_list.append(w)
v_list.append(v)
w1 = w_list[0]
for j in range(N):
if w_list[j] == w1:
w1_values.append(v_list[j])
sum_v1 += v_list[j]
sum_w1_values.append(sum_v1)
elif w_list[j] == w1 + 1:
w2_values.append(v_list[j])
sum_v2 += v_list[j]
sum_w2_values.append(sum_v2)
elif w_list[j] == w1 + 2:
w3_values.append(v_list[j])
sum_v3 += v_list[j]
sum_w3_values.append(sum_v3)
elif w_list[j] == w1 + 3:
w4_values.append(v_list[j])
sum_v4 += v_list[j]
sum_w4_values.append(sum_v4)
w1_values.sort()
w1_values.reverse()
w2_values.sort()
w2_values.reverse()
w3_values.sort()
w3_values.reverse()
w4_values.sort()
w4_values.reverse()
for p in range(len(w1_values)):
sum_v1 += w1_values[p]
sum_w1_values.append(sum_v1)
for q in range(len(w2_values)):
sum_v2 += w2_values[q]
sum_w2_values.append(sum_v2)
for r in range(len(w3_values)):
sum_v3 += w3_values[r]
sum_w3_values.append(sum_v3)
for s in range(len(w4_values)):
sum_v4 += w4_values[s]
sum_w4_values.append(sum_v4)
sum_w1_values.insert(0, 0)
sum_w2_values.insert(0, 0)
sum_w3_values.insert(0, 0)
sum_w4_values.insert(0, 0)
max_value = 0
count = 0
for w in range(len(sum_w4_values)):
for x in range(len(sum_w3_values)):
for y in range(len(sum_w2_values)):
for z in range(len(sum_w1_values)):
count = w + x + y + z
weight = (w1) * z + (w1 + 1) * y + (w1 + 2) * x + (w1 + 3) * w
if (
count <= N
and weight <= M
and max_value
< (
sum_w1_values[z]
+ sum_w2_values[y]
+ sum_w3_values[x]
+ sum_w4_values[w]
)
):
max_value = (
sum_w1_values[z]
+ sum_w2_values[y]
+ sum_w3_values[x]
+ sum_w4_values[w]
)
print(max_value)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s487485131 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | N, W, *L = map(int, open(0).read().split())
w1 = L[0]
l = [[] for _ in range(4)]
for w, v in zip(*[iter(L)] * 2):
l[w - w1].append(v)
l = [sorted(t)[::-1] for t in l]
a, b, c, d = map(len, l)
ans = 0
for h in range(a + 1):
for i in range(b + 1):
for j in range(c + 1):
for k in range(d + 1):
if w1 * h + (w1 + 1) * i + (w1 + 2) * j + (w1 + 3) * k <= W:
ans = max(ans, sum(l[0][:h] + l[1][:i] + l[2][:j] + l[3][:k]))
print(ans)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s974346280 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
def resolve():
n, W = map(int, input().split())
WV = [tuple(map(int, input().split())) for _ in range(n)]
weight = set()
for i in range(n + 1):
if WV[0][0] * i > W:
break
for j in range(3 * i + 1):
if WV[0][0] * i + j > W:
break
weight.add(WV[0][0] * i + j)
weight = sorted(weight)
dp = defaultdict(int)
for i in range(n):
ndp = defaultdict(int)
w, v = WV[i]
for key in weight:
ndp[key] = max(ndp[key], dp[key])
if key + w <= W:
ndp[key + w] = max(ndp[key + w], dp[key] + v)
dp = ndp
print(max(dp.values()))
resolve()
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s392338153 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | N, W = map(int, input().split())
wlist = [0] * N
vlist = [0] * N
for i in range(N):
wlist[i], vlist[i] = map(int, input().split())
minw = min(wlist)
w = list()
for i in range(4):
w.append(list())
for i in range(N):
w[wlist[i] - minw].append(vlist[i])
for i in range(4):
w[i].sort(reverse=True)
ans = 0
sumw0 = 0
sumv0 = 0
for i in range(len(w[0]) + 1):
sumw1 = 0
sumv1 = 0
for j in range(len(w[1]) + 1):
sumw2 = 0
sumv2 = 0
for k in range(len(w[2]) + 1):
sumw3 = 0
sumv3 = 0
for l in range(len(w[3]) + 1):
sumw = sumw0 + sumw1 + sumw2 + sumw3
sumv = sumv0 + sumv1 + sumv2 + sumv3
if sumw <= W:
ans = max(ans, sumv)
if l != len(w[3]):
sumw3 += minw + 3
sumv3 += w[3][l]
if k != len(w[2]):
sumw2 += minw + 2
sumv2 += w[2][k]
if j != len(w[1]):
sumw1 += minw + 1
sumv1 += w[1][j]
if i != len(w[0]):
sumw0 += minw
sumv0 += w[0][i]
print(ans)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s550519461 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | n, max_w = map(int, input().split())
w1 = []
w2 = []
w3 = []
w4 = []
v1 = []
v2 = []
v3 = []
v4 = []
w_1, v_1 = map(int, input().split())
w1.append(w_1)
v1.append(v_1)
for i in range(1, n):
tmp_w, tmp_v = map(int, input().split())
if tmp_w == w_1:
w1.append(tmp_w)
v1.append(tmp_v)
elif tmp_w == w_1 + 1:
w2.append(tmp_w)
v2.append(tmp_v)
elif tmp_w == w_1 + 2:
w3.append(tmp_w)
v3.append(tmp_v)
elif tmp_w == w_1 + 3:
w4.append(tmp_w)
v4.append(tmp_v)
count1 = len(w1)
count2 = len(w2)
count3 = len(w3)
count4 = len(w4)
v1 = sorted(v1, reverse=True)
v2 = sorted(v2, reverse=True)
v3 = sorted(v3, reverse=True)
v4 = sorted(v4, reverse=True)
ruiseki_v1 = [0] * count1
ruiseki_v2 = [0] * count2
ruiseki_v3 = [0] * count3
ruiseki_v4 = [0] * count4
if v1:
ruiseki_v1[0] = v1[0]
for i in range(count1 - 1):
ruiseki_v1[i + 1] = ruiseki_v1[i] + v1[i + 1]
if v2:
ruiseki_v2[0] = v2[0]
for i in range(count2 - 1):
ruiseki_v2[i + 1] = ruiseki_v2[i] + v2[i + 1]
if v3:
ruiseki_v3[0] = v3[0]
for i in range(count3 - 1):
ruiseki_v3[i + 1] = ruiseki_v3[i] + v3[i + 1]
if v4:
ruiseki_v4[0] = v4[0]
for i in range(count4 - 1):
ruiseki_v4[i + 1] = ruiseki_v4[i] + v4[i + 1]
ruiseki_v1.insert(0, 0)
ruiseki_v2.insert(0, 0)
ruiseki_v3.insert(0, 0)
ruiseki_v4.insert(0, 0)
ans = 0
for i in range(count1 + 1):
for j in range(count2 + 1):
for k in range(count3 + 1):
for l in range(count4 + 1):
if i * w_1 + j * (w_1 + 1) + k * (w_1 + 2) + l * (w_1 + 3) <= max_w:
ans = max(
ans,
ruiseki_v1[i] + ruiseki_v2[j] + ruiseki_v3[k] + ruiseki_v4[l],
)
print(ans)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum possible total value of the selected items.
* * * | s562003980 | Accepted | p03732 | Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N | n, W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
data = [[] for i in range(4)]
w1 = wv[0][0]
for u in wv:
w, v = u
data[w - w1].append(v)
for i in range(4):
data[i].sort(reverse=True)
data[i] = [0] + data[i]
for j in range(1, len(data[i])):
data[i][j] += data[i][j - 1]
a = len(data[0])
b = len(data[1])
c = len(data[2])
d = len(data[3])
ans = 0
for i in range(a):
for j in range(b):
for k in range(c):
for l in range(d):
if w1 * i + (w1 + 1) * j + (w1 + 2) * k + (w1 + 3) * l <= W:
ans = max(ans, data[0][i] + data[1][j] + data[2][k] + data[3][l])
print(ans)
| Statement
You have N items and a bag of strength W. The i-th item has a weight of w_i
and a value of v_i.
You will select some of the items and put them in the bag. Here, the total
weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items. | [{"input": "4 6\n 2 1\n 3 4\n 4 10\n 3 4", "output": "11\n \n\nThe first and third items should be selected.\n\n* * *"}, {"input": "4 6\n 2 1\n 3 7\n 4 10\n 3 6", "output": "13\n \n\nThe second and fourth items should be selected.\n\n* * *"}, {"input": "4 10\n 1 100\n 1 100\n 1 100\n 1 100", "output": "400\n \n\nYou can take everything.\n\n* * *"}, {"input": "4 1\n 10 100\n 10 100\n 10 100\n 10 100", "output": "0\n \n\nYou can take nothing."}] |
Print the maximum total score earned in the game.
* * * | s806686214 | Runtime Error | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | *t, s = open(0).read().split()
n, k, r, s, p = map(int, t)
d = {"r": p, "s": r, "p": s}
b = [""] * n * 2
a = 0
for i, c in enumerate(s[:n]):
if c != b[i - k]:
b[i] = c
a += d[c]
print(a)
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s724867108 | Runtime Error | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | import random
def main():
"""Main function that will welcome the player to the game."""
print("\tWelcome to Battle Sim! This is a turn based combat simulator where")
print("\tthere can only be one winner.")
print(
"\nHow to play.\n\nPlayers take turn to choose a move. Moves can either deal moderate damage"
)
print("with a low range, deal high damage but over a wide")
print("range, or they can heal. (Note: Moves can miss, including Heal!)")
print("\nEach player starts with 100 health, and the first")
print("player to reduce their opponent to 0 is the winner.")
print("\nThat's it! Good luck")
play_again = True
# Set up the play again loop
while play_again:
winner = None
player_health = 100
computer_health = 100
# determine whose turn it is
turn = random.randint(1, 2) # heads or tails
if turn == 1:
player_turn = True
computer_turn = False
print("\nPlayer will go first.")
else:
player_turn = False
computer_turn = True
print("\nComputer will go first.")
print("\nPlayer health: ", player_health, "Computer health: ", computer_health)
# set up the main game loop
while player_health != 0 or computer_health != 0:
heal_up = False # determine if heal has been used by the player. Resets false each loop.
miss = False # determine if the chosen move will miss.
# create a dictionary of the possible moves and randomly select the damage it does when selected
moves = {
"Punch": random.randint(18, 25),
"Mega Punch": random.randint(10, 35),
"Heal": random.randint(20, 25),
}
if player_turn:
print(
"\nPlease select a move:\n1. Punch (Deal damage between 18-25)\n2. Mega Punch (Deal damage between 10-35)\n3. Heal (Restore between 20-25 health)\n"
)
player_move = input("> ").lower()
move_miss = random.randint(1, 5) # 20% of missing
if move_miss == 1:
miss = True
else:
miss = False
if miss:
player_move = 0 # player misses and deals no damage
print("You missed!")
else:
if player_move in ("1", "punch"):
player_move = moves["Punch"]
print("\nYou used Punch. It dealt ", player_move, " damage.")
elif player_move in ("2", "mega punch"):
player_move = moves["Mega Punch"]
print(
"\nYou used Mega Punch. It dealt ", player_move, " damage."
)
elif player_move in ("3", "heal"):
heal_up = True # heal activated
player_move = moves["Heal"]
print(
"\nYou used Heal. It healed for ", player_move, " health."
)
else:
print("\nThat is not a valid move. Please try again.")
continue
else: # computer turn
move_miss = random.randint(1, 5)
if move_miss == 1:
miss = True
else:
miss = False
if miss:
computer_move = 0 # the computer misses and deals no damage
print("The computer missed!")
else:
if computer_health > 30:
if player_health > 75:
computer_move = moves["Punch"]
print(
"\nThe computer used Punch. It dealt ",
computer_move,
" damage.",
)
elif (
player_health > 35 and player_health <= 75
): # computer decides whether to go big or play it safe
imoves = ["Punch", "Mega Punch"]
imoves = random.choice(imoves)
computer_move = moves[imoves]
print(
"\nThe computer used ",
imoves,
". It dealt ",
computer_move,
" damage.",
)
elif player_health <= 35:
computer_move = moves["Mega Punch"] # FINISH HIM!
print(
"\nThe computer used Mega Punch. It dealt ",
computer_move,
" damage.",
)
else: # if the computer has less than 30 health, there is a 50% chance they will heal
heal_or_fight = random.randint(1, 2)
if heal_or_fight == 1:
heal_up = True
computer_move = moves["Heal"]
print(
"\nThe computer used Heal. It healed for ",
computer_move,
" health.",
)
else:
if player_health > 75:
computer_move = moves["Punch"]
print(
"\nThe computer used Punch. It dealt ",
computer_move,
" damage.",
)
elif player_health > 35 and player_health <= 75:
imoves = ["Punch", "Mega Punch"]
imoves = random.choice(imoves)
computer_move = moves[imoves]
print(
"\nThe computer used ",
imoves,
". It dealt ",
computer_move,
" damage.",
)
elif player_health <= 35:
computer_move = moves["Mega Punch"] # FINISH HIM!
print(
"\nThe computer used Mega Punch. It dealt ",
computer_move,
" damage.",
)
if heal_up:
if player_turn:
player_health += player_move
if player_health > 100:
player_health = 100 # cap max health at 100. No over healing!
else:
computer_health += computer_move
if computer_health > 100:
computer_health = 100
else:
if player_turn:
computer_health -= player_move
if computer_health < 0:
computer_health = 0 # cap minimum health at 0
winner = "Player"
break
else:
player_health -= computer_move
if player_health < 0:
player_health = 0
winner = "Computer"
break
print(
"\nPlayer health: ", player_health, "Computer health: ", computer_health
)
# switch turns
player_turn = not player_turn
computer_turn = not computer_turn
# once main game while loop breaks, determine winner and congratulate
if winner == "Player":
print(
"\nPlayer health: ", player_health, "Computer health: ", computer_health
)
print("\nCongratulations! You have won. You're an animal!!")
else:
print(
"\nPlayer health: ", player_health, "Computer health: ", computer_health
)
print(
"\nSorry, but your opponent wiped the floor with you. Better luck next time."
)
print("\nWould you like to play again?")
answer = input("> ").lower()
if answer not in ("yes", "y"):
play_again = False
main()
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s120536783 | Wrong Answer | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | # -*- coding: utf-8 -*-
################ DANGER ################
test = ""
# test = \
"""
5 2
8 7 6
rsrpr
ans 27
"""
"""
7 1
100 10 1
ssssppr
ans 211
"""
"""
30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr
ans 4996
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
def input2():
return test.pop()
else:
def input2():
return input()
########################################
n, k = map(int, input2().split())
r, s, p = map(int, input2().split())
t = list(input2())
rsp = {"r", "s", "p"}
for i in range(k, n - 1):
if t[i] == t[i - k]:
t[i] = rsp - {t[i], t[i + 1]}
ans = t.count("r") * p + t.count("s") * r + t.count("p") * s
print(ans)
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s691860812 | Accepted | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | n, k = map(int, input().split())
r, s, p = map(int, input().split())
point = {"r": r, "s": s, "p": p}
v = {"r": "p", "s": "r", "p": "s"}
t = input()
ans = 0
for i in range(k):
for j in range(i, n, k):
if j == i:
prev = v[t[j]]
ans += point[v[t[j]]]
else:
if v[t[j]] != prev:
ans += point[v[t[j]]]
prev = v[t[j]]
else:
# rに勝つ手が出せない
if t[j] == "r":
if j + k < n:
if t[j + k] == "r":
prev = "s"
elif t[j + k] == "s":
prev = "s"
else:
prev = "r"
elif t[j] == "s":
if j + k < n:
if t[j + k] == "r":
prev = "s"
elif t[j + k] == "s":
prev = "s"
else:
prev = "p"
elif t[j] == "p":
if j + k < n:
if t[j + k] == "r":
prev = "r"
elif t[j + k] == "s":
prev = "p"
else:
prev = "r"
print(ans)
# dp = [{x: 0 for x in ["r", "s", "p"]} for y in range(n + 1)]
# v = {"r": "p", "s": "r", "p": "s"}
# for i in range(1, n + 1):
# for j in ["r", "s", "p"]:
# now_v = v[t[i - 1]]
# if i < k + 1:
# if j == now_v:
# dp[i][j] = max(dp[i - 1].values()) + 1
# else:
# dp[i][j] = max(dp[i - 1].values())
# else:
# if j == now_v:
# if now_v == "r":
# dp[i][j] = max(dp[i - 1][j] + dp[i - k]["s"], dp[i - 1][j] + dp[i - k]["p"])
# elif now_v == "s":
# dp[i][j] = max(dp[i - 1][j] + dp[i - k]["r"], dp[i - 1][j] + dp[i - k]["p"])
# elif now_v == "p":
# dp[i][j] = max(dp[i - 1][j] + dp[i - k]["r"], dp[i - 1][j] + dp[i - k]["s"])
# print(dp)
# for i in dp:
# print(i)
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s380536251 | Runtime Error | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ro, si, pa = 0, 0, 0
rp, sp, pp = 0, 0, 0
for t in range(len(T)):
if T[t] == "r":
pa += 1
if (t - K >= 0 and T[t - K] == "r") and (
t + K > N or (t + K <= N and T[t + K] != "r")
):
pp += 1
if T[t] == "s":
ro += 1
if (t - K >= 0 and T[t - K] == "s") and (
t + K > N or (t + K <= N and T[t + K] != "s")
):
rp += 1
if T[t] == "p":
si += 1
if (t - K >= 0 and T[t - K] == "p") and (
t + K > N or (t + K <= N and T[t + K] != "p")
):
sp += 1
s_r = (ro - rp) * R
s_s = (si - sp) * S
s_p = (pa - pp) * P
print(s_r + s_s + s_p)
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s029283925 | Accepted | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | # import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, R, S, P, T):
k_list = [[] for _ in range(K)]
for i in range(len(T)):
k_list[i % K].append(T[i])
ans = 0
for kl in k_list:
dp = [[0, 0, 0] for _ in range(len(kl) + 1)]
for i in range(len(kl)):
# rock
dp[i + 1][0] = max(dp[i][1], dp[i][2])
dp[i + 1][0] += R if kl[i] == "s" else 0
# scissors
dp[i + 1][1] = max(dp[i][0], dp[i][2])
dp[i + 1][1] += S if kl[i] == "p" else 0
# paper
dp[i + 1][2] = max(dp[i][0], dp[i][1])
dp[i + 1][2] += P if kl[i] == "r" else 0
ans += max(dp[-1])
print(ans)
if __name__ == "__main__":
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
# N, K = 10 ** 5, 10 ** 3
# R, S, P = 100, 90, 5
# T = 'r' * 10 ** 5
solve(N, K, R, S, P, T)
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s959567506 | Accepted | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | import sys
from io import StringIO
import unittest
import numpy as np
def resolve():
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
ans = [[-1 for _ in range(n)] for _ in range(3)]
# 0 -> グーrを出したとき
# 1 -> ちょきs
# 2 -> パーp
for i in range(k):
for j in range(i, n, k):
if j < k:
if t[j] == "r":
ans[0][j] = 0
ans[1][j] = 0
ans[2][j] = p
elif t[j] == "s":
ans[0][j] = r
ans[1][j] = 0
ans[2][j] = 0
elif t[j] == "p":
ans[0][j] = 0
ans[1][j] = s
ans[2][j] = 0
else:
if t[j] == "r":
ans[0][j] = max(ans[1][j - k], ans[2][j - k])
ans[1][j] = max(ans[0][j - k], ans[2][j - k])
ans[2][j] = max(ans[0][j - k], ans[1][j - k]) + p
elif t[j] == "s":
ans[0][j] = max(ans[1][j - k], ans[2][j - k]) + r
ans[1][j] = max(ans[0][j - k], ans[2][j - k])
ans[2][j] = max(ans[0][j - k], ans[1][j - k])
elif t[j] == "p":
ans[0][j] = max(ans[1][j - k], ans[2][j - k])
ans[1][j] = max(ans[0][j - k], ans[2][j - k]) + s
ans[2][j] = max(ans[0][j - k], ans[1][j - k])
ans = np.array(ans)
print(ans[:, (-1 * k) :].max(axis=0).sum())
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """5 2
8 7 6
rsrpr"""
output = """27"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """7 1
100 10 1
ssssppr"""
output = """211"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr"""
output = """4996"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s838628697 | Wrong Answer | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | n, k = map(int, input().split())
r_origin, s_origin, p_origin = map(int, input().split())
t = "!" + str(input())
def make_rsp(i):
global t, r_origin, s_origin, p_origin
r_temp = 0
s_temp = 0
p_temp = 0
if t[i] == "r":
p_temp = p_origin
if t[i] == "s":
r_temp = r_origin
if t[i] == "p":
s_temp = s_origin
return r_temp, s_temp, p_temp
rock = [0] * (n + 1)
sissors = [0] * (n + 1)
paper = [0] * (n + 1)
best = [0] * (n + 1)
for i in range(1, n + 1):
best[i] = max(make_rsp(i))
for i in range(1, k + 1):
m = max(rock[i - 1], sissors[i - 1], paper[i - 1])
r_temp, s_temp, p_temp = make_rsp(i)
rock[i] = r_temp + m
sissors[i] = s_temp + m
paper[i] = p_temp + m
if k > 1:
cnt = sum(best[2 : k + 1])
else:
cnt = 0
for i in range(k + 1, n + 1):
r_temp, s_temp, p_temp = make_rsp(i)
rb = rock[i - k]
sb = sissors[i - k]
pb = paper[i - k]
rock[i] = r_temp + cnt + max(sb, pb)
sissors[i] = s_temp + cnt + max(rb, pb)
paper[i] = p_temp + cnt + max(rb, sb)
cnt += best[i]
cnt -= best[i - k + 1]
print(max(rock[n], sissors[n], paper[n]))
# print("r", rock)
# print("s", sissors)
# print("p", paper)
# print(best)
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s159694432 | Wrong Answer | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | n, k = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
slist = [""] * k
for i in range(n):
slist[i % k] += T[i]
ans = 0
for s in slist:
dp = [[0, 0, 0] for i in range(len(s))]
# dp[i][j] = 直前にjを出したときの得点の最大値
"""
0..r
1..s
2..p
"""
dp[0][1] = S if s[0] == "p" else 0
dp[0][0] = R if s[0] == "s" else 0
dp[0][2] = P if s[0] == "r" else 0
for i in range(1, len(s)):
if s[i] == "r":
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + P
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2])
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2])
elif s[i] == "s":
dp[i][0] = max(dp[i - 1][2], dp[i - 1][1]) + R
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2])
dp[i][2] = max(dp[i - 1][1], dp[i - 1][0])
else:
dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + S
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2])
dp[i][2] = max(dp[i - 1][1], dp[i - 1][0])
ans += max(dp[len(s) - 1][0], dp[len(s) - 1][1], dp[len(s) - 1][2])
print(slist)
print(ans)
"""
解説AC...
"""
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s477243442 | Wrong Answer | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | from sys import stdin
n, k = [int(x) for x in stdin.readline().rstrip().split()]
r, s, p = [int(x) for x in stdin.readline().rstrip().split()]
t = stdin.readline().rstrip()
r, s, p = p, r, s
rsp = [0] * 3
if r >= s and r >= p:
rsp[0] = "r"
elif r >= s and r < p:
rsp[1] = "r"
elif r < s and r >= p:
rsp[1] = "r"
elif r < s and r < p:
rsp[2] = "r"
if s > r and s > p:
rsp[0] = "s"
elif s >= r and s <= p:
rsp[1] = "s"
elif s < r and s >= p:
rsp[1] = "s"
elif s < r and s < p:
rsp[2] = "s"
if p > s and p > r:
rsp[0] = "p"
elif p >= s and p < r:
rsp[1] = "p"
elif p < s and p >= r:
rsp[1] = "p"
elif p <= s and p <= r:
rsp[2] = "p"
answer = 0
a = max(r, s, p)
c = min(r, s, p)
b = r + s + p - a - c
tk = t
t = [0] * n
for i in range(n):
t[i] = tk[i]
for i in range(n):
if i <= k - 1:
if t[i] == rsp[0]:
answer += a
else:
if t[i] == rsp[0]:
if t[i] == t[i - k]:
t[i] = "n"
else:
answer += a
for i in range(n):
if i <= k - 1:
if t[i] == rsp[1]:
answer += b
else:
if t[i] == rsp[1]:
if t[i] == t[i - k]:
t[i] = "n"
else:
answer += b
for i in range(n):
if i <= k - 1:
if t[i] == rsp[2]:
answer += c
else:
if t[i] == rsp[2]:
if t[i] == t[i - k]:
t[i] = "n"
else:
answer += c
print(answer)
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Print the maximum total score earned in the game.
* * * | s954295949 | Wrong Answer | p02820 | Input is given from Standard Input in the following format:
N K
R S P
T | n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = []
dp = [[0] * 4 for _ in range(n + 1)]
for i in range(n):
if i >= k:
ng = ans[i - k]
if ng == "r":
dp[i + 1][0] = 0
if t[i] == "r":
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2]) + p
elif t[i] == "s":
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
elif t[i] == "p":
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2]) + s
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
elif ng == "s":
dp[i + 1][1] = 0
if t[i] == "r":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2]) + p
elif t[i] == "s":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2]) + r
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
elif t[i] == "p":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
elif ng == "p":
dp[i + 1][2] = 0
if t[i] == "r":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
elif t[i] == "s":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2]) + r
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
elif t[i] == "p":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2]) + s
else:
if t[i] == "r":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2]) + p
elif t[i] == "s":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2]) + r
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
elif t[i] == "p":
dp[i + 1][0] = max(dp[i][0], dp[i][1], dp[i][2])
dp[i + 1][1] = max(dp[i][0], dp[i][1], dp[i][2]) + s
dp[i + 1][2] = max(dp[i][0], dp[i][1], dp[i][2])
rock, sci, paper = dp[i + 1][0], dp[i + 1][1], dp[i + 1][2]
if rock == max(rock, sci, paper):
ans += ["r"]
elif sci == max(rock, sci, paper):
ans += ["s"]
elif paper == max(rock, sci, paper):
ans += ["p"]
# print('dp: ', dp)
# print('ans:', ans)
print(max(dp[n][0], dp[n][1], dp[n][2]))
| Statement
At an arcade, Takahashi is playing a game called _RPS Battle_ , which is
played as follows:
* The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)
* Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):
* R points for winning with Rock;
* S points for winning with Scissors;
* P points for winning with Paper.
* However, in the i-th round, the player cannot use the hand he/she used in the (i-K)-th round. (In the first K rounds, the player can use any hand.)
Before the start of the game, the machine decides the hand it will play in
each round. With supernatural power, Takahashi managed to read all of those
hands.
The information Takahashi obtained is given as a string T. If the i-th
character of T (1 \leq i \leq N) is `r`, the machine will play Rock in the
i-th round. Similarly, `p` and `s` stand for Paper and Scissors, respectively.
What is the maximum total score earned in the game by adequately choosing the
hand to play in each round? | [{"input": "5 2\n 8 7 6\n rsrpr", "output": "27\n \n\nThe machine will play {Rock, Scissors, Rock, Paper, Rock}.\n\nWe can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to\nearn 27 points. We cannot earn more points, so the answer is 27.\n\n* * *"}, {"input": "7 1\n 100 10 1\n ssssppr", "output": "211\n \n\n* * *"}, {"input": "30 5\n 325 234 123\n rspsspspsrpspsppprpsprpssprpsr", "output": "4996"}] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.