output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s298633512
Accepted
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
t = open(0).read() print(("P" * (t.count("#") < sum(map(int, t.split()[:2]))) or "Imp") + "ossible")
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s527112091
Accepted
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
from collections import deque # 下右1マスを検索するために必要とする dis_x = [1, 0] dis_y = [0, 1] # 迷路の縦幅,横幅 max_h, max_w = map(int, input().split()) s = [] av_count = 0 for _ in range(max_h): line = input() av_count += line.count("#") # 横1マスを壁でPadding. これでindex out of boundを防ぐ s.append(list(".{}.".format(line))) # 縦1マスを壁でPadding. これでindex out of boundを防ぐ s = [list("." * (max_w + 2))] + s + [list("." * (max_w + 2))] # 迷路と同じサイズの距離表を作成. # 値が0 -> 未訪問, それ以外 -> スタート地点からそれまでの距離となる dist = [[0] * (max_w + 2) for _ in range(max_h + 2)] # キューにスタート地点をプッシュ que = deque([(1, 1)]) # キューに値が格納されている間 while que: # 先頭の値を取り出す h, w = que.popleft() for i in range(2): # 移動距離 dx, dy = dis_x[i], dis_y[i] if s[h + dy][w + dx] == "#" and dist[h + dy][w + dx] == 0: # ここまでの距離+1して訪問済みに dist[h + dy][w + dx] = dist[h][w] + 1 # キューに加える -> (h+dy, w+dx) を起点にまた上下左右4マスをチェックする,という意味 que.append((h + dy, w + dx)) break dist[1][1] = 1 dis = 0 for line in dist: dis += len(list(filter(lambda x: x != 0, line))) print("Possible" if av_count == dis else "Impossible")
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s388445803
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
h, w = map(int, input().split()) mat_a = [ list(input()) for _ in range(h) ] ans = 'Possible' ans = 'Impossible' def check(i,j): if mat_a[i][j] == '.': return True count = 0 try: if mat_a[i][j-1] == '#': count += 1 except: pass try: if mat_a[i-1][j] == '#': count += 1 except: pass try: if mat_a[i][j+1] == '#': count += 1 except: pass try: if mat_a[i+1][j] == '#': count += 1 except: pass if count == 2 or count ==4: return True else: return False ans = True for i in range(h): for j in range(w): if not check(i,j): if i+1 == h and j+1 == w: continue if i == 0 and j == 0: continue ans = False break if ans: print('Possible') else: print('Impossible') (env3) (kentaro:~/git/2020/atcode/20200717/3 2020-07-17T17:09:31)$ vi main.py (env3) (kentaro:~/git/2020/atcode/20200717/3 2020-07-17T17:10:52)$ cat main.py h, w = map(int, input().split()) mat_a = [ list(input()) for _ in range(h) ] def check(i,j): if mat_a[i][j] == '.': return True count = 0 try: if mat_a[i][j-1] == '#': count += 1 except: pass try: if mat_a[i-1][j] == '#': count += 1 except: pass try: if mat_a[i][j+1] == '#': count += 1 except: pass try: if mat_a[i+1][j] == '#': count += 1 except: pass if count == 2 or count == 4: return True else: return False ans = True for i in range(h): for j in range(w): if not check(i,j): if i+1 == h and j+1 == w: continue if i == 0 and j == 0: continue ans = False break if ans: print('Possible') else: print('Impossible')
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s896466307
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
#define rep(i,n) for (int i = 0; i < (int)(n); i++) #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { cin.tie(0); ios::sync_with_stdio(false); short h,w,ans = 0; cin >> h >> w; char ai[10]; rep(i,h) { cin >> ai; rep(j,8) if (ai[j] == '#') ans ++; } if (ans == h+w-1) cout << "Possible\n"; else cout << "Impossible\n"; }
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s485715397
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
input_nums = [int(n) for n in input().slice(“ ”)] h = input_nums[0] w = input_nums[1] count = 0 for i in range(h): for c in input(): if c == “#”: count += 1 if count == h+w-1: print(“Possible”) else: print(“Impossible”)
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s376446570
Accepted
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
def chk(r, c): cnt_in, cnt_out = 0, 0 if (r, c) == (0, 0): cnt_in += 1 if (r, c) == (H - 1, W - 1): cnt_out += 1 if r - 1 >= 0: if a[r - 1][c] == "#": cnt_in += 1 if r + 1 < H: if a[r + 1][c] == "#": cnt_out += 1 if c - 1 >= 0: if a[r][c - 1] == "#": cnt_in += 1 if c + 1 < W: if a[r][c + 1] == "#": cnt_out += 1 return cnt_in == 1 and cnt_out == 1 H, W = map(int, input().split()) a = [list(input()) for _ in range(H)] bl = True for r in range(H): for c in range(W): if a[r][c] == "#": if not chk(r, c): bl = False break else: continue break print("Possible" if bl else "Impossible")
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s490347854
Wrong Answer
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
# coding: utf-8 # Your code here! n, m = map(int, input().split()) s = [list(input()) for i in range(n)] ans = [] print("Possible") """ def dfs(x,y): for i in range(2): for j in range(2): if i==0 and j==0: continue else: nx=i+x ny=j+y if 0<=nx<n and 0<=ny<m and s[nx][ny]=='#': if [nx,ny] not in ans: ans.append([nx,ny]) dfs(nx,ny) dfs(0,0) cnt=0 for i in range(n): for j in range(m): if s[i][j]=='#': cnt+=1 if ans[len(ans)-1]==[n-1,m-1] and len(ans)==cnt-1: print('Possible') else: print('Impossible') #print(ans)"""
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s347452947
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
h,w=map(int,input().split()) c=0 for i in range(h): c+=input().count("#") print("Possible" if c=h+w-1 else "Impossible")
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s594736202
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
h,w=map(int,input().split()) num=0 s=[str(input()) for i in range(h):] for i in range(h): num+=s[i].count("#") if num>h+w-1: print("Impossible") exit() print("Possible")
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s688260057
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
a
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s078936053
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
h,w=map(int,input().split()) c=0 for i in range(h): c=input().count("#") print("Possible" if c=h+w-1: "Impossible")
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
If it is possible that Shik only uses right and down moves, print `Possible`. Otherwise, print `Impossible`. * * *
s185224804
Runtime Error
p03937
The input is given from Standard Input in the following format: H W a_{11}a_{12}...a_{1W} : a_{H1}a_{H2}...a_{HW}
n = int(input()) a = [i * 40000 for i in range(n)] b = [40000**2 - i for i in a] p = list(map(int, input().split())) for i in range(n): a[p[i]] += i b[p[i]] += i print(*a) print(*b)
Statement We have a grid of H rows and W columns. Initially, there is a stone in the top left cell. Shik is trying to move the stone to the bottom right cell. In each step, he can move the stone one cell to its left, up, right, or down (if such cell exists). It is possible that the stone visits a cell multiple times (including the bottom right and the top left cell). You are given a matrix of characters a_{ij} (1 \leq i \leq H, 1 \leq j \leq W). After Shik completes all moving actions, a_{ij} is `#` if the stone had ever located at the i-th row and the j-th column during the process of moving. Otherwise, a_{ij} is `.`. Please determine whether it is possible that Shik only uses right and down moves in all steps.
[{"input": "4 5\n ##...\n .##..\n ..##.\n ...##", "output": "Possible\n \n\nThe matrix can be generated by a 7-move sequence: right, down, right, down,\nright, down, and right.\n\n* * *"}, {"input": "5 3\n ###\n ..#\n ###\n #..\n ###", "output": "Impossible\n \n\n* * *"}, {"input": "4 5\n ##...\n .###.\n .###.\n ...##", "output": "Impossible"}]
Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer -1 if the described situation is impossible. * * *
s238953469
Runtime Error
p03464
Input is given from Standard Input in the following format: K A_1 A_2 ... A_K
# from collections import deque k = int(input()) a = list(map(int, input().split())) now = [2] if k == 1: print("2 3") if a[0] == 2 else print(-1) else: for i in reversed(range(1,k)): nxt = [] for j in range(len(now)): test = now[j] nxtd = a[i-1] if test % a[i] == 0: mod = test % nxtd if (nxtd-mod)%nxtd < a[i]: for k in range((nxtd-mod)%nxtd, a[i], nxtd): nxt.append(k+test) if not nxt: print(-1) exit() now = nxt ans = [] for i in now: test = i if test % a[0] == 0: ans.append(i) ans.append(i+a[0]-1) ans = sorted(ans) print("{} {}".format(ans[0], ans[-1])) resolve()
Statement An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round. In the end, after the K-th round, there are exactly two children left, and they are declared the winners. You have heard the values of A_1, A_2, ..., A_K. You don't know N, but you want to estimate it. Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.
[{"input": "4\n 3 4 3 2", "output": "6 8\n \n\nFor example, if the game starts with 6 children, then it proceeds as follows:\n\n * In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.\n * In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.\n * In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.\n * In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.\n\nThe last 2 children are declared the winners.\n\n* * *"}, {"input": "5\n 3 4 100 3 2", "output": "-1\n \n\nThis situation is impossible. In particular, if the game starts with less than\n100 children, everyone leaves after the third round.\n\n* * *"}, {"input": "10\n 2 2 2 2 2 2 2 2 2 2", "output": "2 3"}]
Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer -1 if the described situation is impossible. * * *
s344740945
Wrong Answer
p03464
Input is given from Standard Input in the following format: K A_1 A_2 ... A_K
print(-1)
Statement An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round. In the end, after the K-th round, there are exactly two children left, and they are declared the winners. You have heard the values of A_1, A_2, ..., A_K. You don't know N, but you want to estimate it. Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.
[{"input": "4\n 3 4 3 2", "output": "6 8\n \n\nFor example, if the game starts with 6 children, then it proceeds as follows:\n\n * In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.\n * In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.\n * In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.\n * In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.\n\nThe last 2 children are declared the winners.\n\n* * *"}, {"input": "5\n 3 4 100 3 2", "output": "-1\n \n\nThis situation is impossible. In particular, if the game starts with less than\n100 children, everyone leaves after the third round.\n\n* * *"}, {"input": "10\n 2 2 2 2 2 2 2 2 2 2", "output": "2 3"}]
Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer -1 if the described situation is impossible. * * *
s770755030
Runtime Error
p03464
Input is given from Standard Input in the following format: K A_1 A_2 ... A_K
K = int(input()) A = list(map(int,input().split())) if A[-1] != 2: print(-1) exit(0) minval = 2 maxval = 3 for i in range(K-1,-1,-1): if maxval < A[i] or (minval > A[i] and ((maxval - (maxval % A[i]) < minval)): print(-1) exit(0) if minval > A[i]: if minval % A[i] != 0: minval = minval + (A[i] - (minval % A[i])) maxval = (maxval - (maxval % A[i]) + A[i] - 1) else: maxval = A[i] + (A[i] - 1) minval = A[i] print(str(minval) + " " + str(maxval))
Statement An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round. In the end, after the K-th round, there are exactly two children left, and they are declared the winners. You have heard the values of A_1, A_2, ..., A_K. You don't know N, but you want to estimate it. Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.
[{"input": "4\n 3 4 3 2", "output": "6 8\n \n\nFor example, if the game starts with 6 children, then it proceeds as follows:\n\n * In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.\n * In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.\n * In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.\n * In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.\n\nThe last 2 children are declared the winners.\n\n* * *"}, {"input": "5\n 3 4 100 3 2", "output": "-1\n \n\nThis situation is impossible. In particular, if the game starts with less than\n100 children, everyone leaves after the third round.\n\n* * *"}, {"input": "10\n 2 2 2 2 2 2 2 2 2 2", "output": "2 3"}]
Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer -1 if the described situation is impossible. * * *
s341574599
Runtime Error
p03464
Input is given from Standard Input in the following format: K A_1 A_2 ... A_K
# 後ろから順に考える # 最後のA_Kは必ず2である必要がある # A_Kの前には2~3人である必要がある # ... K = int(input()) As = list(map(int, input().split())) As.reverse() fail = False if As[0] != 2: fail = True else: mn = 2 mx = 3 for a in As[1:]: # 今 [mn, mx] = [4, 13], a = 3だとする # a人組をつくったあとにありうる数は3の倍数なので、ここでは6, 9, 12のみありうる if mn % a != 0: mn = (mn // a) * a + a if mx % a != 0: mx = (mx // a) * a if mn > mx: fail = True break # mxを修正 mx = mx + (a - 1) if fail: print(-1) else:
Statement An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round. In the end, after the K-th round, there are exactly two children left, and they are declared the winners. You have heard the values of A_1, A_2, ..., A_K. You don't know N, but you want to estimate it. Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.
[{"input": "4\n 3 4 3 2", "output": "6 8\n \n\nFor example, if the game starts with 6 children, then it proceeds as follows:\n\n * In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.\n * In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.\n * In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.\n * In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.\n\nThe last 2 children are declared the winners.\n\n* * *"}, {"input": "5\n 3 4 100 3 2", "output": "-1\n \n\nThis situation is impossible. In particular, if the game starts with less than\n100 children, everyone leaves after the third round.\n\n* * *"}, {"input": "10\n 2 2 2 2 2 2 2 2 2 2", "output": "2 3"}]
Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer -1 if the described situation is impossible. * * *
s539574048
Accepted
p03464
Input is given from Standard Input in the following format: K A_1 A_2 ... A_K
_, a = open(0) l, r = -2, -3 for a in map(int, a.split()[::-1]): l, r = l // a * a, r // a * a print(-(l == r) or "%d %d" % (-l, ~r))
Statement An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round. In the end, after the K-th round, there are exactly two children left, and they are declared the winners. You have heard the values of A_1, A_2, ..., A_K. You don't know N, but you want to estimate it. Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.
[{"input": "4\n 3 4 3 2", "output": "6 8\n \n\nFor example, if the game starts with 6 children, then it proceeds as follows:\n\n * In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.\n * In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.\n * In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.\n * In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.\n\nThe last 2 children are declared the winners.\n\n* * *"}, {"input": "5\n 3 4 100 3 2", "output": "-1\n \n\nThis situation is impossible. In particular, if the game starts with less than\n100 children, everyone leaves after the third round.\n\n* * *"}, {"input": "10\n 2 2 2 2 2 2 2 2 2 2", "output": "2 3"}]
Print two integers representing the smallest and the largest possible value of N, respectively, or a single integer -1 if the described situation is impossible. * * *
s456142946
Runtime Error
p03464
Input is given from Standard Input in the following format: K A_1 A_2 ... A_K
def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n /= i table.append(i) i += 1 if n > 1: table.append(n) return table input() test = input().split(" ") test = list(map(int, test)) suma = 1 for i in test: suma *= i test1 = prime_decomposition(suma) test1 = list(set(test1)) minn = 1 for i in test1: minn *= i maxi = minn + test[0] - 1 temp = minn for i in test: temp = temp - (temp % i) if temp != 2: print(-1) else: print(str(minn) + " " + str(maxi))
Statement An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as many groups of A_i children as possible. One child may belong to at most one group. Those who are left without a group leave the game. The others proceed to the next round. Note that it's possible that nobody leaves the game in some round. In the end, after the K-th round, there are exactly two children left, and they are declared the winners. You have heard the values of A_1, A_2, ..., A_K. You don't know N, but you want to estimate it. Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.
[{"input": "4\n 3 4 3 2", "output": "6 8\n \n\nFor example, if the game starts with 6 children, then it proceeds as follows:\n\n * In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.\n * In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.\n * In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.\n * In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.\n\nThe last 2 children are declared the winners.\n\n* * *"}, {"input": "5\n 3 4 100 3 2", "output": "-1\n \n\nThis situation is impossible. In particular, if the game starts with less than\n100 children, everyone leaves after the third round.\n\n* * *"}, {"input": "10\n 2 2 2 2 2 2 2 2 2 2", "output": "2 3"}]
Print the score obtained by the optimal choice of A and B. * * *
s517199267
Runtime Error
p03034
Input is given from Standard Input in the following format: N s_0 s_1 ...... s_{N-1}
from operator import itemgetter N, Q = map(int, input().split(" ")) check_points = [list(map(int, input().split(" "))) for _ in range(N)] querys = sorted([int(input()) for i in range(Q)]) time = {} for q in querys: time[q] = 0 check_parsed = [] for s, f, x in sorted(check_points, key=itemgetter(2)): start, end = [max(0, s - x), max(0, f - x)] for q in querys: if q < start: pass elif start <= q < end: if time[q] == 0: time[q] = x + 1 else: pass else: break for q in querys: print(time[q] - 1)
Statement There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1. On the lotus at coordinate i, an integer s_i is written. You are standing on the lotus at coordinate 0. You will play a game that proceeds as follows: * 1. Choose positive integers A and B. Your score is initially 0. * 2. Let x be your current coordinate, and y = x+A. The lotus at coordinate x disappears, and you move to coordinate y. * If y = N-1, the game ends. * If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. * If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. * 3. Let x be your current coordinate, and y = x-B. The lotus at coordinate x disappears, and you move to coordinate y. * If y = N-1, the game ends. * If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. * If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. * 4. Go back to step 2. You want to end the game with as high a score as possible. What is the score obtained by the optimal choice of A and B?
[{"input": "5\n 0 2 5 1 0", "output": "3\n \n\nIf you choose A = 3 and B = 2, the game proceeds as follows:\n\n * Move to coordinate 0 + 3 = 3. Your score increases by s_3 = 1.\n * Move to coordinate 3 - 2 = 1. Your score increases by s_1 = 2.\n * Move to coordinate 1 + 3 = 4. The game ends with a score of 3.\n\nThere is no way to end the game with a score of 4 or higher, so the answer is\n3. Note that you cannot land the lotus at coordinate 2 without drowning later.\n\n* * *"}, {"input": "6\n 0 10 -7 -4 -13 0", "output": "0\n \n\nThe optimal strategy here is to land the final lotus immediately by choosing A\n= 5 (the value of B does not matter).\n\n* * *"}, {"input": "11\n 0 -4 0 -99 31 14 -15 -39 43 18 0", "output": "59"}]
Print the score obtained by the optimal choice of A and B. * * *
s339967635
Runtime Error
p03034
Input is given from Standard Input in the following format: N s_0 s_1 ...... s_{N-1}
from bisect import bisect_left N, Q = [int(c) for c in input().split()] M = [10**10] * Q STX = [] for n in range(N): s, t, x = [int(c) for c in input().split()] STX.append((s, t, x)) D = [int(input()) for q in range(Q)] for s, t, x in STX: d_l = bisect_left(D, s - x) d_r = bisect_left(D[d_l:], t - x) + d_l for d in range(d_l, d_r): M[d] = min(x, M[d]) for q in range(Q): m = -1 if M[q] == 10**10 else M[q] print(m)
Statement There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1. On the lotus at coordinate i, an integer s_i is written. You are standing on the lotus at coordinate 0. You will play a game that proceeds as follows: * 1. Choose positive integers A and B. Your score is initially 0. * 2. Let x be your current coordinate, and y = x+A. The lotus at coordinate x disappears, and you move to coordinate y. * If y = N-1, the game ends. * If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. * If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. * 3. Let x be your current coordinate, and y = x-B. The lotus at coordinate x disappears, and you move to coordinate y. * If y = N-1, the game ends. * If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. * If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. * 4. Go back to step 2. You want to end the game with as high a score as possible. What is the score obtained by the optimal choice of A and B?
[{"input": "5\n 0 2 5 1 0", "output": "3\n \n\nIf you choose A = 3 and B = 2, the game proceeds as follows:\n\n * Move to coordinate 0 + 3 = 3. Your score increases by s_3 = 1.\n * Move to coordinate 3 - 2 = 1. Your score increases by s_1 = 2.\n * Move to coordinate 1 + 3 = 4. The game ends with a score of 3.\n\nThere is no way to end the game with a score of 4 or higher, so the answer is\n3. Note that you cannot land the lotus at coordinate 2 without drowning later.\n\n* * *"}, {"input": "6\n 0 10 -7 -4 -13 0", "output": "0\n \n\nThe optimal strategy here is to land the final lotus immediately by choosing A\n= 5 (the value of B does not matter).\n\n* * *"}, {"input": "11\n 0 -4 0 -99 31 14 -15 -39 43 18 0", "output": "59"}]
Print the score obtained by the optimal choice of A and B. * * *
s253961278
Wrong Answer
p03034
Input is given from Standard Input in the following format: N s_0 s_1 ...... s_{N-1}
# -*- coding: utf-8 -*- import sys sys.setrecursionlimit(10**9) INF = 10**18 MOD = 10**9 + 7 input = lambda: sys.stdin.readline().rstrip() YesNo = lambda b: bool([print("Yes")] if b else print("No")) YESNO = lambda b: bool([print("YES")] if b else print("NO")) int1 = lambda x: int(x) - 1 def main(): N = int(input()) s = tuple(map(int, input().split())) cost = [-INF] * (N + 1) for i in range(1, int((N - 1) ** 0.5) + 1): if (N - 1) % i == 0: cost[i] *= 2 cost[(N - 1) // i] *= 2 is_prime = [True] * (N + 1) is_prime[0] = False is_prime[1] = False for i in range(2, int(N**0.5) + 1): if not is_prime[i]: continue for j in range(i * 2, N + 1, i): is_prime[j] = False primes = [i for i in range(N + 1) if is_prime[i]] def get_divprime(n): divprime = [] for x in primes: if n % x == 0: divprime.append(x) while n % x == 0: n //= x if n == 1: break return divprime ans = 0 for x in range(N - 2, 1, -1): if cost[x] == -INF * 2: continue if x > N // 2: tmp = 0 for i in range(x, N - 1, x): tmp += s[i] + s[N - 1 - i] cost[x] = tmp ans = max(ans, tmp) if (N - 1) % x == 1: continue elif cost[x] == -INF: if (N - 1) % x > 1: tmp = 0 for i in range(x, N - 1, x): tmp += s[i] + s[N - 1 - i] cost[x] = tmp ans = max(ans, tmp) else: tmp = 0 for i in range(x, N - 2, x): tmp += s[i] + s[N - 1 - i] cost[x] = tmp ans = max(ans, tmp) else: tmp = cost[x] divprime = get_divprime(x) for y in divprime: if x == y or cost[x // y] == -INF * 2: continue tmptmp = tmp if (N - 1) % y > 1: for i in range(x // y, N - 1, x // y): if i % x != 0: tmptmp += s[i] + s[N - 1 - i] else: for i in range(x // y, N - 2, x // y): if i % x != 0: tmptmp += s[i] + s[N - 1 - i] cost[x // y] = tmptmp ans = max(ans, tmptmp) print(ans) if __name__ == "__main__": main()
Statement There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1. On the lotus at coordinate i, an integer s_i is written. You are standing on the lotus at coordinate 0. You will play a game that proceeds as follows: * 1. Choose positive integers A and B. Your score is initially 0. * 2. Let x be your current coordinate, and y = x+A. The lotus at coordinate x disappears, and you move to coordinate y. * If y = N-1, the game ends. * If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. * If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. * 3. Let x be your current coordinate, and y = x-B. The lotus at coordinate x disappears, and you move to coordinate y. * If y = N-1, the game ends. * If y \neq N-1 and there is a lotus floating at coordinate y, your score increases by s_y. * If y \neq N-1 and there is no lotus floating at coordinate y, you drown. Your score decreases by 10^{100} points, and the game ends. * 4. Go back to step 2. You want to end the game with as high a score as possible. What is the score obtained by the optimal choice of A and B?
[{"input": "5\n 0 2 5 1 0", "output": "3\n \n\nIf you choose A = 3 and B = 2, the game proceeds as follows:\n\n * Move to coordinate 0 + 3 = 3. Your score increases by s_3 = 1.\n * Move to coordinate 3 - 2 = 1. Your score increases by s_1 = 2.\n * Move to coordinate 1 + 3 = 4. The game ends with a score of 3.\n\nThere is no way to end the game with a score of 4 or higher, so the answer is\n3. Note that you cannot land the lotus at coordinate 2 without drowning later.\n\n* * *"}, {"input": "6\n 0 10 -7 -4 -13 0", "output": "0\n \n\nThe optimal strategy here is to land the final lotus immediately by choosing A\n= 5 (the value of B does not matter).\n\n* * *"}, {"input": "11\n 0 -4 0 -99 31 14 -15 -39 43 18 0", "output": "59"}]
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}. * * *
s919071424
Accepted
p03043
Input is given from Standard Input in the following format: N K
# for #!/usr/bin/env python import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion class union_find: def __init__(self, n): self.n = n self.rank = [0] * n self.parent = [int(j) for j in range(n)] def union(self, i, j): i = self.find(i) j = self.find(j) if self.rank[i] == self.rank[j]: self.parent[i] = j self.rank[j] += 1 elif self.rank[i] > self.rank[j]: self.parent[j] = i else: self.parent[i] = j def find(self, i): temp = i if self.parent[temp] != temp: self.parent[temp] = self.find(self.parent[temp]) return self.parent[temp] from math import log2, ceil def main(): # Enter your code here. Read input from STDIN. Print output to STDOUT n, k = [int(j) for j in input().split()] a = max(n - k + 1, 0) for x in range(1, min(k, n + 1)): tmp = (1 / 2) ** ceil(log2(k / x)) # print(tmp,x,ceil(log2(k/x))) a += tmp print(a / n) # if # s[k-1] = s[k-1].lower() # print("".join(s)) # ls[i+1]= # base = f # print() # l = [int(j) for j in input().split()] if __name__ == "__main__": main()
Statement Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: 1. Throw the die. The current score is the result of the die. 2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up. 3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0. You are given N and K. Find the probability that Snuke wins the game.
[{"input": "3 10", "output": "0.145833333333\n \n\n * If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n * If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n * If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} +\n\\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\n* * *"}, {"input": "100000 5", "output": "0.999973749998"}]
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}. * * *
s191983322
Runtime Error
p03043
Input is given from Standard Input in the following format: N K
N, K = map(int, input().split()) kaizyo = (K - 1) // 2 print(kaizyo) all_sum = 0 for n in range(0, N): all_sum = all_sum + 1 / N * ((1 / 2) ** (kaizyo - n)) print("-" * 20) print(1 / N) print((1 / 2) ** (kaizyo - n)) print(1 / N * (1 / 2) ** (kaizyo - n)) print(all_sum)
Statement Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: 1. Throw the die. The current score is the result of the die. 2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up. 3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0. You are given N and K. Find the probability that Snuke wins the game.
[{"input": "3 10", "output": "0.145833333333\n \n\n * If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n * If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n * If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} +\n\\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\n* * *"}, {"input": "100000 5", "output": "0.999973749998"}]
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}. * * *
s574868400
Runtime Error
p03043
Input is given from Standard Input in the following format: N K
S = input() sf = int(S[:2]) sb = int(S[3:]) if 1 <= sf and sf <= 12: if 1 <= sb and sb <= 12: print("AMBIGUOUS") else: print("MMYY") else: if 1 <= sb and sb <= 12: print("YYMM") else: print("NA")
Statement Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: 1. Throw the die. The current score is the result of the die. 2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up. 3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0. You are given N and K. Find the probability that Snuke wins the game.
[{"input": "3 10", "output": "0.145833333333\n \n\n * If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n * If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n * If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} +\n\\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\n* * *"}, {"input": "100000 5", "output": "0.999973749998"}]
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}. * * *
s610515842
Wrong Answer
p03043
Input is given from Standard Input in the following format: N K
N, K = map(int, input().split()) times = 0 total = 1 while total < K: total *= 2 times += 1 bo = N * (2**times) # num = 2**(times-1)-1 num = 0 num2 = 1 for i in range(times - 1): num += num2 num2 *= 2 # print(times) # print(num) # print(bo) print(num / bo)
Statement Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: 1. Throw the die. The current score is the result of the die. 2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up. 3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0. You are given N and K. Find the probability that Snuke wins the game.
[{"input": "3 10", "output": "0.145833333333\n \n\n * If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n * If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n * If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} +\n\\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\n* * *"}, {"input": "100000 5", "output": "0.999973749998"}]
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}. * * *
s574238961
Runtime Error
p03043
Input is given from Standard Input in the following format: N K
def d_even_relation_bfs(): from collections import deque N = int(input()) Edges = [[int(i) - 1 for i in input().split()] for j in range(N - 1)] # 0-indexed graph = [[] for _ in range(N)] for u, v, w in Edges: graph[u].append((v, w)) graph[v].append((u, w)) distance_from_root = [0] * N # 根は頂点 0 とする queue = deque([(-1, 0, 0)]) # 親と現在の頂点番号,根から親までの距離 while queue: parent, current, distance = queue.pop() distance_from_root[current] = distance for next_vertex, dist in graph[current]: if parent != next_vertex: # 木を「逆戻り」しない頂点だけ調べる queue.appendleft((current, next_vertex, distance + dist)) ans = (1 if d % 2 == 0 else 0 for d in distance_from_root) return " ".join(map(str, ans)) print(d_even_relation_bfs())
Statement Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: 1. Throw the die. The current score is the result of the die. 2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up. 3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0. You are given N and K. Find the probability that Snuke wins the game.
[{"input": "3 10", "output": "0.145833333333\n \n\n * If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n * If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n * If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} +\n\\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\n* * *"}, {"input": "100000 5", "output": "0.999973749998"}]
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}. * * *
s527010451
Wrong Answer
p03043
Input is given from Standard Input in the following format: N K
n, k = map(int, input().split()) a = n n0 = n i = 0 sum = 0 power_list = [0] * 24 if n > k: power_list[0] = n - k + 1 n = k - 1 a = k i = 1 a = k while a != 1: if a % 2 == 0 and a // 2 > n: a = a // 2 k = a i += 1 elif a % 2 == 0 and a // 2 <= n: power_list[i] = n - a // 2 + 1 n = a // 2 - 1 a = a // 2 i += 1 else: a += 1 for i in range(24): sum += (1 / 2) ** i * power_list[i] # print(power_list) print(sum / n0)
Statement Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: 1. Throw the die. The current score is the result of the die. 2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up. 3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0. You are given N and K. Find the probability that Snuke wins the game.
[{"input": "3 10", "output": "0.145833333333\n \n\n * If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n * If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n * If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} +\n\\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\n* * *"}, {"input": "100000 5", "output": "0.999973749998"}]
Print the probability that Snuke wins the game. The output is considered correct when the absolute or relative error is at most 10^{-9}. * * *
s852585390
Wrong Answer
p03043
Input is given from Standard Input in the following format: N K
def li(): return list(map(int, input().split())) if __name__ == "__main__": [n, k] = li() # 最初の目がk以上で勝つ確率 win1 = max(0, (n - k + 1)) # print(win1) # コインを投げる最大回数 coin_max_num = len(bin(k)) - 2 win_list = [] candidate_list = [] for coin in range(1, coin_max_num + 1): upper = min(n, (k + 2**coin - 1) // 2**coin) # print(upper) candidate = max(upper + 1 - (k + 2**coin - 1) // 2**coin, 0) candidate_list.append(candidate) # print(candidate) # print() win_list.append(max(0, candidate * 0.5**coin * candidate * 10**7)) # print(win_list) print((win1 * 10**7 + sum(win_list)) / (n * 10**7)) # upper = min(n, k) # win_list.append(max(0, (upper - (k + 2**1-1) // 2) / n) * 0.5 ** 1) # upper = min(n, (k + 1) // 2) # win_list.append(max(0, (upper - (k+2**2-1) // 2**2) / n) * 0.5 ** 2)
Statement Snuke has a fair N-sided die that shows the integers from 1 to N with equal probability and a fair coin. He will play the following game with them: 1. Throw the die. The current score is the result of the die. 2. As long as the score is between 1 and K-1 (inclusive), keep flipping the coin. The score is doubled each time the coin lands heads up, and the score becomes 0 if the coin lands tails up. 3. The game ends when the score becomes 0 or becomes K or above. Snuke wins if the score is K or above, and loses if the score is 0. You are given N and K. Find the probability that Snuke wins the game.
[{"input": "3 10", "output": "0.145833333333\n \n\n * If the die shows 1, Snuke needs to get four consecutive heads from four coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^4 = \\frac{1}{48}.\n * If the die shows 2, Snuke needs to get three consecutive heads from three coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^3 = \\frac{1}{24}.\n * If the die shows 3, Snuke needs to get two consecutive heads from two coin flips to obtain a score of 10 or above. The probability of this happening is \\frac{1}{3} \\times (\\frac{1}{2})^2 = \\frac{1}{12}.\n\nThus, the probability that Snuke wins is \\frac{1}{48} + \\frac{1}{24} +\n\\frac{1}{12} = \\frac{7}{48} \\simeq 0.1458333333.\n\n* * *"}, {"input": "100000 5", "output": "0.999973749998"}]
* In the first line, print the maximum possible value of the final element in the sequence. * In the second line, print the number of operations that you perform. * In the (2+i)-th line, if the element chosen in the i-th operation is the x-th element from the left in the sequence at that moment, print x. * If there are multiple ways to achieve the maximum value of the final element, any of them may be printed. * * *
s573089124
Accepted
p03413
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): N = I() A = LI() ans = -inf S = [0] * (N + 1) fr = [-1] * N best = -1 for i, a in enumerate(A): S[i] = a for j in range(i): if (i - j) % 2 == 0: if S[j] + a > S[i]: fr[i] = j S[i] = S[j] + a if S[i] > ans: ans = S[i] best = i # print(best) V = [] for i in range(best + 1, N)[::-1]: V.append(i + 1) i = best while fr[i] >= 0: f = fr[i] # print(i,f) while f < i: V.append(1 + (i + f) // 2) i -= 2 for _ in range(i): V.append(1) print(ans) print(len(V)) for v in V: print(v) return def examF(): ans = 0 print(ans) return from decimal import getcontext, Decimal as dec import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def I(): return int(input()) def LI(): return list(map(int, sys.stdin.readline().split())) def DI(): return dec(input()) def LDI(): return list(map(dec, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = dec("0.000000000001") alphabet = [chr(ord("a") + i) for i in range(26)] alphabet_convert = {chr(ord("a") + i): i for i in range(26)} getcontext().prec = 28 sys.setrecursionlimit(10**7) if __name__ == "__main__": examE() """ 142 12 9 1445 0 1 asd dfg hj o o aidn """
Statement You have an integer sequence of length N: a_1, a_2, ..., a_N. You repeatedly perform the following operation until the length of the sequence becomes 1: * First, choose an element of the sequence. * If that element is at either end of the sequence, delete the element. * If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements. You would like to maximize the final element that remains in the sequence. Find the maximum possible value of the final element, and the way to achieve it.
[{"input": "5\n 1 4 3 7 5", "output": "11\n 3\n 1\n 4\n 2\n \n\nThe sequence would change as follows:\n\n * After the first operation: 4, 3, 7, 5\n * After the second operation: 4, 3, 7\n * After the third operation: 11(4+7)\n\n* * *"}, {"input": "4\n 100 100 -1 100", "output": "200\n 2\n 3\n 1\n \n\n * After the first operation: 100, 200(100+100)\n * After the second operation: 200\n\n* * *"}, {"input": "6\n -1 -2 -3 1 2 3", "output": "4\n 3\n 2\n 1\n 2\n \n\n * After the first operation: -4, 1, 2, 3\n * After the second operation: 1, 2, 3\n * After the third operation: 4\n\n* * *"}, {"input": "9\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n 4\n 2\n 2\n 2\n 2"}]
* In the first line, print the maximum possible value of the final element in the sequence. * In the second line, print the number of operations that you perform. * In the (2+i)-th line, if the element chosen in the i-th operation is the x-th element from the left in the sequence at that moment, print x. * If there are multiple ways to achieve the maximum value of the final element, any of them may be printed. * * *
s518741195
Runtime Error
p03413
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
#include<bits/stdc++.h> using namespace std; typedef long long ll; signed main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<ll> v; for(int i=0;i<n;i++){ int a; cin>>a; v.push_back(a); } ll ans=-1e18; vector<ll> out; while(v.size()!=1){ vector<ll> em; ll mx=max(v[0],v[v.size()-1]); ll sum=-1e18; ll p=-1; for(int i=1;i<v.size()-1;i++){ ll t=v[i-1]+v[i+1]; mx=max(mx,v[i]); if(t>sum && t>v[i] && t>v[i+1] && t>v[i-1]){ sum=t; p=i; } } if(p==-1){ if(mx==v[0]){ out.push_back(v.size()); for(int i=0;i<v.size()-1;i++){ em.push_back(v[i]); } } else { out.push_back(1); for(int i=1;i<v.size();i++){ em.push_back(v[i]); } } } else { for(int i=0;i<v.size();i++){ if(i==p-1) continue; if(i==p){ out.push_back(i+1); em.push_back(v[i-1]+v[i+1]); continue; } if(i==p+1) continue; em.push_back(v[i]); } } v=em; //cerr<<v.size()<<endl; if(v.size()==1){ ans=v[0]; cout<<ans<<"\n"; cout<<out.size()<<"\n"; for(auto i:out){ cout<<i<<"\n"; } return 0; } } }
Statement You have an integer sequence of length N: a_1, a_2, ..., a_N. You repeatedly perform the following operation until the length of the sequence becomes 1: * First, choose an element of the sequence. * If that element is at either end of the sequence, delete the element. * If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements. You would like to maximize the final element that remains in the sequence. Find the maximum possible value of the final element, and the way to achieve it.
[{"input": "5\n 1 4 3 7 5", "output": "11\n 3\n 1\n 4\n 2\n \n\nThe sequence would change as follows:\n\n * After the first operation: 4, 3, 7, 5\n * After the second operation: 4, 3, 7\n * After the third operation: 11(4+7)\n\n* * *"}, {"input": "4\n 100 100 -1 100", "output": "200\n 2\n 3\n 1\n \n\n * After the first operation: 100, 200(100+100)\n * After the second operation: 200\n\n* * *"}, {"input": "6\n -1 -2 -3 1 2 3", "output": "4\n 3\n 2\n 1\n 2\n \n\n * After the first operation: -4, 1, 2, 3\n * After the second operation: 1, 2, 3\n * After the third operation: 4\n\n* * *"}, {"input": "9\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n 4\n 2\n 2\n 2\n 2"}]
* In the first line, print the maximum possible value of the final element in the sequence. * In the second line, print the number of operations that you perform. * In the (2+i)-th line, if the element chosen in the i-th operation is the x-th element from the left in the sequence at that moment, print x. * If there are multiple ways to achieve the maximum value of the final element, any of them may be printed. * * *
s628006219
Wrong Answer
p03413
Input is given from Standard Input in the following format: N a_1 a_2 ... a_N
n = int(input()) a = list(map(int, input().split())) ans1 = sum([a[i] for i in range(0, n, 2) if a[i] > 0]) ans2 = sum([a[i] for i in range(1, n, 2) if a[i] > 0]) if max(ans1, ans2) == 0: print(0) print(n) for _ in range(n): print(1) elif ans1 >= ans2: print(ans1) op = [] left = 0 while a[left] <= 0: left += 2 right = True in_seg = False for i in range(n - 1, -1, -1): if right: if i % 2 == 1 or a[i] <= 0: op.append(i + 1) else: right = False elif i < left: op += [1] * (i + 1) break else: if in_seg == False and i % 2 == 1: in_seg = True seg_right = i elif i % 2 == 0 and a[i] > 0: in_seg = False op += list(range((i + seg_right + 3) // 2, i + 1, -1)) print(len(op)) print(*op, sep="\n") else: print(ans2) op = [] left = 1 while a[left] <= 0: left += 2 right = True in_seg = False for i in range(n - 1, -1, -1): if right: if i % 2 == 0 or a[i] <= 0: op.append(i + 1) else: right = False elif i < left: op += [1] * (i + 1) break else: if in_seg == False and i % 2 == 0: in_seg = True seg_right = i elif i % 2 == 1 and a[i] > 0: in_seg = False op += list(range((i + seg_right + 3) // 2, i + 1, -1)) print(len(op)) print(*op, sep="\n")
Statement You have an integer sequence of length N: a_1, a_2, ..., a_N. You repeatedly perform the following operation until the length of the sequence becomes 1: * First, choose an element of the sequence. * If that element is at either end of the sequence, delete the element. * If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements. You would like to maximize the final element that remains in the sequence. Find the maximum possible value of the final element, and the way to achieve it.
[{"input": "5\n 1 4 3 7 5", "output": "11\n 3\n 1\n 4\n 2\n \n\nThe sequence would change as follows:\n\n * After the first operation: 4, 3, 7, 5\n * After the second operation: 4, 3, 7\n * After the third operation: 11(4+7)\n\n* * *"}, {"input": "4\n 100 100 -1 100", "output": "200\n 2\n 3\n 1\n \n\n * After the first operation: 100, 200(100+100)\n * After the second operation: 200\n\n* * *"}, {"input": "6\n -1 -2 -3 1 2 3", "output": "4\n 3\n 2\n 1\n 2\n \n\n * After the first operation: -4, 1, 2, 3\n * After the second operation: 1, 2, 3\n * After the third operation: 4\n\n* * *"}, {"input": "9\n 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "5000000000\n 4\n 2\n 2\n 2\n 2"}]
Print the minimum possible unbalancedness of S'. * * *
s234297589
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
def solve(s): n = len(s) # count 0 # ? -> 1 res_0 = 0 cnt_00 = 0 cnt_01 = 0 # count 1 # ? -> 0 res_1 = 0 cnt_10 = 0 cnt_11 = 0 for i in range(n): if s[i] == "0": cnt_00 += 1 cnt_10 += 1 elif s[i] == "1": cnt_01 += 1 cnt_11 += 1 else: cnt_01 += 1 cnt_10 += 1 res_0 = max(res_0, cnt_00 - cnt_01) res_1 = max(res_1, cnt_11 - cnt_10) if cnt_00 < cnt_01: cnt_00 = 0 cnt_01 = 0 if cnt_11 < cnt_10: cnt_10 = 0 cnt_11 = 0 # print(res_0, res_1) if max(res_0, res_1) > 1: if res_0 != res_1: return max(res_0, res_1) else: # check # count 0 # ? -> 1 cnt_00 = 0 cnt_01 = 0 left_0 = 0 # count 1 # ? -> 0 cnt_10 = 0 cnt_11 = 0 left_1 = 0 max_0_flg = [0] * n max_1_flg = [0] * n for i in range(n): if s[i] == "0": cnt_00 += 1 cnt_10 += 1 elif s[i] == "1": cnt_01 += 1 cnt_11 += 1 else: cnt_01 += 1 cnt_10 += 1 # print(cnt_00 - cnt_01, left_0, cnt_11 - cnt_10, left_1) if cnt_00 - cnt_01 == res_0: for j in range(left_0, i + 1): max_0_flg[j] = 1 left_0 = i + 1 if cnt_11 - cnt_10 == res_1: for j in range(left_1, i + 1): max_1_flg[j] = 1 left_1 = i + 1 if cnt_00 < cnt_01: cnt_00 = 0 cnt_01 = 0 left_0 = i + 1 if cnt_11 < cnt_10: cnt_10 = 0 cnt_11 = 0 left_1 = i + 1 # print(max_0_flg, max_1_flg) # check flag_0 = False flag_1 = False count_q = 0 flag_tie = False for i in range(n): if max_0_flg[i] == 1: flag_0 = True if flag_1 and count_q % 2 == 1: flag_tie = True flag_1 = False count_q = 0 elif max_1_flg[i] == 1: flag_1 = True if flag_0 and count_q % 2 == 1: flag_tie = True flag_0 = False count_q = 0 elif s[i] == "?": count_q += 1 else: flag_0 = False flag_1 = False count_q = 0 # tie break if flag_tie: return res_0 + 1 else: return res_0 else: # 0 happens flag_01 = False flag_02 = False # 1 happens flag_11 = False flag_12 = False for i in range(n): if s[i] == "0": if i % 2 == 0: flag_02 = True else: flag_01 = True elif s[i] == "1": if i % 2 == 0: flag_12 = True else: flag_11 = True flag_one = True if flag_01 and flag_02: flag_one = False if flag_11 and flag_12: flag_one = False if flag_one: # 1 is possible return 1 else: return 2 def main(): s = input() res = solve(s) print(res) def test(): assert solve("0??") == 1 assert solve("0??0") == 2 assert solve("??00????0??0????0?0??00??1???11?1?1???1?11?111???1") == 4 assert solve("11?00") == 3 if __name__ == "__main__": test() main()
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s547325232
Accepted
p02652
Input is given from Standard Input in the following format: S
S = input() max0 = 0 max1 = 0 amax0 = [] amax1 = [] mi0 = 0 mi1 = 0 h0 = 0 h1 = 0 for i, c in enumerate(S): if c == "1": h1 += 1 if h1 - mi1 > max1: max1 = h1 - mi1 amax1 = [i] elif h1 - mi1 == max1: amax1.append(i) h0 -= 1 if h0 < mi0: mi0 = h0 elif c == "0": h1 -= 1 if h1 < mi1: mi1 = h1 h0 += 1 if h0 - mi0 > max0: max0 = h0 - mi0 amax0 = [i] elif h0 - mi0 == max0: amax0.append(i) else: h1 -= 1 if h1 < mi1: mi1 = h1 h0 -= 1 if h0 < mi0: mi0 = h0 if max0 < max1: if len(set([i % 2 for i in amax1])) == 1: print(max1) else: print(max1 + 1) elif max0 > max1: if len(set([i % 2 for i in amax0])) == 1: print(max0) else: print(max0 + 1) else: if len(set([i % 2 for i in amax1] + [(max0 + i) % 2 for i in amax0])) == 1: print(max0) else: print(max0 + 1)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s640934553
Accepted
p02652
Input is given from Standard Input in the following format: S
def main(): S = input() size = [[[[0, 0]], []], [[], []]] length = 0 for s in S: size2 = [[[], []], [[], []], [[], []]] if s != "0": for i in range(2): for j in range(2): if size[i][j]: for x, y in size[i][j]: if y == length + i: size2[i + 1][j ^ 1].append([y + 1, y + 1]) if x != y: size2[i][j ^ 1].append([x + 1, y - 1]) else: size2[i][j ^ 1].append([x + 1, y + 1]) if s != "1": for i in range(2): for j in range(2): if size[i][j]: for x, y in size[i][j]: if x == 0: size2[i + 1][j].append([0, 0]) if x != y: size2[i][j ^ 1].append([x + 1, y - 1]) else: size2[i][j ^ 1].append([x - 1, y - 1]) if len(size2[0][0] + size2[0][1]) == 0: size2 = size2[1:] length += 1 else: size2.pop() for i in range(2): for j in range(2): size2[i][j] = sorted(size2[i][j]) size = [[[], []], [[], []]] for i in range(2): for j in range(2): if len(size2[i][j]) == 0: continue size[i][j] = [size2[i][j][0]] for x, y in size2[i][j][1:]: size[i][j][-1][1] = max(y, size[i][j][-1][1]) print(length) main()
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s189337298
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) # 二分探索、左右からの貪欲法、?をスキップした状態で1の連続数と0の連続数 S = list(sr()) answer = 0 def solve(S): global answer one_seq = 0 one_max = 0 one_start = set() zero_seq = 0 zero_max = 0 zero_start = set() cur = 0 for i, s in enumerate(S): if s == "1": one_seq += 1 zero_seq -= 0 zero_seq = max(0, zero_seq) cur += 1 elif s == "0": zero_seq += 1 one_seq -= 0 one_seq = max(0, one_seq) cur -= 1 elif s == "?": one_seq -= 1 zero_seq -= 1 one_seq = max(0, one_seq) zero_seq = max(0, zero_seq) # ここでは保留 if one_seq > 0 and one_seq == one_max: one_start.add(i - one_seq + 1) elif one_seq > 0 and one_seq > one_max: one_start = {i - one_seq + 1} one_max = one_seq if zero_seq > 0 and zero_seq == zero_max: zero_start.add(i - zero_seq + 1) elif zero_seq > 0 and zero_seq > zero_max: zero_start = {i - zero_seq + 1} zero_max = zero_seq answer = max(one_max, zero_max) one_seq = 0 zero_seq = 0 cur = 0 for i, s in enumerate(S): if s == "1": one_seq += 1 zero_seq -= 0 zero_seq = max(0, zero_seq) cur += 1 elif s == "0": zero_seq += 1 one_seq -= 0 one_seq = max(0, one_seq) cur -= 1 elif s == "?": if zero_seq == answer and i + 1 in one_start: zero_max += 1 answer += 1 return None elif one_seq == answer and i + 1 in zero_start: one_max += 1 answer += 1 return None if i + 1 in one_start: S[i] = "0" cur -= 1 elif i + 1 in zero_start: S[i] = "1" cur += 1 else: one_seq -= 1 zero_seq -= 1 one_seq = max(0, one_seq) zero_seq = max(0, zero_seq) # ここでは保留 return S for i in range(10): ret = solve(S) if ret: S = ret solve(S[::-1]) print(answer)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s121767738
Runtime Error
p02652
Input is given from Standard Input in the following format: S
import itertools import copy syokiti = list(input()) last = [] for i in itertools.product("10", repeat=syokiti.count("?")): yousuu = 0 a = copy.deepcopy(syokiti) for kai, j in enumerate(a): if j == "?": a[kai] = i[yousuu] yousuu += 1 ls = [j + 1 for j in range(len(a))] handan = [] for j in itertools.combinations(ls, 2): j = list(j) renzoku = 0 saisyo = a[0] saikouti = 0 for k in range(j[0] - 1, j[1]): if a[k] == saisyo: renzoku += 1 else: saisyo = a[k] renzoku = 1 if saikouti < renzoku: saikouti = renzoku handan.append(saikouti) last.append(max(handan)) print(min(last))
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s570521617
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
input = input() min = 10000000000000000 nums = [""] for c in input: newnums = [] if c == "0" or c == "1": for i in range(len(nums)): newnums.append(nums[i] + c) else: for i in range(len(nums)): newnums.append(nums[i] + "0") newnums.append(nums[i] + "1") nums = newnums for num in nums: gap = 0 max = 0 min = 0 for c in num: if c == "0": gap += 1 max = gap if gap > max else max elif c == "1": gap -= 1 min = gap if gap < min else min x = max - min min = x if x < min else min min = 0 - min if min < 0 else min print(min)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s736019971
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
def solve(S): if S[0] == "?": for i in range(len(S)): if S[i] == "0": if i % 2 == 0: S[0] = "0" else: S[0] = "1" break elif S[i] == "1": if i % 2 == 0: S[0] = "1" else: S[0] = "0" break if S[0] == "?": return 1 sum0 = 0 sum1 = 0 un = 1 val = -1 for i in range(len(S)): if S[i] == "0": sum0 += 1 val = -1 elif S[i] == "1": sum1 += 1 val = -1 else: if sum0 > sum1: sum1 += 1 elif sum1 > sum0: sum0 += 1 else: if val == -1: for j in range(i, len(S)): if S[j] == "0": if (j - i) % 2 == 0: val = 0 else: val = 1 break elif S[j] == "1": if (j - i) % 2 == 0: val = 1 else: val = 0 break if val == 1: sum1 += 1 elif val == 0: sum0 += 1 else: return un un = max(un, abs(sum0 - sum1)) return un S = list(input()) print(min(solve(S), solve(S[::-1])))
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s608189177
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
s=input() qus=s.count("?") zeros=s.count("0") ones=s.count("1") result=abs(zeros-ones) if qus%2 ==1: result+= -1 max1=1 max2=0 last="" for subs in s: if subs == "?": max1=1 last="" continue if last == subs: max1+=1 else: max1=1 last=subs max2=max(max1,max2) result=max(result,max2) print(result)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s224533486
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
S = list(input()) def long_repeat(line): max = 0 cnt = 1 for i in range(len(line) - 1): if cnt > 1: cnt -= 1 continue for j in range(i + 1, len(line)): if line[i] == line[j]: cnt += 1 else: break if max < cnt: max = cnt return max s = long_repeat(S) if len(S) <= s + 1: print(s - 1) else: print(s)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s654264243
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
a = input() X = a.count("0") Y = a.count("1") Z = a.count("?") % 2 q = abs(X - Y) - Z print(q)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s642370410
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
S = input() print(1)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s357590262
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
s = list(input()) zero = s.count("0") iti = s.count("1") hatena = s.count("?") if hatena == 0: print(abs(zero - iti)) elif zero - iti == 0: print(1) elif zero + iti <= hatena: print(abs(zero - iti)) elif len(s) % 2 == 0: print(abs(zero - iti) + 1) elif (len(s) % 2) != 0: print(abs(zero - iti) - 1)
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print the minimum possible unbalancedness of S'. * * *
s986893797
Wrong Answer
p02652
Input is given from Standard Input in the following format: S
s = list(input()) zero = s.count("0") iti = s.count("1") hatena = s.count("?") print(abs(zero - iti))
Statement Given is a string S, where each character is `0`, `1`, or `?`. Consider making a string S' by replacing each occurrence of `?` with `0` or `1` (we can choose the character for each `?` independently). Let us define the unbalancedness of S' as follows: * (The unbalancedness of S') = \max \\{ The absolute difference between the number of occurrences of `0` and `1` between the l-th and r-th character of S (inclusive) :\ 1 \leq l \leq r \leq |S|\\} Find the minimum possible unbalancedness of S'.
[{"input": "0??", "output": "1\n \n\nWe can make S'= `010` and achieve the minimum possible unbalancedness of 1.\n\n* * *"}, {"input": "0??0", "output": "2\n \n\n* * *"}, {"input": "??00????0??0????0?0??00??1???11?1?1???1?11?111???1", "output": "4"}]
Print an integer denoting the answer. * * *
s441944788
Wrong Answer
p03940
The input is given from Standard Input in the following format: N E T x_1 x_2 ... x_N
import sys def solve(n, e, t, xxx): if n == 1: return e + t ans = xxx[0] + (e - xxx[-1]) i = 0 while i < n: for j in range(i, n - 1): dx0 = xxx[j] - xxx[i] dx1 = xxx[j + 1] - xxx[i] stop = max(2 * dx0, t) + dx0 + xxx[j + 1] - xxx[j] + t through = max(2 * dx1, t) + dx1 if stop < through: ans += stop - t i = j + 1 break else: dx1 = xxx[n - 1] - xxx[i] ans += max(2 * dx1, t) + dx1 i = n return ans n, e, t, *xxx = map(int, sys.stdin.buffer.read().split()) print(solve(n, e, t, xxx))
Statement Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E. There are also N bears in the game. The i-th bear is located at x_i. The maximum moving speed of the player is 1 while the bears do not move at all. When the player gives a candy to a bear, it will provide a coin after T units of time. More specifically, if the i-th bear is given a candy at time t, it will put a coin at its position at time t+T. The purpose of this game is to give candies to all the bears, pick up all the coins, and go to the exit. Note that the player can only give a candy to a bear if the player is at the exact same position of the bear. Also, each bear will only produce a coin once. If the player visits the position of a coin after or at the exact same time that the coin is put down, the player can pick up the coin. Coins do not disappear until collected by the player. Shik is an expert of this game. He can give candies to bears and pick up coins instantly. You are given the configuration of the game. Please calculate the minimum time Shik needs to collect all the coins and go to the exit.
[{"input": "3 9 1\n 1 3 8", "output": "12\n \n\nThe optimal strategy is to wait for the coin after treating each bear. The\ntotal time spent on waiting is 3 and moving is 9. So the answer is 3 + 9 = 12.\n\n* * *"}, {"input": "3 9 3\n 1 3 8", "output": "16\n \n\n* * *"}, {"input": "2 1000000000 1000000000\n 1 999999999", "output": "2999999996"}]
Print an integer denoting the answer. * * *
s583981091
Wrong Answer
p03940
The input is given from Standard Input in the following format: N E T x_1 x_2 ... x_N
s = input().split() n, e, t = int(s[0]), int(s[1]), int(s[2]) s = input().split() if (int(s[n - 1]) - int(s[0])) + t > t * n: print(e + t * n) elif t > int(s[n - 1]) * 2: print(int(s[0]) + (int(s[n - 1]) - int(s[0])) + t + (e - int(s[0]))) else: print(int(s[0]) + (int(s[n - 1]) - int(s[0])) * 2 + (e - int(s[0])))
Statement Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E. There are also N bears in the game. The i-th bear is located at x_i. The maximum moving speed of the player is 1 while the bears do not move at all. When the player gives a candy to a bear, it will provide a coin after T units of time. More specifically, if the i-th bear is given a candy at time t, it will put a coin at its position at time t+T. The purpose of this game is to give candies to all the bears, pick up all the coins, and go to the exit. Note that the player can only give a candy to a bear if the player is at the exact same position of the bear. Also, each bear will only produce a coin once. If the player visits the position of a coin after or at the exact same time that the coin is put down, the player can pick up the coin. Coins do not disappear until collected by the player. Shik is an expert of this game. He can give candies to bears and pick up coins instantly. You are given the configuration of the game. Please calculate the minimum time Shik needs to collect all the coins and go to the exit.
[{"input": "3 9 1\n 1 3 8", "output": "12\n \n\nThe optimal strategy is to wait for the coin after treating each bear. The\ntotal time spent on waiting is 3 and moving is 9. So the answer is 3 + 9 = 12.\n\n* * *"}, {"input": "3 9 3\n 1 3 8", "output": "16\n \n\n* * *"}, {"input": "2 1000000000 1000000000\n 1 999999999", "output": "2999999996"}]
Print an integer denoting the answer. * * *
s425141963
Accepted
p03940
The input is given from Standard Input in the following format: N E T x_1 x_2 ... x_N
#####segfunc##### def segfunc(x, y): return min(x, y) ################# #####ide_ele##### ide_ele = float("inf") ################# class SegTree: """ init(init_val, ide_ele): 配列init_valで初期化 O(N) update(k, x): k番目の値をxに更新 O(logN) query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN) """ def __init__(self, n, segfunc, ide_ele): """ init_val: 配列の初期値 segfunc: 区間にしたい操作 ide_ele: 単位元 n: 要素数 num: n以上の最小の2のべき乗 tree: セグメント木(1-index) """ self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num # 配列の値を葉にセット # 構築していく def update(self, k, x): """ k番目の値をxに更新 k: index(0-index) x: update value """ k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): """ [l, r)のsegfuncしたものを得る l: index(0-index) r: index(0-index) """ res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res import bisect, random N, E, T = map(int, input().split()) x = list(map(int, input().split())) x = [0] + x X = [2 * x[i] for i in range(N + 1)] dp = [0 for i in range(N + 1)] dp[N] = abs(E - x[N]) seg1 = SegTree(N + 1, segfunc, ide_ele) seg3 = SegTree(N + 1, segfunc, ide_ele) seg1.update(N, E - x[N] + x[N]) seg3.update(N, E - x[N] + 3 * x[N]) for i in range(N - 1, -1, -1): id = bisect.bisect_right(X, T + 2 * x[i + 1]) test, test2 = 10**20, 10**20 if id > i + 1: # test1=min(dp[j]+x[j] for j in range(i+1,id))+T test1 = seg1.query(i + 1, id) + T if N + 1 > id: # test2=min(3*x[j]+dp[j] for j in range(id,N+1))-2*x[i+1] test2 = seg3.query(id, N + 1) - 2 * x[i + 1] dp[i] = min(test1, test2) - x[i] seg1.update(i, dp[i] + x[i]) seg3.update(i, dp[i] + 3 * x[i]) # dp[i]=min(max(T,2*x[j]-2*x[i+1])+dp[j]+x[j] for j in range(i+1,N+1))-x[i] print(dp[0])
Statement Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E. There are also N bears in the game. The i-th bear is located at x_i. The maximum moving speed of the player is 1 while the bears do not move at all. When the player gives a candy to a bear, it will provide a coin after T units of time. More specifically, if the i-th bear is given a candy at time t, it will put a coin at its position at time t+T. The purpose of this game is to give candies to all the bears, pick up all the coins, and go to the exit. Note that the player can only give a candy to a bear if the player is at the exact same position of the bear. Also, each bear will only produce a coin once. If the player visits the position of a coin after or at the exact same time that the coin is put down, the player can pick up the coin. Coins do not disappear until collected by the player. Shik is an expert of this game. He can give candies to bears and pick up coins instantly. You are given the configuration of the game. Please calculate the minimum time Shik needs to collect all the coins and go to the exit.
[{"input": "3 9 1\n 1 3 8", "output": "12\n \n\nThe optimal strategy is to wait for the coin after treating each bear. The\ntotal time spent on waiting is 3 and moving is 9. So the answer is 3 + 9 = 12.\n\n* * *"}, {"input": "3 9 3\n 1 3 8", "output": "16\n \n\n* * *"}, {"input": "2 1000000000 1000000000\n 1 999999999", "output": "2999999996"}]
Print an integer denoting the answer. * * *
s818836308
Wrong Answer
p03940
The input is given from Standard Input in the following format: N E T x_1 x_2 ... x_N
import sys readline = sys.stdin.readline class Segtree: def __init__(self, A, intv, initialize=True, segf=max): self.N = len(A) self.N0 = 2 ** (self.N - 1).bit_length() self.intv = intv self.segf = segf if initialize: self.data = [intv] * self.N0 + A + [intv] * (self.N0 - self.N) for i in range(self.N0 - 1, 0, -1): self.data[i] = self.segf(self.data[2 * i], self.data[2 * i + 1]) else: self.data = [intv] * (2 * self.N0) def update(self, k, x): k += self.N0 self.data[k] = x while k > 0: k = k >> 1 self.data[k] = self.segf(self.data[2 * k], self.data[2 * k + 1]) def query(self, l, r): L, R = l + self.N0, r + self.N0 s = self.intv while L < R: if R & 1: R -= 1 s = self.segf(s, self.data[R]) if L & 1: s = self.segf(s, self.data[L]) L += 1 L >>= 1 R >>= 1 return s def binsearch(self, l, r, check, reverse=False): L, R = l + self.N0, r + self.N0 SL, SR = [], [] while L < R: if R & 1: R -= 1 SR.append(R) if L & 1: SL.append(L) L += 1 L >>= 1 R >>= 1 if reverse: for idx in SR + SL[::-1]: if check(self.data[idx]): break else: return -1 while idx < self.N0: if check(self.data[2 * idx + 1]): idx = 2 * idx + 1 else: idx = 2 * idx return idx - self.N0 else: pre = self.data[l + self.N0] for idx in SL + SR[::-1]: if not check(self.segf(pre, self.data[idx])): pre = self.segf(pre, self.data[idx]) else: break else: return -1 while idx < self.N0: if check(self.segf(pre, self.data[2 * idx])): idx = 2 * idx else: pre = self.segf(pre, self.data[2 * idx]) idx = 2 * idx + 1 return idx - self.N0 INF = 10**9 + 7 N, E, T = map(int, readline().split()) X = list(map(int, readline().split())) X = [0] + [x - X[0] for x in X] + [INF] E -= X[0] dp = [0] * (N + 2) dpl = Segtree([0] * (N + 2), INF, initialize=False, segf=min) dpr = Segtree([0] * (N + 2), INF, initialize=False, segf=min) dpl.update(0, 0) dpr.update(0, 0) for i in range(1, N + 1): di = X[i] dn = X[i + 1] ok = i ng = -1 while abs(ok - ng) > 1: med = (ok + ng) // 2 if (X[i] - X[med]) * 2 <= T: ok = med else: ng = med left = ok - 1 resr = dpr.query(left, i) + T + di resl = dpl.query(0, left) + 3 * di dp[i] = min(resl, resr) dpl.update(i, dp[i] - di - 2 * dn) dpr.update(i, dp[i] - di) print(dp[N] + E - X[N])
Statement Imagine a game played on a line. Initially, the player is located at position 0 with N candies in his possession, and the exit is at position E. There are also N bears in the game. The i-th bear is located at x_i. The maximum moving speed of the player is 1 while the bears do not move at all. When the player gives a candy to a bear, it will provide a coin after T units of time. More specifically, if the i-th bear is given a candy at time t, it will put a coin at its position at time t+T. The purpose of this game is to give candies to all the bears, pick up all the coins, and go to the exit. Note that the player can only give a candy to a bear if the player is at the exact same position of the bear. Also, each bear will only produce a coin once. If the player visits the position of a coin after or at the exact same time that the coin is put down, the player can pick up the coin. Coins do not disappear until collected by the player. Shik is an expert of this game. He can give candies to bears and pick up coins instantly. You are given the configuration of the game. Please calculate the minimum time Shik needs to collect all the coins and go to the exit.
[{"input": "3 9 1\n 1 3 8", "output": "12\n \n\nThe optimal strategy is to wait for the coin after treating each bear. The\ntotal time spent on waiting is 3 and moving is 9. So the answer is 3 + 9 = 12.\n\n* * *"}, {"input": "3 9 3\n 1 3 8", "output": "16\n \n\n* * *"}, {"input": "2 1000000000 1000000000\n 1 999999999", "output": "2999999996"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s195327154
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
data = input() x = data.split(" ") tmp = x[2] x[2] = x[1] x[1] = x[0] x[0] = tmp print(x[0], x[1], x[2])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s455712574
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
x, y, z = list(map(str, input().split())) s = z + x + y print(s.split(" "))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s764593310
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
line = input().split(" ") X = line[2] Y = line[0] Z = line[1] output = X + " " + Y + " " + Z print(output)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s505041545
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
try: X_s, Y_s, Z_s = input().split(" ") X = int(X_s) Y = int(Y_s) Z = int(Z_s) if X >= 1 and X <= 100 and Y >= 1 and Y <= 100 and Z >= 1 and Z <= 100: A = X B = Y C = Z temp = B B = A A = temp temp = C C = A A = temp print(A, "", B, "", C) except Exception as e: print(e)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s450189130
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
def resolve(): import sys input = sys.stdin.readline k = int(input().rstrip()) if k <= 9: # print(k) sys.exit() def judge(number_list, index, total): if index == len(number_list) - 2: # 最後から2番目の桁 num = number_list[index] add_num = 2 if num in (0, 9) else 3 if (total + add_num) < k: total += add_num return total else: if num == 0: right_nums = [num, num + 1] elif num == 9: right_nums = [num - 1, num] else: right_nums = [num - 1, num, num + 1] number_list[-1] = right_nums[k - total - 1] # print("".join(number_list)) print(*number_list, sep="") sys.exit() else: # 最後から2番目の桁じゃない num = number_list[index] if num == 0: right_nums = [num, num + 1] elif num == 9: right_nums = [num - 1, num] else: right_nums = [num - 1, num, num + 1] for right_num in right_nums: number_list[index + 1] = right_num total = judge(number_list, index + 1, total) return total total = 9 num_list = [9] while True: num_list = [0 for _ in range(len(num_list) + 1)] for left in [1, 2, 3, 4, 5, 6, 7, 8, 9]: num_list[0] = left # print(num_list, 0, total) total = judge(num_list, 0, total) if __name__ == "__main__": resolve()
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s324707669
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
lun_luns = [1, 2, 3, 4, 5, 6, 7, 8, 9] k = int(input()) index = 0 while True: if len(lun_luns) >= k: break num = lun_luns.pop(index) lun_luns.insert(index, num) mod = num % 10 n = num * 10 if mod == 9: lun_luns.extend([n + mod - 1, n + mod]) else: lun_luns.extend([n + mod - 1, n + mod, n + mod + 1]) index += 1 print(lun_luns[k - 1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s910541142
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
list = list(map(int, input().split())) x = list[0] k = list[1] y = abs(x - k) while y >= k: y = abs(y - k) z = k - y if z >= y: print(y) else: print(z)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s320024729
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
S = input().split() for i in range(S): print(S[i + 1] + " ")
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s211814640
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
x = [int(i) for i in input().split(" ")] print(x[3], x[0], x[1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s897848125
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
X, Y, Z = input().split(" ") print([Z, X, Y].join(" "))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s947408165
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
import sys from io import StringIO import unittest def resolve(): # get input a, b, c = input().split() work = "" work = b b = a a = work work = c c = a a = work print(a + " " + b + " " + c) class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """1 2 3""" output = """3 1 2""" self.assertIO(input, output) def test_入力例_2(self): input = """100 100 100""" output = """100 100 100""" self.assertIO(input, output) def test_入力例_3(self): input = """41 59 31""" output = """31 41 59""" self.assertIO(input, output) if __name__ == "__main__": # unittest.main() resolve()
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s334702494
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
X, Y, Z = (int(X) for X in input().split()) Y, X = X, Y Z, X = X, Z print("{} {} {}".format(X, Y, Z))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s070130085
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
input_lists = list(input().split(" ")) result = [input_lists[-1]] result += input_lists[0:-1] result = " ".join(result) print(result)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s907118282
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
N = int(input()) import math a = 0 for i in range(1, int(math.sqrt(N - 1)) + 1): if (N - 1) % i == 0: a += 2 i += 1 else: i += 1 a -= 1 if int(math.sqrt(N - 1)) == math.sqrt(N - 1): a -= 1 for i in range(2, int(math.sqrt(N)) + 1): if N % i == 0: t = N while t % i == 0: t = t / i if t % i == 1: a += 1 i += 1 else: i += 1 a += 1 print(a)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s157952554
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
n = list(map(str, input().split())) print(n[2] + " " + n[0] + " " + n[1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s458629764
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
print("Yes")
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s106217823
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
n, x, y = input().split(" ") n, x, y = int(n), int(x), int(y) print(y, n, x)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s867796121
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
A = [int(b) for b in input().split()] B = A[:] A[0] = B[2] A[1] = B[0] A[2] = B[1] print(A[0], A[1], A[2])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s195126455
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
a = list(input()) r = [] r = a[4] + " " + a[0] + " " + a[2] print(r)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s186624265
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
tmp = list(map(int, input("input some numbers.").split())) print(tmp[2], tmp[0], tmp[1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s545267303
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
box = list(map(int, input().split())) box.reverse() print(" ".join(map(str, box)))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s046437145
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
lst = list(map(int, input().split())) a, b, c = lst[0], lst[1], lst[2] ans = [c, a, b] print(" ".join(map(str, ans)))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s118562829
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
# coding: utf-8 DATA = """ 5 5 10 ssdss """.split( "\n" ) def get_debug_line(): for i in DATA: yield i if 1: get_line = input else: get_line = get_debug_line().__next__ get_line() X, Y, Z = [int(i) for i in get_line().strip().split(" ")] print("{0} {1} {2}".format(Z, X, Y))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s578662236
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
inputline = list(map(lambda x: int(x), input().split(" "))) print(inputline[1], inputline[2], inputline[0])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s116135157
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
n = int(input()) D = [] def FindOtvet(i, j, otv): if i == 0: return "" if j == 0: if (otv + D[i - 1][j]) < n: otv += D[i - 1][j] return str(j + 1) + FindOtvet(i - 1, j + 1, otv) else: return str(j) + FindOtvet(i - 1, j, otv) elif j == 9: if (otv + D[i - 1][j - 1]) < n: otv += D[i - 1][j - 1] return str(j) + FindOtvet(i - 1, j, otv) else: return str(j - 1) + FindOtvet(i - 1, j - 1, otv) else: if (otv + D[i - 1][j - 1]) < n: otv += D[i - 1][j - 1] if (otv + D[i - 1][j]) < n: otv += D[i - 1][j] return str(j + 1) + FindOtvet(i - 1, j + 1, otv) else: return str(j) + FindOtvet(i - 1, j, otv) else: return str(j - 1) + FindOtvet(i - 1, j - 1, otv) arr = [] for i in range(10): arr.append(1) D.append(arr) totalSum = 9 i = 1 respI = 0 respJ = 0 while respI == 0 and respJ == 0: arr = [] for j in range(10): if j == 0: arr.append(D[i - 1][j] + D[i - 1][j + 1]) elif j < 9: arr.append(D[i - 1][j - 1] + D[i - 1][j] + D[i - 1][j + 1]) else: arr.append(D[i - 1][j - 1] + D[i - 1][j]) if j > 0: if (totalSum + arr[j]) >= n: respI = i respJ = j break totalSum += arr[j] D.append(arr) i += 1 respStr = str(respJ) print(respStr + FindOtvet(respI, respJ, totalSum))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s757472658
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
import collections def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a # N-1の約数を数える N = int(input()) factor = collections.Counter(prime_factorize(N - 1)) K = 1 for i in list(factor.values()): K *= i + 1 K -= 1 for f in range(2, int(N**0.5) + 1): n = N if n % f != 0: continue while n % f == 0: n //= f if n % f == 1 or n == 1: K += 1 # 最後は自分自身を加える。 K += 1 print(K)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s030697050
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
lis = list(map(int, input().split())) print(lis[2], lis[0], lis[1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s753968852
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
x = list(input().split()) a = [x[2], x[0], x[1]] print(" ".join(a))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s151097187
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
usr = input() print(usr[2], usr[0], usr[1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s701348297
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
print(*sorted(list(map(int, input().split()))))
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s430614276
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
d, e, f = map(int, input().split()) print(f, e, d)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s250776671
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
N, A, B = input().split() print(B, A, N)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s154137403
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
num = list(map(str, input().split())) out = num[2] + " " + num[0] + " " + num[1] print(out)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s931545706
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
val = input() nums = list(map(int, val.split())) nums[0], nums[1] = nums[1], nums[0] nums[0], nums[2] = nums[2], nums[0] print(nums[0], nums[1], nums[2])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s349340492
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
l_input = [int(e) for e in input().split()] l_output = [l_input[2], l_input[0], l_input[1]] print(*l_output)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s398818921
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
s = str(input()) l = [0, 0] i = 0 for n in range(0, len(s)): if s[n] == " ": l[i] = n i += 1 if i == 2: break X = int(s[0 : l[0] - 1]) Y = int(s[l[0] + 1, l[1] - 1]) Z = int(s[l[1] + 1, len(s) - 1]) temp1 = X X = Y Y = temp1 temp2 = X X = Z Z = temp2 print(X, " ", Y, " ", Z)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s779732812
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
A = int(input()) B = int(input()) C = int(input()) if A < B and B < C: T = A A = B B = T print(A, B, C) else: T1 = A A = C C = T1 print(A, B, C)
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s071505979
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
K = int(input()) num = list(range(1, 10)) for i in range(K): a = num[i] b = 10 * a + a % 10 if a % 10 != 0: num.append(b - 1) num.append(b) if a % 10 != 9: num.append(b + 1) print(num[K - 1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s828698804
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
# 複数の入力 input_list = input().split() input_list = input_list.sort print(input_list[0], input_list[1], input_list[2])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s793913463
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
data = input().split() print(data[2] + " " + data[0] + " " + data[1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s308480108
Accepted
p02717
Input is given from Standard Input in the following format: X Y Z
user = input().split() print(user[2], user[0], user[1])
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s236396312
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
d, s, r = map(int, input().split()) print(f"{r} {d} {s}")
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s038014769
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
def swapper(X, Y, Z): X, Y, Z = Z, X, Y return X, Y, Z
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s955027748
Runtime Error
p02717
Input is given from Standard Input in the following format: X Y Z
X = input().split(" ") print(f"{X[2]} {X[0]} {X[1]}")
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the integers contained in the boxes A, B, and C, in this order, with space in between. * * *
s842038619
Wrong Answer
p02717
Input is given from Standard Input in the following format: X Y Z
s = input() print("Yes" if s[2] == s[3] and s[4] == s[5] else "No")
Statement We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C
[{"input": "1 2 3", "output": "3 1 2\n \n\nAfter the contents of the boxes A and B are swapped, A, B, and C contain 2, 1,\nand 3, respectively. \nThen, after the contents of A and C are swapped, A, B, and C contain 3, 1, and\n2, respectively.\n\n* * *"}, {"input": "100 100 100", "output": "100 100 100\n \n\n* * *"}, {"input": "41 59 31", "output": "31 41 59"}]
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once. * * *
s543601268
Accepted
p03805
The input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
def examA(): O = SI() E = SI() ans = "" for i in range(len(O) + len(E)): if i % 2 == 0: ans += O[i // 2] else: ans += E[i // 2] print(ans) return def examB(): A = LI() A.sort() ans = (A[2] - A[0]) // 2 + (A[2] - A[1]) // 2 if (A[2] - A[0]) % 2 == 1: ans += 1 if (A[2] - A[1]) % 2 == 0: ans += 1 elif (A[2] - A[1]) % 2 == 1: ans += 2 print(ans) return def examC(): S = SI() S.replace("RL", "A") S.replace("LR", "B") N = len(S) A = [0] * N print(S) l = 0 r = 0 for i, s in enumerate(S): if s == "A": A[i] += r elif s == "B": A[i] += l ans = 0 print(ans) return def examD(): def warshall_floyd(n, d): # 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 H, W = LI() C = [LI() for _ in range(10)] A = [LI() for _ in range(H)] C = warshall_floyd(10, C) ans = 0 for i in range(H): for j in range(W): a = A[i][j] if a == -1: continue ans += C[a][1] print(ans) return def examE(): N, M = LI() V = [[] for _ in range(N)] for _ in range(M): a, b = LI() a -= 1 b -= 1 V[a].append(b) V[b].append(a) def dfs(s, visited): # print(s,visited) res = 0 visited.add(s) if len(visited) == N: visited.remove(s) return 1 for ne in V[s]: if ne in visited: continue res += dfs(ne, visited) visited.remove(s) return res visited = set() ans = dfs(0, visited) # print(visited) print(ans) return def examF(): ans = 0 print(ans) return import sys, bisect, itertools, heapq, math, random from copy import deepcopy from heapq import heappop, heappush, heapify from collections import Counter, defaultdict, deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LSI(): return list(map(str, sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod, mod2, inf, alphabet, _ep mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 _ep = 10 ** (-12) alphabet = [chr(ord("a") + i) for i in range(26)] sys.setrecursionlimit(10**6) if __name__ == "__main__": examE() """ """
Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. ![](https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png) Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. ![](https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png) Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. ![](https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png) Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. ![](https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png) Figure 4: another example of a path that does not satisfy the condition
[{"input": "3 3\n 1 2\n 1 3\n 2 3", "output": "2\n \n\nThe given graph is shown in the following figure:\n\n![43c0ac53de20d989d100bf60b3cd05fa.png](https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png)\n\nThe following two paths satisfy the condition:\n\n![c4a27b591d364fa479314e3261b85071.png](https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png)\n\n* * *"}, {"input": "7 7\n 1 3\n 2 7\n 3 4\n 4 5\n 4 6\n 5 6\n 6 7", "output": "1\n \n\nThis test case is the same as the one described in the problem statement."}]
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once. * * *
s750161081
Accepted
p03805
The input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
n, m = map(int, input().split()) a = [tuple(map(int, input().split())) for _ in range(m)] sum_n = sum([i for i in range(n + 1)]) all_route = [] def dfs(i, r, o): route = r o_v = o route.append(i) o_v.append(i) v_num = [v[1] for v in a if v[0] == i and v[1] not in o_v] v_num += [v[0] for v in a if v[1] == i and v[0] not in o_v] if len(v_num) == 0: all_route.append(route[:]) else: for v in v_num: dfs(v, route[:], o_v[:]) dfs(1, [], []) all_route_scores = [sum(route) for route in all_route] r = all_route_scores.count(sum_n) print(r)
Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. ![](https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png) Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. ![](https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png) Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. ![](https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png) Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. ![](https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png) Figure 4: another example of a path that does not satisfy the condition
[{"input": "3 3\n 1 2\n 1 3\n 2 3", "output": "2\n \n\nThe given graph is shown in the following figure:\n\n![43c0ac53de20d989d100bf60b3cd05fa.png](https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png)\n\nThe following two paths satisfy the condition:\n\n![c4a27b591d364fa479314e3261b85071.png](https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png)\n\n* * *"}, {"input": "7 7\n 1 3\n 2 7\n 3 4\n 4 5\n 4 6\n 5 6\n 6 7", "output": "1\n \n\nThis test case is the same as the one described in the problem statement."}]
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once. * * *
s894701933
Accepted
p03805
The input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
# import time N, M = map(int, input().split()) # 動くことのできる経路とその逆向きの移動をリストにし、それをリストにしたもの lst = [] for i in range(M): a = list(map(int, input().split())) lst += [a] + [a[::-1]] def next_permutation(L): # リストを順列で並び替える部分 i = N - 2 while i >= 0 and L[i] > L[i + 1]: i -= 1 if i == -1: return False j = i + 1 while j < N and L[i] < L[j]: j += 1 j -= 1 L[i], L[j] = L[j], L[i] left = i + 1 right = N - 1 while left < right: L[left], L[right] = L[right], L[left] left += 1 right -= 1 return True # 1-->Nまでの整数が順に並んでいるリスト、このリストの順番にたどるとする L = [i + 1 for i in range(N)] # print ('作成したL', L) def judge( L, ): # ある経路Lが与えられたときに、その移動がリスト内の移動法で可能かどうかを判定、可能-->True 不可-->Falseを返す for i in range(N - 1): if not L[i : i + 2] in lst: # print ('L[i:i+2]=', L[i:i+2]) return False return True def roop(L): # 全判定する部分 count = 0 while True: # 順路が条件を満たすか判定する部分 # print ('ループ内L', L) # time.sleep(3) if ( L[0] != 1 ): # 並び替えた後に最初が1ではない-->パスが1から始まらず条件を満たさない print(count) break if judge(L): count += 1 if not next_permutation(L): print(count) break return "error" # print ('lst = ',lst) roop(L)
Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. ![](https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png) Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. ![](https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png) Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. ![](https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png) Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. ![](https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png) Figure 4: another example of a path that does not satisfy the condition
[{"input": "3 3\n 1 2\n 1 3\n 2 3", "output": "2\n \n\nThe given graph is shown in the following figure:\n\n![43c0ac53de20d989d100bf60b3cd05fa.png](https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png)\n\nThe following two paths satisfy the condition:\n\n![c4a27b591d364fa479314e3261b85071.png](https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png)\n\n* * *"}, {"input": "7 7\n 1 3\n 2 7\n 3 4\n 4 5\n 4 6\n 5 6\n 6 7", "output": "1\n \n\nThis test case is the same as the one described in the problem statement."}]
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once. * * *
s574640200
Accepted
p03805
The input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
import math import itertools INF = 10**9 + 7 PRIME_NUM = [ 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, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, ] def main(): n, m = map(int, input().split()) ab = [] for i in range(m): ab.append(list(map(int, input().split()))) link = [] for i in range(n + 1): link.append([]) for i in ab: link[i[0]].append(i[1]) link[i[1]].append(i[0]) tmp = [i for i in range(2, n + 1)] ans = 0 for i in itertools.permutations(tmp): flag = True array = [1] + list(i) for j in range(0, n - 1): if link[array[j]].count(array[j + 1]) == 0: flag = False if flag: ans += 1 print(ans) main()
Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. ![](https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png) Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. ![](https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png) Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. ![](https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png) Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. ![](https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png) Figure 4: another example of a path that does not satisfy the condition
[{"input": "3 3\n 1 2\n 1 3\n 2 3", "output": "2\n \n\nThe given graph is shown in the following figure:\n\n![43c0ac53de20d989d100bf60b3cd05fa.png](https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png)\n\nThe following two paths satisfy the condition:\n\n![c4a27b591d364fa479314e3261b85071.png](https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png)\n\n* * *"}, {"input": "7 7\n 1 3\n 2 7\n 3 4\n 4 5\n 4 6\n 5 6\n 6 7", "output": "1\n \n\nThis test case is the same as the one described in the problem statement."}]
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once. * * *
s285687634
Accepted
p03805
The input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
import sys sys.setrecursionlimit(10000) def memoize(function): def _memoize(*args, _cache={}): if args in _cache: return _cache[args] result = function(*args) _cache[args] = result return result return _memoize class Union_find: def __init__(self, num): self.num = num self.par = list(range(num)) self.rank = [0] * num def find(self, x): px = self.par[x] if px == x: return x else: rx = self.find(px) self.par[x] = rx return rx def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] > self.rank[y]: self.par[y] = x else: self.par[x] = y if self.rank[x] == self.rank[y]: self.rank[y] = self.rank[y] + 1 return self def same(self, x, y): return self.find(x) == self.find(y) def group_num(self): l = set() for i in range(self.num): l.add(self.find(i)) return len(l) class Adjlist: def __init__(self, nodes, edges=None): self.nodes = nodes lis = [set() for i in range(nodes)] if edges is not None: for edge in edges: lis[edge[0]].add(edge[1]) self.edges = lis def add_edge(self, edge): self.edges[edge[0]].add(edge[1]) return self def discard_edge(self, edge): self.edges[edge[0]].discard(edge[1]) return self def next_set(self, x): return self.edges[x] def include_edge(self, x, y): return y in self.next_set(x) class Adjlist_weighted: def __init__(self, nodes, edges=None): self.nodes = nodes lis = [{} for i in range(nodes)] if edges is not None: for edge in edges: lis[edge[0]][edge[1]] = edge[2] self.edges = lis def add_edge(self, edge): self.edges[edge[0]][edge[1]] = edge[2] return self def discard_edge(self, edge): del self.edges[edge[0]][edge[1]] return self def next_set(self, x): return self.edges[x].keys() def include_edge(self, x, y): return y in self.next_set(x) def weight_edge(self, x, y): return self.edge[x][y] class Adjmat: def __init__(self, nodes, edges=None): self.nodes = nodes mat = [[0] * nodes for i in range(nodes)] if edges is not None: for edge in edges: mat[edge[0]][edge[1]] = 1 self.edges = mat def add_edge(self, edge): self.edges[edge[0]][edge[1]] = 1 return self def discard_edge(self, edge): self.edges[edge[0]][edge[1]] = 0 return self def include_edge(self, x, y): return self.edge[x][y] == 1 def next_set(self, x): set = set() for y in range(nodes): if self.include_edge(x, y): set.add(y) return set class Adjmat_weighted: def __init__(self, nodes, edges=None): self.nodes = nodes mat = [[None] * nodes for i in range(nodes)] if edges is not None: for edge in edges: mat[edge[0]][edge[1]] = edge[2] self.edges = mat def add_edge(self, edge): self.edges[edge[0]][edge[1]] = edge[2] return self def discard_edge(self, edge): self.edges[edge[0]][edge[1]] = None return self def include_edge(self, x, y): return self.edges[x][y] is not None def next_set(self, x): set = set() for y in range(nodes): if self.include_edge(x, y): set.add(y) return set def weight_edge(self, x, y): return self.edge[x][y] class Graph: def __init__(self, nodes, adj_mat=True, weighted=False, directed=False, edges=None): self.nodes = nodes self.adj_mat = adj_mat self.directed = directed self.weighted = weighted if weighted: if not (directed): if edges is not None: for edge in edges: edges.add((edge[1], edge[0], edge[2])) if adj_mat: edges = Adjmat_weighted(nodes, edges) else: edges = Adjlist_weighted(nodes, edges) else: if not (directed): if edges is not None: for edge in edges: edges.add((edge[1], edge[0])) if adj_mat: edges = Adjmat(nodes, edges) else: edges = Adjlist(nodes, edges) self.edges = edges def add_edge(self, edge): self.edges.add_edge(edge) if not (self.directed): if self.weighted: self.edges.add_edge((edge[1], edge[0], edge[2])) else: self.edges.add_edge((edge[1], edge[0])) return self def discard_edge(self, edge): self.edges.discard_edge(edge) if not (self.directed): self.edges.discard_edge((edge[1], edge[0])) return self def include_edge(self, x, y): return self.edges.include_edge(x, y) def next_set(self, x): return self.edges.next_set(x) def weight_edge(self, x, y): if self.weighted: return self.edges.weight_edge(x, y) elif self.adj_mat: return self.edges[x][y] else: if self.include_edge(x, y): return 1 else: return 0 def union_find(self): uf = Union_find(self.nodes) if self.adj_mat: for i in range(self.nodes): for j in range(self.nodes): if self.edges.include_edge(i, j): uf.union(i, j) else: for i in range(self.nodes): for j in self.edges.next_set(): uf.union(i, j) return uf (N, M) = tuple(map(int, input().split(" "))) g = Graph(N, False) for i in range(M): g.add_edge(tuple(map(lambda x: int(x) - 1, input().split(" ")))) @memoize def one_path(point, path=(), remin=N - 1): if remin != 0: s = set(path) s.add(point) d = g.next_set(point) - s sum = 0 for n in d: sum += one_path(n, tuple(s), remin - 1) return sum else: return 1 print(one_path(0))
Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. ![](https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png) Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. ![](https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png) Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. ![](https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png) Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. ![](https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png) Figure 4: another example of a path that does not satisfy the condition
[{"input": "3 3\n 1 2\n 1 3\n 2 3", "output": "2\n \n\nThe given graph is shown in the following figure:\n\n![43c0ac53de20d989d100bf60b3cd05fa.png](https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png)\n\nThe following two paths satisfy the condition:\n\n![c4a27b591d364fa479314e3261b85071.png](https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png)\n\n* * *"}, {"input": "7 7\n 1 3\n 2 7\n 3 4\n 4 5\n 4 6\n 5 6\n 6 7", "output": "1\n \n\nThis test case is the same as the one described in the problem statement."}]
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once. * * *
s747462476
Runtime Error
p03805
The input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
from collections import defaultdict n, m = map(lambda x: int(x), input().split()) links = defaultdict(set) for _ in range(m): a, b = map(lambda x: int(x), input().split()) links[a].add(b) links[b].add(a) path_counter = 0 def path_patterns_number(current_node, remaining_nodes):#, remaining_links): # print(current_node, remaining_nodes) if len(remaining_nodes) == 0: return 1 patterns = 0 for next_node in (links[current_node] & remaining_nodes): # remaining_links_copy = remaining_links.copy() # remaining_links_copy[current_node].remove(next_node) <=浅いコピーなので元のからもremoveされてる patterns += path_patterns_number( next_node, remaining_nodes.copy() - {next_node} # remaining_links_copy ) return patterns print(path_patterns_number(1, set(range(2,n+1)))#, links))
Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. ![](https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png) Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. ![](https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png) Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. ![](https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png) Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. ![](https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png) Figure 4: another example of a path that does not satisfy the condition
[{"input": "3 3\n 1 2\n 1 3\n 2 3", "output": "2\n \n\nThe given graph is shown in the following figure:\n\n![43c0ac53de20d989d100bf60b3cd05fa.png](https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png)\n\nThe following two paths satisfy the condition:\n\n![c4a27b591d364fa479314e3261b85071.png](https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png)\n\n* * *"}, {"input": "7 7\n 1 3\n 2 7\n 3 4\n 4 5\n 4 6\n 5 6\n 6 7", "output": "1\n \n\nThis test case is the same as the one described in the problem statement."}]
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once. * * *
s614124162
Runtime Error
p03805
The input is given from Standard Input in the following format: N M a_1 b_1 a_2 b_2 : a_M b_M
N,M = map(int,input(),aplit()) path = [[] for i in range(N)] for _ in range(M): a,b = map(int,input(),split()) path[a-1],append(b-1) path[b-1],append(a-1) vis = [0 for i in range(N)] cnt = 0 def dfs(now,path): global cnt if depth == N: cnt+=1 for new in path[now]: if vis[new] == 0: vis[new] = 1 dfs(new,depth+1) vis[new] = 0 vis[0] = 1 dfs(0,1) print(cnt)
Statement You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges. Here, a _self-loop_ is an edge where a_i = b_i (1≤i≤M), and _double edges_ are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M). How many different paths start from vertex 1 and visit all the vertices exactly once? Here, the endpoints of a path are considered visited. For example, let us assume that the following undirected graph shown in Figure 1 is given. ![](https://atcoder.jp/img/5013/888b2f55d46f66125a4ac25cd8cfc19a.png) Figure 1: an example of an undirected graph The following path shown in Figure 2 satisfies the condition. ![](https://atcoder.jp/img/5013/694eda4639f3f4608c9f0b38af1633d3.png) Figure 2: an example of a path that satisfies the condition However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices. ![](https://atcoder.jp/img/5013/4739baf6665ab2832ea424b1cc404ee1.png) Figure 3: an example of a path that does not satisfy the condition Neither the following path shown in Figure 4, because it does not start from vertex 1. ![](https://atcoder.jp/img/5013/7ad401c30e069a98a34c8cfec70ec278.png) Figure 4: another example of a path that does not satisfy the condition
[{"input": "3 3\n 1 2\n 1 3\n 2 3", "output": "2\n \n\nThe given graph is shown in the following figure:\n\n![43c0ac53de20d989d100bf60b3cd05fa.png](https://atcoder.jp/img/5013/43c0ac53de20d989d100bf60b3cd05fa.png)\n\nThe following two paths satisfy the condition:\n\n![c4a27b591d364fa479314e3261b85071.png](https://atcoder.jp/img/5013/c4a27b591d364fa479314e3261b85071.png)\n\n* * *"}, {"input": "7 7\n 1 3\n 2 7\n 3 4\n 4 5\n 4 6\n 5 6\n 6 7", "output": "1\n \n\nThis test case is the same as the one described in the problem statement."}]