output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s047166798
Accepted
p03088
Input is given from Standard Input in the following format: N
import sys s2nn = lambda s: [int(c) for c in s.split(" ")] ss2nn = lambda ss: [int(s) for s in list(ss)] ss2nnn = lambda ss: [s2nn(s) for s in list(ss)] i2s = lambda: sys.stdin.readline().rstrip() i2n = lambda: int(i2s()) i2nn = lambda: s2nn(i2s()) ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)] # NG: 021, 201, 012, 0x21, 02x1 def check(c0, c1, c2, c3): if c0 == 1 and c1 == 2 and c2 == 0: return False if c0 == 1 and c1 == 0 and c2 == 2: return False if c0 == 2 and c1 == 1 and c2 == 0: return False if c0 == 1 and c1 == 2 and c3 == 0: return False if c0 == 1 and c2 == 2 and c3 == 0: return False return True def main(N): mod = int(1e9) + 7 dp1 = [0 for _ in range(4)] for c0 in range(4): if check(c0, -1, -1, -1) == False: continue dp1[c0] = 1 if N == 1: ans = 0 for c1 in range(4): ans += dp1[c1] ans %= mod print(ans) return dp2 = [[0 for _ in range(4)] for _ in range(4)] for c1 in range(4): for c0 in range(4): if check(c0, c1, -1, -1) == False: continue dp2[c0][c1] += dp1[c1] dp2[c0][c1] %= mod if N == 2: ans = 0 for c1 in range(4): for c2 in range(4): ans += dp2[c1][c2] ans %= mod print(ans) return dp3 = [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for c1 in range(4): for c2 in range(4): for c0 in range(4): if check(c0, c1, c2, -1) == False: continue dp3[c0][c1][c2] += dp2[c1][c2] dp3[c0][c1][c2] %= mod if N == 3: ans = 0 for c1 in range(4): for c2 in range(4): for c3 in range(4): ans += dp3[c1][c2][c3] ans %= mod print(ans) return dp = [ [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(N + 1) ] for c1 in range(4): for c2 in range(4): for c3 in range(4): dp[3][c1][c2][c3] = dp3[c1][c2][c3] for l in range(3, N): for c1 in range(4): for c2 in range(4): for c3 in range(4): for c0 in range(4): if check(c0, c1, c2, c3) == False: continue dp[l + 1][c0][c1][c2] += dp[l][c1][c2][c3] dp[l + 1][c0][c1][c2] %= mod ans = 0 for c1 in range(4): for c2 in range(4): for c3 in range(4): ans += dp[N][c1][c2][c3] ans %= mod print(ans) main(i2n())
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s516318812
Accepted
p03088
Input is given from Standard Input in the following format: N
N = int(input()) mod = int(1e9 + 7) dp = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(N)] for i in range(4): for j in range(4): for k in range(4): dp[2][i][j][k] = 1 dp[2][2][1][0] = 0 dp[2][1][2][0] = 0 dp[2][2][0][1] = 0 for i in range(3, N): for x in range(4): for y in range(4): dp[i][0][x][y] = ( dp[i - 1][x][y][0] + dp[i - 1][x][y][1] + dp[i - 1][x][y][2] + dp[i - 1][x][y][3] ) dp[i][1][x][y] = ( dp[i - 1][x][y][0] + dp[i - 1][x][y][1] + dp[i - 1][x][y][2] + dp[i - 1][x][y][3] ) dp[i][2][x][y] = ( dp[i - 1][x][y][0] + dp[i - 1][x][y][1] + dp[i - 1][x][y][2] + dp[i - 1][x][y][3] ) dp[i][3][x][y] = ( dp[i - 1][x][y][0] + dp[i - 1][x][y][1] + dp[i - 1][x][y][2] + dp[i - 1][x][y][3] ) dp[i][2][3][1] -= dp[i - 1][3][1][0] dp[i][2][1][3] -= dp[i - 1][1][3][0] dp[i][2][0][1] -= dp[i - 1][0][1][0] dp[i][2][1][0] -= dp[i - 1][1][0][0] dp[i][2][1][1] -= dp[i - 1][1][1][0] dp[i][1][2][0] = 0 dp[i][2][0][1] = 0 dp[i][2][1][0] = 0 ans = 0 for i in range(4): for j in range(4): for k in range(4): ans = (ans + dp[N - 1][i][j][k]) % mod print(ans)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s675432652
Accepted
p03088
Input is given from Standard Input in the following format: N
N = int(input()) ans = 0 M = (10**9) + 7 dic = {} pdic = {} pdic["AAA"] = 1 pdic["AAC"] = 1 pdic["AAG"] = 1 pdic["AAT"] = 1 pdic["ACA"] = 1 pdic["ACC"] = 1 pdic["ACG"] = 0 pdic["ACT"] = 1 pdic["AGA"] = 1 pdic["AGC"] = 0 pdic["AGG"] = 1 pdic["AGT"] = 1 pdic["ATA"] = 1 pdic["ATC"] = 1 pdic["ATG"] = 1 pdic["ATT"] = 1 pdic["CAA"] = 1 pdic["CAC"] = 1 pdic["CAG"] = 1 pdic["CAT"] = 1 pdic["CCA"] = 1 pdic["CCC"] = 1 pdic["CCG"] = 1 pdic["CCT"] = 1 pdic["CGA"] = 1 pdic["CGC"] = 1 pdic["CGG"] = 1 pdic["CGT"] = 1 pdic["CTA"] = 1 pdic["CTC"] = 1 pdic["CTG"] = 1 pdic["CTT"] = 1 pdic["GAA"] = 1 pdic["GAC"] = 0 pdic["GAG"] = 1 pdic["GAT"] = 1 pdic["GCA"] = 1 pdic["GCC"] = 1 pdic["GCG"] = 1 pdic["GCT"] = 1 pdic["GGA"] = 1 pdic["GGC"] = 1 pdic["GGG"] = 1 pdic["GGT"] = 1 pdic["GTA"] = 1 pdic["GTC"] = 1 pdic["GTG"] = 1 pdic["GTT"] = 1 pdic["TAA"] = 1 pdic["TAC"] = 1 pdic["TAG"] = 1 pdic["TAT"] = 1 pdic["TCA"] = 1 pdic["TCC"] = 1 pdic["TCG"] = 1 pdic["TCT"] = 1 pdic["TGA"] = 1 pdic["TGC"] = 1 pdic["TGG"] = 1 pdic["TGT"] = 1 pdic["TTA"] = 1 pdic["TTC"] = 1 pdic["TTG"] = 1 pdic["TTT"] = 1 for i in range(N - 3): for k in pdic.keys(): k = str(k) if k == "ACG" or k == "AGC" or k == "GAC": dic[k] = 0 elif k[1:] == "GC": dic[k] = pdic["C" + k[:-1]] + pdic["G" + k[:-1]] + pdic["T" + k[:-1]] elif k[0] == "G" and k[2] == "C": dic[k] = pdic["C" + k[:-1]] + pdic["G" + k[:-1]] + pdic["T" + k[:-1]] else: dic[k] = ( pdic["A" + k[:-1]] + pdic["C" + k[:-1]] + pdic["G" + k[:-1]] + pdic["T" + k[:-1]] ) for k in pdic.keys(): pdic[k] = dic[k] if N == 3: print(61) else: for v in dic.values(): ans += v ans = ans % M print(ans)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s950143389
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) rr = lambda N: [ri() for _ in range(N)] YN = lambda b: print("YES") if b else print("NO") yn = lambda b: print("Yes") if b else print("No") OE = lambda x: print("Odd") if x % 2 else print("Even") INF = 10**18 MOD = 10**9 + 7 N = ri() dp = [[[0 for k in range(4)] for j in range(7)] for i in range(N)] dp[0][0][0] = 2 dp[0][1][0] = 1 dp[0][5][0] = 1 for i in range(1, N): dp[i][0][0] = ( dp[i - 1][0][0] * 2 + dp[i - 1][2][2] + dp[i - 1][3][2] + dp[i - 1][4][1] * 2 + dp[i - 1][5][0] * 2 + dp[i - 1][5][1] + dp[i - 1][6][1] * 2 + dp[i - 1][6][2] ) dp[i][1][0] = ( dp[i - 1][0][0] + dp[i - 1][1][0] + dp[i - 1][2][2] + dp[i - 1][4][1] + dp[i - 1][5][1] + dp[i - 1][6][1] ) dp[i][1][1] = dp[i - 1][1][0] + dp[i - 1][5][1] dp[i][1][2] = dp[i - 1][1][1] dp[i][2][2] = dp[i - 1][1][1] dp[i][2][3] = dp[i - 1][2][2] dp[i][3][2] = dp[i - 1][1][1] dp[i][3][3] = dp[i - 1][3][2] dp[i][4][1] = dp[i - 1][1][0] dp[i][4][2] = dp[i - 1][4][1] dp[i][5][0] = ( dp[i - 1][0][0] + dp[i - 1][2][2] + dp[i - 1][3][2] + dp[i - 1][5][0] + dp[i - 1][6][2] ) dp[i][5][1] = dp[i - 1][1][1] + dp[i - 1][3][2] + dp[i - 1][5][0] + dp[i - 1][6][2] dp[i][5][2] = dp[i - 1][5][1] dp[i][6][1] = dp[i - 1][1][0] dp[i][6][2] = dp[i - 1][6][1] dp[i][6][3] = dp[i - 1][6][2] ans = ( dp[N - 1][0][0] + dp[N - 1][1][0] + dp[N - 1][1][1] + dp[N - 1][2][2] + dp[N - 1][3][2] + dp[N - 1][4][1] + dp[N - 1][5][0] + dp[N - 1][5][1] + dp[N - 1][6][1] + dp[N - 1][6][2] ) print(ans % MOD)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s664318610
Accepted
p03088
Input is given from Standard Input in the following format: N
n = int(input()) k = 2 f = [1, 4, 16] r = [ {"AG": 0, "GA": 0, "AC": 0, "AGG": 0, "A": 0, "G": 0}, {"AG": 0, "GA": 0, "AC": 0, "AGG": 0, "A": 1, "G": 1}, {"AG": 1, "GA": 1, "AC": 1, "AGG": 0, "A": 4, "G": 4, "ATG": 0, "AGT": 0, "AT": 1}, ] while k < n: k += 1 r.append({}) r[k]["AC"] = r[k - 1]["A"] - r[k - 1]["GA"] r[k]["GA"] = r[k - 1]["G"] r[k]["AG"] = r[k - 1]["A"] r[k]["AGG"] = r[k - 1]["AG"] r[k]["A"] = f[k - 1] r[k]["G"] = f[k - 1] - r[k - 1]["AC"] r[k]["ATG"] = r[k - 1]["AT"] r[k]["AT"] = r[k - 1]["A"] r[k]["AGT"] = r[k - 1]["AG"] f.append(0) f[k] = ( f[k - 1] * 4 - r[k - 1]["AG"] - r[k - 1]["GA"] - r[k - 1]["AC"] - r[k - 1]["AGG"] - r[k - 1]["ATG"] - r[k - 1]["AGT"] ) print(f[n] % (10**9 + 7))
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s869988752
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
n = int(input()) mod = 10**9 + 7 a = [1] * 16 no = [0, 0] for _ in range(n - 2): b = [0] * 16 b[0] = a[0] + a[4] + a[8] + a[12] b[1] = a[0] + a[4] + a[12] b[2] = a[0] + a[4] + a[8] + a[12] b[3] = a[0] + a[4] + a[8] + a[12] b[4] = a[1] + a[5] + a[9] + a[13] b[5] = a[1] + a[5] + a[9] + a[13] b[6] = a[5] + a[9] + a[13] b[7] = a[1] + a[5] + a[9] + a[13] b[8] = a[2] + a[6] + a[9] + a[14] b[9] = a[6] + a[9] + a[14] - no[0] - no[1] b[10] = a[2] + a[6] + a[9] + a[14] b[11] = a[2] + a[6] + a[9] + a[14] b[12] = a[3] + a[7] + a[10] + a[15] b[13] = a[3] + a[7] + a[10] + a[15] - no[1] b[14] = a[3] + a[7] + a[10] + a[15] b[15] = a[3] + a[7] + a[10] + a[15] no[0] = a[2] no[1] = a[3] a = b for i in range(16): a[i] %= mod print(sum(a))
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s587614911
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
XAA = 1 XAT = 1 XAG = 1 XAC = 1 XTA = 1 XTT = 1 XTG = 1 XTC = 1 XGA = 1 XGT = 1 XGG = 1 XGC = 1 XCA = 1 XCT = 1 XCG = 1 XCC = 1 m = 1000000007 N = int(input()) for i in range(N - 2): XAA, XAT, XAG, XAC, XTA, XTT, XTG, XTC, XGA, XGT, XGG, XGC, XCA, XCT, XCG, XCC = ( (XAA + XTA + XGA + XCA) % m, (XAA + XTA + XGA + XCA) % m, (XAA + XTA + XGA + XCA) % m, (XAA + XTA + XCA) % m, (XAT + XTT + XGT + XCT) % m, (XAT + XTT + XGT + XCT) % m, (XAT + XTT + XGT + XCT) % m, (XAT + XTT + XGT + XCT) % m, (XAG + XTG + XGG) % m, (XAG + XTG + XGG + XCG) % m, (XAG + XTG + XGG + XCG) % m, (XTG + XGG + XCG) % m, (XAC + XTC + XGC + XCC) % m, (XAC + XTC + XGC + XCC) % m, (XTC + XGC + XCC) % m, (XAC + XTC + XGC + XCC) % m, ) print( ( XAA + XAT + XAG + XAC + XTA + XTT + XTG + XTC + XGA + XGT + XGG + XGC + XCA + XCT + XCG + XCC ) % m )
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s514665402
Accepted
p03088
Input is given from Standard Input in the following format: N
## クソみたいな漸化式をクソみたいなコードで書いてしまった def ABC122D_sum(): return ( ACT_A[-1] + G_A[-1] + A_G[-1] + GCT_G_G[-1] + A_G_G[-1] + C_G[-1] + A_T_G[-1] + GCT_T_G[-1] + A_C[-1] + GCT_C[-1] + A_T[-1] + A_G_T[-1] + GCT_G_T[-1] + CT_T[-1] ) N = int(input()) mod = int(1e9 + 7) ## N=3の場合で初項を作る ACT_A = [4 * 3 * 1] G_A = [4 * 1 * 1] A_G = [4 * 1 * 1] GCT_G_G = [3 * 1 * 1] A_G_G = [1 * 1 * 1] C_G = [3 * 1 * 1] A_T_G = [1 * 1 * 1] GCT_T_G = [3 * 1 * 1] A_C = [3 * 1 * 1] GCT_C = [4 * 2 * 1 + 3 * 1 * 1] A_T = [4 * 1 * 1] A_G_T = [1 * 1 * 1] GCT_G_T = [3 * 1 * 1] CT_T = [4 * 2 * 1] # print(ABC122D_sum()) if N == 3: print(ABC122D_sum()) exit() for i in range(N - 3): new_ACT_A = ( ACT_A[-1] + G_A[-1] + A_C[-1] + GCT_C[-1] + A_T[-1] + A_G_T[-1] + GCT_G_T[-1] + CT_T[-1] ) new_G_A = A_G[-1] + GCT_G_G[-1] + A_G_G[-1] + C_G[-1] + A_T_G[-1] + GCT_T_G[-1] new_A_G = ACT_A[-1] + G_A[-1] new_GCT_G_G = GCT_G_G[-1] + A_G_G[-1] + C_G[-1] + A_T_G[-1] + GCT_T_G[-1] new_A_G_G = A_G[-1] new_C_G = GCT_C[-1] new_A_T_G = A_T[-1] new_GCT_T_G = A_G_T[-1] + GCT_G_T[-1] + CT_T[-1] new_A_C = ACT_A[-1] new_GCT_C = ( GCT_G_G[-1] + C_G[-1] + GCT_T_G[-1] + A_C[-1] + GCT_C[-1] + A_T[-1] + GCT_G_T[-1] + CT_T[-1] ) new_A_T = ACT_A[-1] + G_A[-1] new_A_G_T = A_G[-1] new_GCT_G_T = GCT_G_G[-1] + A_G_G[-1] + C_G[-1] + A_T_G[-1] + GCT_T_G[-1] new_CT_T = A_C[-1] + GCT_C[-1] + A_T[-1] + A_G_T[-1] + GCT_G_T[-1] + CT_T[-1] ACT_A.append(new_ACT_A) G_A.append(new_G_A) A_G.append(new_A_G) GCT_G_G.append(new_GCT_G_G) A_G_G.append(new_A_G_G) C_G.append(new_C_G) A_T_G.append(new_A_T_G) GCT_T_G.append(new_GCT_T_G) A_C.append(new_A_C) GCT_C.append(new_GCT_C) A_T.append(new_A_T) A_G_T.append(new_A_G_T) GCT_G_T.append(new_GCT_G_T) CT_T.append(new_CT_T) ans = ABC122D_sum() % mod print(ans)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s673810427
Accepted
p03088
Input is given from Standard Input in the following format: N
N = int(input()) dp = [dict() for i in range(2)] big = 10**9 + 7 for a in ["A", "C", "G", "T"]: for b in ["A", "C", "G", "T"]: for c in ["A", "C", "G", "T"]: seq = a + b + c if seq != "AGC" and seq != "GAC" and seq != "ACG": dp[0][seq] = 1 else: dp[0][seq] = 0 def sum_of_dict(d): ans = 0 for a in ["A", "C", "G", "T"]: for b in ["A", "C", "G", "T"]: for c in ["A", "C", "G", "T"]: seq = a + b + c ans += d[seq] return ans def sum_of_dict_with(d, latter): ans = 0 for a in ["A", "C", "G", "T"]: seq = a + latter ans += d[seq] return ans for i in range(3, N): n = i % 2 for a in ["A", "C", "G", "T"]: for b in ["A", "C", "G", "T"]: for c in ["A", "C", "G", "T"]: seq = a + b + c if seq == "AGC" or seq == "GAC" or seq == "ACG": dp[n][seq] = 0 elif seq == "TGC": dp[n][seq] = ( sum_of_dict_with(dp[(n - 1) % 2], seq[:2]) - dp[(n - 1) % 2]["ATG"] ) % big elif seq == "GGC": dp[n][seq] = ( sum_of_dict_with(dp[(n - 1) % 2], seq[:2]) - dp[(n - 1) % 2]["AGG"] ) % big elif seq == "GTC": dp[n][seq] = ( sum_of_dict_with(dp[(n - 1) % 2], seq[:2]) - dp[(n - 1) % 2]["AGT"] ) % big else: dp[n][seq] = (sum_of_dict_with(dp[(n - 1) % 2], seq[:2])) % big print(sum_of_dict(dp[(N - 1) % 2]) % big)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s776229921
Accepted
p03088
Input is given from Standard Input in the following format: N
n = int(input()) dict = { 3: 61, 4: 230, 5: 865, 6: 3247, 7: 12185, 8: 45719, 9: 171531, 10: 643550, 11: 2414454, 12: 9058467, 13: 33985227, 14: 127504505, 15: 478366600, 16: 794717734, 17: 733354121, 18: 261943303, 19: 776803305, 20: 580025381, 21: 51688048, 22: 44657419, 23: 737209731, 24: 604119499, 25: 159693437, 26: 858533109, 27: 639056669, 28: 549054109, 29: 996291083, 30: 531294469, 31: 23314687, 32: 783022045, 33: 855462856, 34: 649970414, 35: 68697295, 36: 409213624, 37: 604356692, 38: 88638656, 39: 978442997, 40: 534833116, 41: 763737161, 42: 785892908, 43: 123883652, 44: 639213333, 45: 181836645, 46: 998121103, 47: 124885216, 48: 501575626, 49: 39816123, 50: 113468411, 51: 799008836, 52: 775465589, 53: 256852905, 54: 664630886, 55: 971550783, 56: 751629411, 57: 51018086, 58: 702530485, 59: 725438992, 60: 696683714, 61: 792638194, 62: 221791721, 63: 149602322, 64: 414054379, 65: 986519078, 66: 981760191, 67: 305799096, 68: 515140586, 69: 406959393, 70: 975058685, 71: 245601370, 72: 324759692, 73: 673385295, 74: 191483611, 75: 570246669, 76: 427196161, 77: 781042769, 78: 569725155, 79: 842176273, 80: 25328739, 81: 847501730, 82: 206282374, 83: 353770801, 84: 323137024, 85: 371653459, 86: 940737264, 87: 123820509, 88: 915711339, 89: 847205021, 90: 252858375, 91: 718889563, 92: 866398347, 93: 738390145, 94: 133009077, 95: 333099663, 96: 170591295, 97: 329869205, 98: 616680192, 99: 597534442, 100: 388130742, } print(dict[n])
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s046627556
Accepted
p03088
Input is given from Standard Input in the following format: N
N = int(input()) ( AAA, AAG, AAC, AAT, AGA, AGG, AGC, AGT, ACA, ACG, ACC, ACT, ATA, ATG, ATC, ATT, GAA, GAG, GAC, GAT, GGA, GGG, GGC, GGT, GCA, GCG, GCC, GCT, GTA, GTG, GTC, GTT, CAA, CAG, CAC, CAT, CGA, CGG, CGC, CGT, CCA, CCG, CCC, CCT, CTA, CTG, CTC, CTT, TAA, TAG, TAC, TAT, TGA, TGG, TGC, TGT, TCA, TCG, TCC, TCT, TTA, TTG, TTC, TTT, ) = ( 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ) for i in range(N - 3): ( AAA, AAG, AAC, AAT, AGA, AGG, AGC, AGT, ACA, ACG, ACC, ACT, ATA, ATG, ATC, ATT, GAA, GAG, GAC, GAT, GGA, GGG, GGC, GGT, GCA, GCG, GCC, GCT, GTA, GTG, GTC, GTT, CAA, CAG, CAC, CAT, CGA, CGG, CGC, CGT, CCA, CCG, CCC, CCT, CTA, CTG, CTC, CTT, TAA, TAG, TAC, TAT, TGA, TGG, TGC, TGT, TCA, TCG, TCC, TCT, TTA, TTG, TTC, TTT, ) = ( AAA + GAA + CAA + TAA, AAA + GAA + CAA + TAA, AAA + GAA + CAA + TAA, AAA + GAA + CAA + TAA, AAG + GAG + CAG + TAG, AAG + GAG + CAG + TAG, 0, AAG + GAG + CAG + TAG, AAC + GAC + CAC + TAC, 0, AAC + GAC + CAC + TAC, AAC + GAC + CAC + TAC, AAT + GAT + CAT + TAT, AAT + GAT + CAT + TAT, AAT + GAT + CAT + TAT, AAT + GAT + CAT + TAT, AGA + GGA + CGA + TGA, AGA + GGA + CGA + TGA, 0, AGA + GGA + CGA + TGA, AGG + GGG + CGG + TGG, AGG + GGG + CGG + TGG, GGG + CGG + TGG, AGG + GGG + CGG + TGG, AGC + GGC + CGC + TGC, AGC + GGC + CGC + TGC, GGC + CGC + TGC, AGC + GGC + CGC + TGC, AGT + GGT + CGT + TGT, AGT + GGT + CGT + TGT, GGT + CGT + TGT, AGT + GGT + CGT + TGT, ACA + GCA + CCA + TCA, ACA + GCA + CCA + TCA, ACA + GCA + CCA + TCA, ACA + GCA + CCA + TCA, ACG + GCG + CCG + TCG, ACG + GCG + CCG + TCG, GCG + CCG + TCG, ACG + GCG + CCG + TCG, ACC + GCC + CCC + TCC, ACC + GCC + CCC + TCC, ACC + GCC + CCC + TCC, ACC + GCC + CCC + TCC, ACT + GCT + CCT + TCT, ACT + GCT + CCT + TCT, ACT + GCT + CCT + TCT, ACT + GCT + CCT + TCT, ATA + GTA + CTA + TTA, ATA + GTA + CTA + TTA, ATA + GTA + CTA + TTA, ATA + GTA + CTA + TTA, ATG + GTG + CTG + TTG, ATG + GTG + CTG + TTG, GTG + CTG + TTG, ATG + GTG + CTG + TTG, ATC + GTC + CTC + TTC, ATC + GTC + CTC + TTC, ATC + GTC + CTC + TTC, ATC + GTC + CTC + TTC, ATT + GTT + CTT + TTT, ATT + GTT + CTT + TTT, ATT + GTT + CTT + TTT, ATT + GTT + CTT + TTT, ) print( ( AAA + AAG + AAC + AAT + AGA + AGG + AGC + AGT + ACA + ACG + ACC + ACT + ATA + ATG + ATC + ATT + GAA + GAG + GAC + GAT + GGA + GGG + GGC + GGT + GCA + GCG + GCC + GCT + GTA + GTG + GTC + GTT + CAA + CAG + CAC + CAT + CGA + CGG + CGC + CGT + CCA + CCG + CCC + CCT + CTA + CTG + CTC + CTT + TAA + TAG + TAC + TAT + TGA + TGG + TGC + TGT + TCA + TCG + TCC + TCT + TTA + TTG + TTC + TTT ) % (10**9 + 7) )
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s335206745
Accepted
p03088
Input is given from Standard Input in the following format: N
n = int(input()) aa = [1] ac = [1] ag = [1] cc = [1] cg = [1] ca = [1] gc = [1] ga = [1] gg = [1] at = [1] gt = [1] t = [2] ta = [1] tc = [1] tg = [1] mod = 10**9 + 7 for i in range(n - 2): ac.append((ca[i] + ta[i] + aa[i]) % mod) ag.append((ca[i] + ga[i] + ta[i] + aa[i]) % mod) cg.append((cc[i] + gc[i] + tc[i]) % mod) aa.append((ca[i] + aa[i] + ga[i] + ta[i]) % mod) cc.append((ac[i] + cc[i] + gc[i] + tc[i]) % mod) ca.append((ac[i] + cc[i] + gc[i] + tc[i]) % mod) if i > 0: gc.append((cg[i] + gg[i] + tg[i] - ag[i - 1] - at[i - 1]) % mod) else: gc.append((cg[i] + gg[i] + tg[i]) % mod) ga.append((cg[i] + gg[i] + tg[i] + ag[i]) % mod) gg.append((cg[i] + gg[i] + tg[i] + ag[i]) % mod) at.append((ca[i] + ga[i] + ta[i] + aa[i]) % mod) gt.append((cg[i] + gg[i] + tg[i] + ag[i]) % mod) t.append((ac[i] + cc[i] + gc[i] + tc[i] + t[i] + at[i] + gt[i]) % mod) ta.append(t[i] + at[i] + gt[i]) if i > 0: tc.append(t[i] + at[i] + gt[i] - ag[i - 1]) else: tc.append(t[i] + at[i] + gt[i]) tg.append(t[i] + at[i] + gt[i]) ans = 0 ans = ( aa[n - 2] + ac[n - 2] + ag[n - 2] + cc[n - 2] + cg[n - 2] + ca[n - 2] + gc[n - 2] + ga[n - 2] + gg[n - 2] + t[n - 2] + ta[n - 2] + tc[n - 2] + tg[n - 2] + at[n - 2] + gt[n - 2] ) % mod print(ans)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s336815058
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
N = int(input()) dp = [[0] * 16 for _ in range(N + 1)] for i in range(16): dp[2][i] = 1 for n in range(3, N + 1): for f in range(4): for s in range(4): if f == 0 and s == 1: dp[n][s * 4 + 0] = (dp[n][s * 4 + 0] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 1] = (dp[n][s * 4 + 1] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 3] = (dp[n][s * 4 + 3] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) elif f == 0 and s == 2: dp[n][s * 4 + 0] = (dp[n][s * 4 + 0] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 2] = (dp[n][s * 4 + 2] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 3] = (dp[n][s * 4 + 3] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) elif f == 2 and s == 0: dp[n][s * 4 + 0] = (dp[n][s * 4 + 0] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 2] = (dp[n][s * 4 + 2] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 3] = (dp[n][s * 4 + 3] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) else: dp[n][s * 4 + 0] = (dp[n][s * 4 + 0] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 1] = (dp[n][s * 4 + 1] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 2] = (dp[n][s * 4 + 2] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) dp[n][s * 4 + 3] = (dp[n][s * 4 + 3] + dp[n - 1][f * 4 + s]) % ( 10**9 + 7 ) print(sum(dp[N]) % (10**9 + 7))
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s426290324
Accepted
p03088
Input is given from Standard Input in the following format: N
n = int(input()) a = 3 b = 4 c = 4 d = 1 e = 1 f = 1 g = 4 h = 9 i = 12 j = 22 for x in range(3, n): anew = i bnew = c + d + e + h cnew = b + i dnew = c enew = g fnew = c gnew = b + i hnew = d + e + f + h + j inew = a + b + f + g + i + j jnew = a * 2 + d + e + f + (g + h + j) * 2 a = anew b = bnew c = cnew d = dnew e = enew f = fnew g = gnew h = hnew i = inew j = jnew Sum = a + b + c + d + e + f + g + h + i + j print(Sum % (10**9 + 7))
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s039936702
Runtime Error
p03088
Input is given from Standard Input in the following format: N
a
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s714289602
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
# D mod = 10**9 + 7 n = int(input()) ans = (4**n - (3 * 4 ** (n - 3) * (n - 2) + 2 * 4 ** (n - 4) * (n - 3))) % mod print(ans)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s070768476
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
n = int(input()) a1, a2, a3, a4, c1, c2, c3, c4, g1, g2, g3, g4, t1, t2, t3, t4 = ( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ) for i in range(n - 2): a1, a2, a3, a4, c1, c2, c3, c4, g1, g2, g3, g4, t1, t2, t3, t4 = ( a1 + a2 + a3 + a4, c1 + c2 + c4, g1 + g3 + g4, t1 + t2 + t3 + t4, a1 + a2 + a3 + a4, c1 + c2 + c3 + c4, g1 + g2 + g3 + g4, t1 + t2 + t3 + t4, a1 + a3 + a4, c1 + c2 + c3 + c4, g1 + g2 + g3 + g4, t1 + t2 + t3 + t4, a1 + a2 + a3 + a4, c1 + c2 + c3 + c4, g1 + g2 + g3 + g4, t1 + t2 + t3 + t4, ) print( (a1 + a2 + a3 + a4 + c1 + c2 + c3 + c4 + g1 + g2 + g3 + g4 + t1 + t2 + t3 + t4) % (10**9 + 7) )
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s706959493
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
N = int(input()) answer = 0 if N == 3: answer = 61 else: answer = (4**N - 26 * (N - 3) * 4 ** (N - 4)) % (10**9 + 7) print(answer)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s646992930
Wrong Answer
p03088
Input is given from Standard Input in the following format: N
N = int(input()) X = 16 * (N - 4) * 4 ** (N - 5) + 2 * (N - 2) * 4 * (N - 3) A = (4**N - X) % (10**9 + 7) print(A)
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s068040052
Accepted
p03088
Input is given from Standard Input in the following format: N
N = int(input()) mod = 10**9 + 7 dp_A = [1] + [0] * (N + 5) dp_G = [1] + [0] * (N + 5) dp_C = [1] + [0] * (N + 5) dp_T = [1] + [0] * (N + 5) dp_AG = [0] * (N + 5) dp_AC = [0] * (N + 5) dp_GA = [0] * (N + 5) dp_AGA = [0] * (N + 5) dp_AGG = [0] * (N + 5) dp_AGT = [0] * (N + 5) dp_AAG = [0] * (N + 5) dp_AGG = [0] * (N + 5) dp_ATG = [0] * (N + 5) dp_ok = [4] + [0] * (N + 5) # ng=AGC,ACG,GAC,AG*C,A*GC for i in range(1, N): dp_A[i] = dp_ok[i - 1] dp_C[i] = ( dp_ok[i - 1] - dp_AG[i - 1] - dp_GA[i - 1] - dp_AGG[i - 1] - dp_AGT[i - 1] - dp_ATG[i - 1] ) dp_C[i] %= mod dp_G[i] = dp_ok[i - 1] - dp_AC[i - 1] dp_G[i] %= mod dp_T[i] = dp_ok[i - 1] dp_T[i] %= mod dp_AG[i] = dp_A[i - 1] dp_AG[i] %= mod dp_AC[i] = dp_A[i - 1] - dp_GA[i - 1] dp_AC[i] %= mod dp_GA[i] = dp_G[i - 1] dp_GA[i] %= mod dp_AGG[i] = dp_AG[i - 1] dp_AGG[i] %= mod dp_AGT[i] = dp_AG[i - 1] dp_AGT[i] %= mod dp_ATG[i] = dp_A[i - 2] dp_ATG[i] %= mod dp_ok[i] = dp_A[i] + dp_C[i] + dp_G[i] + dp_T[i] dp_ok[i] %= mod print(dp_ok[N - 1])
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
Print the number of strings of length N that satisfy the following conditions, modulo 10^9+7. * * *
s055306499
Accepted
p03088
Input is given from Standard Input in the following format: N
print( ( 388130742, 597534442, 616680192, 329869205, 170591295, 333099663, 133009077, 738390145, 866398347, 718889563, 252858375, 847205021, 915711339, 123820509, 940737264, 371653459, 323137024, 353770801, 206282374, 847501730, 25328739, 842176273, 569725155, 781042769, 427196161, 570246669, 191483611, 673385295, 324759692, 245601370, 975058685, 406959393, 515140586, 305799096, 981760191, 986519078, 414054379, 149602322, 221791721, 792638194, 696683714, 725438992, 702530485, 51018086, 751629411, 971550783, 664630886, 256852905, 775465589, 799008836, 113468411, 39816123, 501575626, 124885216, 998121103, 181836645, 639213333, 123883652, 785892908, 763737161, 534833116, 978442997, 88638656, 604356692, 409213624, 68697295, 649970414, 855462856, 783022045, 23314687, 531294469, 996291083, 549054109, 639056669, 858533109, 159693437, 604119499, 737209731, 44657419, 51688048, 580025381, 776803305, 261943303, 733354121, 794717734, 478366600, 127504505, 33985227, 9058467, 2414454, 643550, 171531, 45719, 12185, 3247, 865, 230, 61, )[2 - int(input())] )
Statement You are given an integer N. Find the number of strings of length N that satisfy the following conditions, modulo 10^9+7: * The string does not contain characters other than `A`, `C`, `G` and `T`. * The string does not contain `AGC` as a substring. * The condition above cannot be violated by swapping two adjacent characters once.
[{"input": "3", "output": "61\n \n\nThere are 4^3 = 64 strings of length 3 that do not contain characters other\nthan `A`, `C`, `G` and `T`. Among them, only `AGC`, `ACG` and `GAC` violate\nthe condition, so the answer is 64 - 3 = 61.\n\n* * *"}, {"input": "4", "output": "230\n \n\n* * *"}, {"input": "100", "output": "388130742\n \n\nBe sure to print the number of strings modulo 10^9+7."}]
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`. * * *
s444265589
Accepted
p02949
Input is given from Standard Input in the following format: N M P A_1 B_1 C_1 : A_M B_M C_M
from collections import deque # ,defaultdict printn = lambda x: print(x, end="") inn = lambda: int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda: input().strip() DBG = True and False BIG = 10**18 R = 10**9 + 7 def ddprint(x): if DBG: print(x) n, m, p = inm() dst = [{} for i in range(n + 1)] src = [{} for i in range(n + 1)] es = [] for i in range(m): a, b, c = inm() dst[a][b] = src[b][a] = p - c es.append((a, b, p - c)) rf1 = [False] * (n + 1) rf1[1] = True q = deque([1]) while len(q) > 0: x = q.popleft() for y in dst[x]: if not rf1[y]: rf1[y] = True q.append(y) rtn = [False] * (n + 1) rtn[n] = True q = deque([n]) while len(q) > 0: x = q.popleft() for y in src[x]: if not rtn[y]: rtn[y] = True q.append(y) ddprint(rf1) ddprint(rtn) use = [rf1[i] and rtn[i] for i in range(n + 1)] es = [z for z in es if use[z[0]] and use[z[1]]] ddprint(es) dp = [BIG] * (n + 1) dp[1] = 0 for i in range(n): ddprint(dp) for a, b, c in es: if dp[b] > dp[a] + c: dp[b] = dp[a] + c if i == n - 1: print(-1) exit() print(max(0, -dp[n]))
Statement There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N. We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again. When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead. Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
[{"input": "3 3 10\n 1 2 20\n 2 3 30\n 1 3 45", "output": "35\n \n\n![Figure of the graph given in Sample Input\n1](https://img.atcoder.jp/ghi/5cb074e2d7c3282da137ac4ab2fbc700.png)\n\nThere are two ways to travel from Vertex 1 to Vertex 3:\n\n * Vertex 1 \\rightarrow 2 \\rightarrow 3: You collect 20 + 30 = 50 coins on the way. After two minutes from the start of the game, you press the button, pay 2 \\times 10 = 20 coins, and you have 50 - 20 = 30 coins left.\n * Vertex 1 \\rightarrow 2: You collect 45 coins on the way. After one minute from the start of the game, you press the button, pay 1 \\times 10 = 10 coins, and you have 45 - 10 = 35 coins left.\n\nThus, the maximum score that can be obtained is 35.\n\n* * *"}, {"input": "2 2 10\n 1 2 100\n 2 2 100", "output": "-1\n \n\n![Figure of the graph given in Sample Input\n2](https://img.atcoder.jp/ghi/eb2188ad1e8189f963d233415fb293b6.png)\n\nThe edge extending from Vertex 1 takes you to Vertex 2. If you then traverse\nthe edge extending from Vertex 2 to itself t times and press the button, your\nscore will be 90 + 90t. Thus, you can infinitely increase your score, which\nmeans there is no maximum value of the score that can be obtained.\n\n* * *"}, {"input": "4 5 10\n 1 2 1\n 1 4 1\n 3 4 1\n 2 2 100\n 3 3 100", "output": "0\n \n\n![Figure of the graph given in Sample Input\n3](https://img.atcoder.jp/ghi/217f7a224b80a05d8e25140c57e65ae7.png)\n\nThere is no way to travel from Vertex 1 to Vertex 4 other than traversing the\nedge leading from Vertex 1 to Vertex 4 directly. You will pick up one coin\nalong this edge, but after being asked to paying 10 coins, your score will be\n0.\n\nNote that you can collect an infinite number of coins if you traverse the edge\nleading from Vertex 1 to Vertex 2, but this is pointless since you can no\nlonger reach Vertex 4 and end the game."}]
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`. * * *
s268821641
Wrong Answer
p02949
Input is given from Standard Input in the following format: N M P A_1 B_1 C_1 : A_M B_M C_M
import heapq class Dijkstra: def __init__(self, rote_map, start_point, goal_point=None): self.rote_map = rote_map self.start_point = start_point self.goal_point = goal_point def execute(self): num_of_city = len(self.rote_map) + 10000 dist = [float("inf") for _ in range(num_of_city)] prev = [float("inf") for _ in range(num_of_city)] dist[self.start_point] = 0 heap_q = [] heapq.heappush(heap_q, (0, self.start_point)) route_count = [0 for _ in range(num_of_city)] route_count[self.start_point] = 1 while len(heap_q) != 0: prev_cost, src = heapq.heappop(heap_q) if dist[src] < prev_cost: continue for dest, cost in self.rote_map[src].items(): if cost != float("inf") and dist[dest] > dist[src] + cost: dist[dest] = dist[src] + cost heapq.heappush(heap_q, (dist[dest], dest)) prev[dest] = src if dist[dest] == dist[src] + cost: route_count[dest] += route_count[src] if self.goal_point is not None: return self._get_path(self.goal_point, prev) else: return dist, route_count def _get_path(self, goal, prev): path = [goal] dest = goal while prev[dest] != float("inf"): path.append(prev[dest]) dest = prev[dest] return list(reversed(path)) N, M, P = map(int, input().split()) items = [] from collections import defaultdict graph = defaultdict(dict) graph2 = defaultdict(dict) for i in range(M): a, b, c = map(int, input().split()) graph[a][b] = c if a != b: graph2[a - 1][b - 1] = 1 if M in graph[M] and graph[M][M] - P > 0: print(-1) exit() res = Dijkstra(graph2, 0, N - 1).execute() if len(res) == 1: print(-1) exit() print(0)
Statement There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N. We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again. When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead. Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
[{"input": "3 3 10\n 1 2 20\n 2 3 30\n 1 3 45", "output": "35\n \n\n![Figure of the graph given in Sample Input\n1](https://img.atcoder.jp/ghi/5cb074e2d7c3282da137ac4ab2fbc700.png)\n\nThere are two ways to travel from Vertex 1 to Vertex 3:\n\n * Vertex 1 \\rightarrow 2 \\rightarrow 3: You collect 20 + 30 = 50 coins on the way. After two minutes from the start of the game, you press the button, pay 2 \\times 10 = 20 coins, and you have 50 - 20 = 30 coins left.\n * Vertex 1 \\rightarrow 2: You collect 45 coins on the way. After one minute from the start of the game, you press the button, pay 1 \\times 10 = 10 coins, and you have 45 - 10 = 35 coins left.\n\nThus, the maximum score that can be obtained is 35.\n\n* * *"}, {"input": "2 2 10\n 1 2 100\n 2 2 100", "output": "-1\n \n\n![Figure of the graph given in Sample Input\n2](https://img.atcoder.jp/ghi/eb2188ad1e8189f963d233415fb293b6.png)\n\nThe edge extending from Vertex 1 takes you to Vertex 2. If you then traverse\nthe edge extending from Vertex 2 to itself t times and press the button, your\nscore will be 90 + 90t. Thus, you can infinitely increase your score, which\nmeans there is no maximum value of the score that can be obtained.\n\n* * *"}, {"input": "4 5 10\n 1 2 1\n 1 4 1\n 3 4 1\n 2 2 100\n 3 3 100", "output": "0\n \n\n![Figure of the graph given in Sample Input\n3](https://img.atcoder.jp/ghi/217f7a224b80a05d8e25140c57e65ae7.png)\n\nThere is no way to travel from Vertex 1 to Vertex 4 other than traversing the\nedge leading from Vertex 1 to Vertex 4 directly. You will pick up one coin\nalong this edge, but after being asked to paying 10 coins, your score will be\n0.\n\nNote that you can collect an infinite number of coins if you traverse the edge\nleading from Vertex 1 to Vertex 2, but this is pointless since you can no\nlonger reach Vertex 4 and end the game."}]
If there exists a maximum value of the score that can be obtained, print that maximum value; otherwise, print `-1`. * * *
s335718141
Wrong Answer
p02949
Input is given from Standard Input in the following format: N M P A_1 B_1 C_1 : A_M B_M C_M
import sys input = sys.stdin.readline n, m, p = map(int, input().split()) abd = [list(map(int, input().split())) for i in range(m)] come = [[] for i in range(n + 1)] for a, b, d in abd: come[b].append(a) visitable = [0] * (n + 1) stack = [n] visitable[n] = 1 while stack: x = stack.pop() for y in come[x]: if visitable[y] == 0: visitable[y] = 1 stack.append(y) score = [10**15 for i in range(n + 1)] score[1] = 0 for j in range(n): flg = 0 for i in range(m): v1, v2, e = abd[i] if visitable[v1] & visitable[v2] == 0: continue e = -e + p if score[v1] != 10**15 and score[v2] > score[v1] + e: score[v2] = score[v1] + e flg = 1 if j == n - 2: last = -score[n] if j == n - 1: onemore = -score[n] if flg == 0: break if flg == 0: print(max(0, -score[n])) else: if last == onemore: print(max(last, 0)) else: print(-1)
Statement There is a directed graph with N vertices numbered 1 to N and M edges. The i-th edge is directed from Vertex A_i to Vertex B_i, and there are C_i coins placed along that edge. Additionally, there is a button on Vertex N. We will play a game on this graph. You start the game on Vertex 1 with zero coins, and head for Vertex N by traversing the edges while collecting coins. It takes one minute to traverse an edge, and you can collect the coins placed along the edge each time you traverse it. As usual in games, even if you traverse an edge once and collect the coins, the same number of coins will reappear next time you traverse that edge, which you can collect again. When you reach Vertex N, you can end the game by pressing the button. (You can also choose to leave Vertex N without pressing the button and continue traveling.) However, when you end the game, you will be asked to pay T \times P coins, where T is the number of minutes elapsed since the start of the game. If you have less than T \times P coins, you will have to pay all of your coins instead. Your score will be the number of coins you have after this payment. Determine if there exists a maximum value of the score that can be obtained. If the answer is yes, find that maximum value.
[{"input": "3 3 10\n 1 2 20\n 2 3 30\n 1 3 45", "output": "35\n \n\n![Figure of the graph given in Sample Input\n1](https://img.atcoder.jp/ghi/5cb074e2d7c3282da137ac4ab2fbc700.png)\n\nThere are two ways to travel from Vertex 1 to Vertex 3:\n\n * Vertex 1 \\rightarrow 2 \\rightarrow 3: You collect 20 + 30 = 50 coins on the way. After two minutes from the start of the game, you press the button, pay 2 \\times 10 = 20 coins, and you have 50 - 20 = 30 coins left.\n * Vertex 1 \\rightarrow 2: You collect 45 coins on the way. After one minute from the start of the game, you press the button, pay 1 \\times 10 = 10 coins, and you have 45 - 10 = 35 coins left.\n\nThus, the maximum score that can be obtained is 35.\n\n* * *"}, {"input": "2 2 10\n 1 2 100\n 2 2 100", "output": "-1\n \n\n![Figure of the graph given in Sample Input\n2](https://img.atcoder.jp/ghi/eb2188ad1e8189f963d233415fb293b6.png)\n\nThe edge extending from Vertex 1 takes you to Vertex 2. If you then traverse\nthe edge extending from Vertex 2 to itself t times and press the button, your\nscore will be 90 + 90t. Thus, you can infinitely increase your score, which\nmeans there is no maximum value of the score that can be obtained.\n\n* * *"}, {"input": "4 5 10\n 1 2 1\n 1 4 1\n 3 4 1\n 2 2 100\n 3 3 100", "output": "0\n \n\n![Figure of the graph given in Sample Input\n3](https://img.atcoder.jp/ghi/217f7a224b80a05d8e25140c57e65ae7.png)\n\nThere is no way to travel from Vertex 1 to Vertex 4 other than traversing the\nedge leading from Vertex 1 to Vertex 4 directly. You will pick up one coin\nalong this edge, but after being asked to paying 10 coins, your score will be\n0.\n\nNote that you can collect an infinite number of coins if you traverse the edge\nleading from Vertex 1 to Vertex 2, but this is pointless since you can no\nlonger reach Vertex 4 and end the game."}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s046029578
Accepted
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
(N, M), *AB = [map(int, s.split()) for s in open(0)] cnt = [1] * N possibly_red = [False] * N possibly_red[0] = True for a, b in AB: a -= 1 b -= 1 cnt[a] -= 1 cnt[b] += 1 if possibly_red[a]: possibly_red[b] = True if cnt[a] == 0: possibly_red[a] = False print(sum(possibly_red))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s331617416
Wrong Answer
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
N, M = list(map(int, input().split())) W = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(M)] BOX = [[1, 1]] BOX.extend([[1, 0] for _ in range(N)]) for i in range(M): BOX[W[i][0]][0] = BOX[W[i][0]][0] - 1 BOX[W[i][1]][0] = BOX[W[i][1]][0] + 1 if BOX[W[i][0]][1] == 1: BOX[W[i][1]][1] = 1 if BOX[W[i][0]][0] == 1: BOX[W[i][0]][1] = 0 print(sum(list(map(lambda x: x[:][1], BOX))))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s035260250
Wrong Answer
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
N, M = [int(hoge) for hoge in input().split()] Ball = [False] * N BallNum = [1] * N Ball[0] = True for i in range(M): x, y = [int(hoge) - 1 for hoge in input().split()] BallNum[x] -= 1 BallNum[y] += 1 Ball[y] = Ball[x] if BallNum[x] == 0: Ball[x] = False print(sum(Ball))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s952250480
Accepted
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
boxnum, sousanum = map(int, input().split(" ")) sousa = [] for i in range(sousanum): sousa.append(list(map(int, input().split(" ")))) # aka[0][0] ...[ボール個数][赤フラグ] ball = [[1, 0] for i in range(boxnum)] ball[0][1] = 1 for i in range(sousanum): if ball[sousa[i][0] - 1][1] == 1: # 赤色あり ball[sousa[i][1] - 1][1] = 1 ball[sousa[i][0] - 1][0] -= 1 ball[sousa[i][1] - 1][0] += 1 if ball[sousa[i][0] - 1][0] == 0: # ボール尽きた ball[sousa[i][0] - 1][1] = 0 total = 0 for i in range(boxnum): total += ball[i][1] print(total)
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s924949397
Wrong Answer
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
N, M = map(int, input().split()) from collections import defaultdict class UnionFind: def __init__(self, n): class KeyDict(dict): # 辞書にないときの対応 def __missing__(self, key): self[key] = key return key self.parent = KeyDict() self.rank = defaultdict(int) self.weight = defaultdict(int) # 根を探す def find(self, x): if self.parent[x] == x: return x else: # 経路圧縮 # 自分自身じゃない場合は、上にさかのぼって検索(再帰的に) y = self.find(self.parent[x]) self.weight[x] += self.weight[self.parent[x]] # 圧縮時にweightを更新(和) self.parent[x] = y # 親の置き換え(圧縮) return self.parent[x] # 結合 def union(self, x, y): x = self.find(x) y = self.find(y) # 低い方を高い方につなげる(親のランクによる) if self.rank[x] < self.rank[y]: self.parent[x] = y else: self.parent[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 ### 重み付き def weighted_union(self, x, y, w): # print("unite",x,y,w,self.weight) px = self.find(x) py = self.find(y) # 低い方を高い方につなげる(親のランクによる) # if px == py: return 0 if self.rank[px] < self.rank[py]: self.parent[px] = py self.weight[px] = -w - self.weight[x] + self.weight[y] else: self.parent[py] = px self.weight[py] = w + self.weight[x] - self.weight[y] if self.rank[px] == self.rank[py]: self.rank[px] += 1 return 0 # 判定 def judge(self, x, y): return self.find(x) == self.find(y) uf = UnionFind(N) dp = [1] * N for i in range(M): xi, yi = map(int, input().split()) xi -= 1 yi -= 1 dp[xi] -= 1 dp[yi] += 1 if not uf.judge(xi, yi): uf.union(xi, yi) ans = 0 p = uf.find(0) for i in range(1, N): if uf.find(i) == p and dp[i] != 0: ans += 1 print(ans)
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s769332505
Accepted
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
#!/usr/bin/env python3 (n, m), *q = [[*map(int, i.split())] for i in open(0)] b = [1] + [0] * (n - 1) c = [1] * n for x, y in q: c[x - 1] -= 1 c[y - 1] += 1 b[y - 1] |= b[x - 1] if c[x - 1] == 0: b[x - 1] = 0 print(sum(b))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s762958109
Wrong Answer
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
n, *l = map(int, open(0).read().split()) a = [0, 1] + [0] * n b = [1] * -~n for i, j in zip(l[1::2], l[2::2]): a[j] |= a[i] b[i] -= 1 b[j] += 1 a[i] &= b[i] print(sum(a))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s866352109
Runtime Error
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
A, B = map(int, input().split()) b = [] Zeroflag = False count = 0 for i in range(A, B + 1, 1): b.append(i) if 0 in b: zeroflag = True for i in b: if i < 0: count += 1 if zeroflag: print("Zero") elif count % 2 == 0: print("Positive") else: print("Negative")
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s280688326
Accepted
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
n, m = map(int, input().split()) prob = [False] * (n + 1) exact = [False] * (n + 1) prob[1] = exact[1] = True num_in = [1] * (n + 1) for _ in range(m): x, y = map(int, input().split()) if num_in[x] == 1 and exact[x]: exact[y] = True exact[x] = False prob[x] = False prob[y] = True elif num_in[x] > 1 and exact[x]: exact[x] = False prob[y] = True elif prob[x]: if num_in[x] == 1: prob[x] = False prob[y] = True num_in[y] += 1 num_in[x] -= 1 print(prob.count(True))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s919153747
Accepted
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
# https://atcoder.jp/contests/agc002/tasks/agc002_b import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv)) # 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと def read_a_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def read_col(H): """H is number of rows A列、B列が与えられるようなとき ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合""" ret = [] for _ in range(H): ret.append(list(map(int, read().split()))) return tuple(map(list, zip(*ret))) N, M = read_ints() X, Y = read_col(M) X = mina(*X) Y = mina(*Y) # 有向グラフでつないで1からbfsで到達するノードの数を記録する?#順序情報が消えてしまう # ただ単純に赤の可能性のある配列を用意しておけばいいんじゃない? # ボールの個数も管理しないと prob = [False] * N n_balls = [1] * N prob[0] = True for x, y in zip(X, Y): prob[y] = prob[y] or prob[x] n_balls[x] -= 1 n_balls[y] += 1 if n_balls[x] == 0: prob[x] = False print(sum(prob))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s971092719
Runtime Error
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def STR(): return input() def INT(): return int(input()) def MAP(): return map(int, input().split()) def S_MAP(): return map(str, input().split()) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) inf = sys.maxsize mod = 10 ** 9 + 7 n, m = MAP() red = [False for _ in range(n)] bal = [1 for _ in range(n)] red[0] = 1 for i in range(m): x, y = MAP() if red[x - 1]: red[y - 1] = True if bal[x - 1] == 1: red[x - 1] = False bal[x - 1] -= 1 bal[y - 1] += 1 print(sum(red))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s236811391
Runtime Error
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
def solve(): N, M = map(int, input().split()) num = [] red = [] for i in range(N+1): num.append(1) red.append(0) red[1] = 1 for _ range(M): x, y = map(int, input().split()) if red[x] == 1: red[y] = 1 num[x] -= 1 num[y] += 1 if num[x] == 0: red[x] = 0 return sum(red) print(solve())
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s663479674
Runtime Error
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
N, M = map(int, input().split()) action = [list(map(int, input().split())) for i in range(M)] for i in range(M): if action[i][0] == 1 and action[i][1] == 2: N -= 1 elif i != 1: if action[i][0] int action and action[i][1] in action: N -= 1 print(N)
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s923281937
Runtime Error
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
import sys, re, os from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from itertools import permutations, combinations, product, accumulate from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from fractions import gcd def input(): return sys.stdin.readline().strip() def STR(): return input() def INT(): return int(input()) def MAP(): return map(int, input().split()) def S_MAP(): return map(str, input().split()) def LIST(): return list(map(int, input().split())) def S_LIST(): return list(map(str, input().split())) sys.setrecursionlimit(10 ** 9) inf = sys.maxsize mod = 10 ** 9 + 7 n, m = MAP() red = [False for _ in range(n)] bal = [1 for _ in range(n)] red[0] = 1 for i in range(m): x, y = MAP() if red[x - 1]: red[y - 1] = True if bal[x - 1] == 1: red[x - 1] = False bal[x - 1] -= 1 bal[y - 1] += 1 print(sum(red))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s273211718
Wrong Answer
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
n, m = map(int, input().split()) a = [[int(i) for i in input().split()] for i in range(m)] p = ["f"] * n p[0] = "t" q = [1] * n for i in range(0, m): if p[a[i][0] - 1] == "t": p[a[i][1] - 1] = "t" q[a[i][0] - 1] -= 1 q[a[i][1] - 1] += 1 if q[a[i][0] - 1] == 0: p[a[i][0] - 1] = "f" print(p.count("t"))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the number of boxes that may contain the red ball after all operations are performed. * * *
s896131346
Accepted
p04034
The input is given from Standard Input in the following format: N M x_1 y_1 : x_M y_M
N, M = map(int, input().split()) XY = [list(map(int, input().split())) for _ in range(M)] """ ボールの数が入ったリストと,赤い玉が一回でもきたことがあるかのリスト どちらもが0じゃないのが,終わったときに赤が入っている可能性のあるリスト ただし,ボールリストが0になる時,seenは0になる """ ball_list = [1] * (N + 1) seen = [0] * (N + 1) ball_list[0] = 0 seen[1] = 1 for i in range(M): x = XY[i][0] y = XY[i][1] if seen[x] == 1: seen[y] = 1 ball_list[x] -= 1 ball_list[y] += 1 if ball_list[x] == 0: seen[x] = 0 else: ball_list[x] -= 1 ball_list[y] += 1 print(seen.count(1))
Statement We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may contain the red ball after all operations are performed.
[{"input": "3 2\n 1 2\n 2 3", "output": "2\n \n\nJust after the first operation, box 1 is empty, box 2 contains one red ball\nand one white ball, and box 3 contains one white ball.\n\nNow, consider the second operation. If Snuke picks the red ball from box 2,\nthe red ball will go into box 3. If he picks the white ball instead, the red\nball will stay in box 2. Thus, the number of boxes that may contain the red\nball after all operations, is 2.\n\n* * *"}, {"input": "3 3\n 1 2\n 2 3\n 2 3", "output": "1\n \n\nAll balls will go into box 3.\n\n* * *"}, {"input": "4 4\n 1 2\n 2 3\n 4 1\n 3 4", "output": "3"}]
Print the maximum number of times the operation can be applied. * * *
s116625139
Wrong Answer
p02660
Input is given from Standard Input in the following format: N
def solve(): n = int(input()) p = [2] A = 10000 for L in range(3, A, 2): # 2 以外の素数は奇数なので if all(L % L2 != 0 for L2 in p): # すべての既存素数で割り切れなかったら素数 p.append(L) z = [] for i in p: for e in range(1, 20): if n % i**e == 0 and i**e not in z: n /= i**e z.append(i**e) if not z: z.append(n) return len(z) print(solve())
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s683896348
Runtime Error
p02660
Input is given from Standard Input in the following format: N
from sympy import divisors, factorint n = int(input()) yakus = divisors(n) ns = set() zs = set() ns.add(n) for z in yakus: d = factorint(z) if ( len(d) == 1 and n % z == 0 and not int(n / z) in ns and int(n / z) != 1 and int(n / z) != 0 and not z in zs ): zs.add(z) n = int(n / z) ns.add(n) if 1 in ns: ns.remove(1) if 0 in ns: ns.remove(0) ns = [n for n in ns if not n in zs] print(len(ns))
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s298882478
Wrong Answer
p02660
Input is given from Standard Input in the following format: N
s = list(map(int, input().split())) li = s[0] counter = 0 if li % 2 == 0: counter += 1 li = li // 2 if li == 1: print(counter) if li % 3 == 0: counter += 1 li = li // 3 if li == 1: print(counter) if li % 4 == 0: counter += 1 li = li // 4 if li == 1: print(counter)
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s843061512
Runtime Error
p02660
Input is given from Standard Input in the following format: N
n= int(input()) import sympy primes= list(sympy.primerange(1, 10**6)) prime_factors= {} while n != 1: for p in primes: if n%p==0: if p in prime_factors: prime_factors[p]+=1 else: prime_factors[p]=1 n/= p break elif p==999983: prime_factors[n]=1 n=1 break tot= 0 for p in prime_factors: if prime_factors[p]>=36: tot+= 8 elif prime_factors[p]>=28: tot+=7 elif prime_factors[p]>=21: tot+=6 elif prime_factors[p]>=15: tot+=5 elif prime_factors[p]>=10: tot+=4 elif prime_factors[p]>=6: tot+=3 elif prime_factors[p]>=3: tot+=2 else: tot+=1 print(tot)
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s029269502
Accepted
p02660
Input is given from Standard Input in the following format: N
import random def primesbelow(N): # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188 # """ Input N>=6, Returns a list of primes, 2 <= p < N """ correction = N % 6 > 1 N = {0: N, 1: N - 1, 2: N + 4, 3: N + 3, 4: N + 2, 5: N + 1}[N % 6] sieve = [True] * (N // 3) sieve[0] = False for i in range(int(N**0.5) // 3 + 1): if sieve[i]: k = (3 * i + 1) | 1 sieve[k * k // 3 :: 2 * k] = [False] * ( (N // 6 - (k * k) // 6 - 1) // k + 1 ) sieve[(k * k + 4 * k - 2 * k * (i % 2)) // 3 :: 2 * k] = [False] * ( (N // 6 - (k * k + 4 * k - 2 * k * (i % 2)) // 6 - 1) // k + 1 ) return [2, 3] + [(3 * i + 1) | 1 for i in range(1, N // 3 - correction) if sieve[i]] smallprimeset = set(primesbelow(100000)) _smallprimeset = 100000 def isprime(n, precision=7): # http://en.wikipedia.org/wiki/Miller-Rabin_primality_test#Algorithm_and_running_time if n < 1: raise ValueError("Out of bounds, first argument must be > 0") elif n <= 3: return n >= 2 elif n % 2 == 0: return False elif n < _smallprimeset: return n in smallprimeset d = n - 1 s = 0 while d % 2 == 0: d //= 2 s += 1 for repeat in range(precision): a = random.randrange(2, n - 2) x = pow(a, d, n) if x == 1 or x == n - 1: continue for r in range(s - 1): x = pow(x, 2, n) if x == 1: return False if x == n - 1: break else: return False return True # https://comeoncodeon.wordpress.com/2010/09/18/pollard-rho-brent-integer-factorization/ def pollard_brent(n): if n % 2 == 0: return 2 if n % 3 == 0: return 3 y, c, m = ( random.randint(1, n - 1), random.randint(1, n - 1), random.randint(1, n - 1), ) g, r, q = 1, 1, 1 while g == 1: x = y for i in range(r): y = (pow(y, 2, n) + c) % n k = 0 while k < r and g == 1: ys = y for i in range(min(m, r - k)): y = (pow(y, 2, n) + c) % n q = q * abs(x - y) % n g = gcd(q, n) k += m r *= 2 if g == n: while True: ys = (pow(ys, 2, n) + c) % n g = gcd(abs(x - ys), n) if g > 1: break return g smallprimes = primesbelow( 1000 ) # might seem low, but 1000*1000 = 1000000, so this will fully factor every composite < 1000000 def primefactors(n, sort=False): factors = [] for checker in smallprimes: while n % checker == 0: factors.append(checker) n //= checker if checker > n: break if n < 2: return factors while n > 1: if isprime(n): factors.append(n) break factor = pollard_brent( n ) # trial division did not fully factor, switch to pollard-brent factors.extend( primefactors(factor) ) # recurse to factor the not necessarily prime factor returned by pollard-brent n //= factor if sort: factors.sort() return factors def factorization(n): factors = {} for p1 in primefactors(n): try: factors[p1] += 1 except KeyError: factors[p1] = 1 return factors totients = {} def totient(n): if n == 0: return 1 try: return totients[n] except KeyError: pass tot = 1 for p, exp in factorization(n).items(): tot *= (p - 1) * p ** (exp - 1) totients[n] = tot return tot def gcd(a, b): if a == b: return a while b > 0: a, b = b, a % b return a def lcm(a, b): return abs((a // gcd(a, b)) * b) l = [ 0, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 0, 0, 0, 0, 0, ] N = int(input()) choice = 0 x = 0 ans = 0 dic = factorization(N) for key in dic.keys(): ans += l[dic[key]] print(ans)
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s187501440
Wrong Answer
p02660
Input is given from Standard Input in the following format: N
N = int(input()) x = 0 a = [] for i in range(2, N + 1): b = 1 l = len(a) for j in range(l): if (i % a[j]) == 0: b = 0 a.append(i) if b == 1: i2 = i if N == 1: break while N % i2 == 0 & N != 1: N //= i2 x += 1 i2 *= i2 i += 1 else: continue print(x)
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s341196802
Accepted
p02660
Input is given from Standard Input in the following format: N
# coding: utf-8 from math import sqrt def solve(*args: str) -> str: n = int(args[0]) ret = 0 i = 2 sqrt_n = -int(-sqrt(n)) P = [True] * (sqrt_n + 1) P[0] = False P[1] = False for i in range(2, len(P)): if P[i]: for j in range(i + i, len(P), i): P[j] = False Q = [] for p, is_prime in enumerate(P): if is_prime and n % p == 0: t = p while t <= n: Q.append(t) t *= p if not Q and 1 < n: Q.append(n) Q.sort() for q in Q: if n % q == 0: n //= q ret += 1 for p, is_prime in enumerate(P): while is_prime and n % p == 0: n //= p if 1 < n: ret += 1 return str(ret) if __name__ == "__main__": print(solve(*(open(0).read().splitlines())))
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s946621532
Wrong Answer
p02660
Input is given from Standard Input in the following format: N
N = int(input()) primeNum = [ 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, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, ] pow = 1 time = 0 while True: for p in primeNum: z = p**pow if p <= N: if N % z == 0: N = int(N / (z)) time += 1 print(N) else: break pow += 1 if pow >= N: break print(time)
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s713219376
Wrong Answer
p02660
Input is given from Standard Input in the following format: N
a = int(input()) list = [] b = 1 for i in range(2, 44): list.append(b) b = b + i n = 0 e = 0 k = 0 for i in range(2, 1000000): if a % i == 0: warikaisi = True while warikaisi: if a % i == 0: list.append(i) a = a / i e = e + 1 if e == list[k]: n = n + 1 k = k + 1 else: e = 0 k = 0 warikaisi = False if n == 0 and a != 1: n = 1 if a >= 1000000: n = n + 1 print(n)
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s728530886
Accepted
p02660
Input is given from Standard Input in the following format: N
def resolve(): answer = 0 N = int(input()) if N==1: print(answer) else: # 素因数pを見つける。範囲は2から√Nまででよい。 for p in range(2, int(N**0.5)+2): e = 0 while (N % p == 0): N /= p e += 1 # z=p**eが見つかった if e>0: # eを1, 2, 3, 4...に分けられる回数カウント for i in range(1, e+1): if e >= i: e -= i answer += 1 # √Nまでで割り切れなかった場合、N自身が素数 if N!=1: answer += 1 print(answer) resolve()
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Print the maximum number of times the operation can be applied. * * *
s629739927
Accepted
p02660
Input is given from Standard Input in the following format: N
# 入力 N = input() N = int(N) # 素因数分解 L = [] M = [] Nu = N for i in range(2, int(-(-(N**0.5) // 1)) + 1): if Nu % i == 0: j = 0 while Nu % i == 0: j += 1 Nu //= i # L.append(i) M.append(j) if Nu != 1: # L.appnend(Nu) M.append(1) if M == []: if N != 1: # L.append(N) M.append(1) else: M.append(0) # 階差数列 l = max(M) p = 0 P = [] for i in range(1, l + 1): p += i P.append(p) # 計算 Answer = 0 l = len(M) for i in range(l): m = M[i] if m != 0: while not (m in P): m -= 1 Index = P.index(m) Index += 1 Answer += Index print(Answer)
Statement Given is a positive integer N. Consider repeatedly applying the operation below on N: * First, choose a positive integer z satisfying all of the conditions below: * z can be represented as z=p^e, where p is a prime number and e is a positive integer; * z divides N; * z is different from all integers chosen in previous operations. * Then, replace N with N/z. Find the maximum number of times the operation can be applied.
[{"input": "24", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=12.)\n * Choose z=3 (=3^1). (Now we have N=4.)\n * Choose z=4 (=2^2). (Now we have N=1.)\n\n* * *"}, {"input": "1", "output": "0\n \n\nWe cannot apply the operation at all.\n\n* * *"}, {"input": "64", "output": "3\n \n\nWe can apply the operation three times by, for example, making the following\nchoices:\n\n * Choose z=2 (=2^1). (Now we have N=32.)\n * Choose z=4 (=2^2). (Now we have N=8.)\n * Choose z=8 (=2^3). (Now we have N=1.)\n\n* * *"}, {"input": "1000000007", "output": "1\n \n\nWe can apply the operation once by, for example, making the following choice:\n\n * z=1000000007 (=1000000007^1). (Now we have N=1.)\n\n* * *"}, {"input": "997764507000", "output": "7"}]
Output an integer representing the minimum total cost. * * *
s542892501
Accepted
p03972
Inputs are provided from Standard Input in the following form. W H p_0 : p_{W-1} q_0 : q_{H-1}
t, *p = open(0) w, h = map(int, t.split()) c = 0 for v, f in sorted((int(t), i < w) for i, t in enumerate(p)): c -= ~h * v * f or ~w * v w -= f h -= 1 ^ f print(c)
Statement On an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers. There are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y coordinates are equal and the difference between the x coordinates is 1. The cost of paving a road between houses on coordinates (i,j) and (i+1,j) is p_i for any value of j, while the cost of paving a road between houses on coordinates (i,j) and (i,j+1) is q_j for any value of i. Mr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.
[{"input": "2 2\n 3\n 5\n 2\n 7", "output": "29\n \n\nIt is enough to pave the following eight roads.\n\n * Road connecting houses at (0,0) and (0,1)\n * Road connecting houses at (0,1) and (1,1)\n * Road connecting houses at (0,2) and (1,2)\n * Road connecting houses at (1,0) and (1,1)\n * Road connecting houses at (1,0) and (2,0)\n * Road connecting houses at (1,1) and (1,2)\n * Road connecting houses at (1,2) and (2,2)\n * Road connecting houses at (2,0) and (2,1)\n\n* * *"}, {"input": "4 3\n 2\n 4\n 8\n 1\n 2\n 9\n 3", "output": "60"}]
Output an integer representing the minimum total cost. * * *
s864803722
Wrong Answer
p03972
Inputs are provided from Standard Input in the following form. W H p_0 : p_{W-1} q_0 : q_{H-1}
from collections import deque def a_contains_b(a, b): for e in b: if e not in a: return False return True inputs = input().split() W = int(inputs[0]) H = int(inputs[1]) p = [] q = [] for i in range(W): p.append(int(input())) for i in range(H): q.append(int(input())) ##W = 2 ##H = 2 ##p = [3, 5] # moving horizontally ##q = [2, 7] # moving vertically ##W = 4 ##H = 3 ##p = [2, 4, 8, 1] ##q = [2, 9, 3] # list of roads. each road is defined using starting point and ending point # list of points that should be reachable i.e. every point on the grid points = [] for j in range(H + 1): row = [] for i in range(W + 1): row.append((i, j)) points.append((i, j)) ##print(points) num_points = (H + 1) * (W + 1) ##visited = [['F' for i in range(W)] for j in range(H+1)] queue = deque() queue.append(((0, 0), [(0, 0)], 0)) # current point, list of points visited, total cost ##visited[0][0] = 'T' min_cost = float("inf") max_path_length = float("-inf") max_path_costs = [] while queue: curr = queue.popleft() x = curr[0][0] y = curr[0][1] path_list = curr[1] cost = curr[2] ## print(path_list) n_move = (x, y - 1) s_move = (x, y + 1) w_move = (x - 1, y) e_move = (x + 1, y) num_moves = 0 # N if y - 1 >= 0 and n_move not in path_list: z = list(path_list) z.append(n_move) queue.append((n_move, z, cost + q[y - 1])) num_moves += 1 # S if y + 1 <= H and s_move not in path_list: z = list(path_list) z.append(s_move) queue.append((s_move, z, cost + q[y])) num_moves += 1 # E if x + 1 <= W and e_move not in path_list: z = list(path_list) z.append(e_move) queue.append((e_move, z, cost + p[x])) num_moves += 1 # W if x - 1 >= 0 and w_move not in path_list: z = list(path_list) z.append(w_move) queue.append((w_move, z, cost + p[x - 1])) num_moves += 1 ## if cost == 60: ## print(path_list) ## print(points) # if we cannot move anywhere else and all points have been visited, then we check length if a_contains_b(path_list, points): ## print(path_list) ## if len(path_list) > max_path_length: ## max_path_costs = [cost] ## max_path_length = len(path_list) ## elif len(path_list) == max_path_length: max_path_costs.append(cost) ##print(max_path_costs) print(min(max_path_costs)) ## if cost < min_cost: ## print('path_list: {}'.format(path_list)) ## print('cost: {}'.format(cost)) ## min_cost = cost
Statement On an xy plane, in an area satisfying 0 ≤ x ≤ W, 0 ≤ y ≤ H, there is one house at each and every point where both x and y are integers. There are unpaved roads between every pair of points for which either the x coordinates are equal and the difference between the y coordinates is 1, or the y coordinates are equal and the difference between the x coordinates is 1. The cost of paving a road between houses on coordinates (i,j) and (i+1,j) is p_i for any value of j, while the cost of paving a road between houses on coordinates (i,j) and (i,j+1) is q_j for any value of i. Mr. Takahashi wants to pave some of these roads and be able to travel between any two houses on paved roads only. Find the solution with the minimum total cost.
[{"input": "2 2\n 3\n 5\n 2\n 7", "output": "29\n \n\nIt is enough to pave the following eight roads.\n\n * Road connecting houses at (0,0) and (0,1)\n * Road connecting houses at (0,1) and (1,1)\n * Road connecting houses at (0,2) and (1,2)\n * Road connecting houses at (1,0) and (1,1)\n * Road connecting houses at (1,0) and (2,0)\n * Road connecting houses at (1,1) and (1,2)\n * Road connecting houses at (1,2) and (2,2)\n * Road connecting houses at (2,0) and (2,1)\n\n* * *"}, {"input": "4 3\n 2\n 4\n 8\n 1\n 2\n 9\n 3", "output": "60"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s862026464
Runtime Error
p03421
Input is given from Standard Input in the following format: N A B
//header #define set_header 1 #ifdef set_header #include <bits/stdc++.h> #ifdef LOCAL #include "cxx-prettyprint-master/prettyprint.hpp" #define print(x) cout << x << endl #else #define print(...) 42 #endif using namespace std; using ll = long long; #define INF 1'010'000'000'000'000'017LL #define mod 998244353LL #define eps 0.0001 #define all(x) (x).begin(), (x).end() #define reverse(x) (x).rbegin(), (x).rend() #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define SZ(x) ((ll)(x).size()) #define sum(x) accumulate(ALL(x), 0LL)//? #define pb(x) push_back(x) typedef pair < ll , ll >P; ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; template< typename T > T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n; public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}}; uint64_t my_rand(void) { static uint64_t x = 88172645463325252ULL; x = x ^ (x << 13); x = x ^ (x >> 7); return x = x ^ (x << 17); } #endif //library //main int main() { int N, A, B; cin >> N >> A >> B; if(N+1<A+B || N>A*B){ cout << -1 << endl; return 0; } int tmp = N; vector<int> ans(0); for(int i = B;i>0;i--)ans.pb(i); tmp-=B; int now = B+1; for(int a = A-1;a>0;a--){ int q = tmp/a; tmp -=q; for(int b = now+q-1;b>=now;b--) ans.pb(b); now+=q; } rep(i, N) cout << ans[i] <<' '; cout << endl; }
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s125563409
Wrong Answer
p03421
Input is given from Standard Input in the following format: N A B
print(-1)
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s366319632
Wrong Answer
p03421
Input is given from Standard Input in the following format: N A B
import sys readline = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) def readstr(): return readline().rstrip().decode() def readstrs(): return list(readline().decode().split()) def readint(): return int(readline()) def readints(): return list(map(int, readline().split())) def printrows(x): print("\n".join(map(str, x))) n, a, b = readints() if a + b - 1 > n: ans = -1 else: if (a * (a - 1) + b * (b + 1)) // 2 >= n: ans = [] B = 0 A = n + 1 blen = b alen = a - 1 flag = 1 while B + 1 != A: lim = min(B + blen, A - 1) for i in range(lim, B, -1): ans.append(i) B = lim blen -= 1 lim = max(A - alen, B + 1) for i in range(lim, A): ans.append(i) A = lim alen -= 1 elif (a * (a + 1) + b * (b - 1)) // 2 >= n: ans = [] B = 0 A = n + 1 blen = b - 1 alen = a flag = 1 while B + 1 != A: lim = max(A - alen, B + 1) for i in range(lim, A): ans.append(i) A = lim alen -= 1 lim = min(B + blen, A - 1) for i in range(lim, B, -1): ans.append(i) B = lim blen -= 1 else: ans = -1 if ans == -1: print(ans) else: printrows(ans)
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s670308177
Wrong Answer
p03421
Input is given from Standard Input in the following format: N A B
N, A, B = map(int, input().split()) l = list(range(1, N + 1)) t = 0 s = "" S = "" if N // max(A, B) == min(A, B): if A > B: while l: t += A s = "" while t: if len(l) == 0: break s = str(l.pop()) + " " + s t -= 1 S += s elif A <= B: while l: t += B s = "" while t: if len(l) == 0: break s += " " + str(l.pop()) t -= 1 S = s + S elif A + B - 1 <= N: p = N // max(A, B) if A > B: tk = l[: B - p - 1] l = l[B - 1 - p :] while l: t += A s = "" while t: if len(l) == 0: break s = str(l.pop()) + " " + s t -= 1 S += s kk = "" for i in tk[::-1]: S += " " + str(i) elif A < B: tk = l[: A - p - 2] l = l[A - p - 2 :] while l: t += B s = "" while t: if len(l) == 0: break s += " " + str(l.pop()) t -= 1 S = s + S kk = "" S = S[1:] for i in tk: S = str(i) + " " + S elif A == B: tk = l[: A - p] l = l[A - p :] while l: t += B s = "" while t: if len(l) == 0: break s += " " + str(l.pop()) t -= 1 S = s + S kk = "" S = S[1:] for i in tk: S = str(i) + " " + S else: S = -1 print(S)
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s354415826
Wrong Answer
p03421
Input is given from Standard Input in the following format: N A B
import sys # from collections import defaultdict, deque # import math # import copy # from bisect import bisect_left, bisect_right # import heapq # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = 10**20 MOD = 1000000007 class Segtree_op: def __init__(self, n): self.size = 1 while n >= 1: self.size = self.size << 1 n = n // 2 self.arr = [self.unit() for i in range(self.size * 2)] def op(self, lch, rch): # update min with holding index return max(lch, rch) def unit(self): return -INF def update(self, k, val): k += self.size - 1 self.arr[k] = val while k: k = (k - 1) // 2 self.arr[k] = self.op(self.arr[k * 2 + 1], self.arr[k * 2 + 2]) def query(self, l, r): L = l + self.size R = r + self.size s = self.unit() while L < R: if R & 1: R -= 1 s = self.op(s, self.arr[R - 1]) if L & 1: s = self.op(s, self.arr[L - 1]) L += 1 L >>= 1 R >>= 1 return s def show(self): idx = 1 while idx <= self.size: print(self.arr[idx - 1 : idx * 2 - 1]) idx *= 2 def solve(): n, a, b = getList() a, b = b, a if n < a + b - 1: print(-1) return if n > 2 * a + 2 * b - 3: print(-1) return if n == a + b - 1: ans = list(reversed([i for i in range(1, a + 1)])) + [ i for i in range(a + 1, n + 1) ] print(*ans) return daini = min(n - a - b + 1, b - 1) ni = list(reversed([i for i in range(a + b, a + b + daini - 1)])) if n > a + b - 1 + daini: daisan = n - a - b + 1 - daini san = [i for i in range(n - daisan, n + 1)] else: san = [] ans = ( list(reversed([i for i in range(1, a + 1)])) + ni + san + [i for i in range(a + 1, a + b)] ) print(*ans) def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": # main() solve()
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s712987554
Wrong Answer
p03421
Input is given from Standard Input in the following format: N A B
n, a, b = map(int, input().split()) print(-1)
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s640331057
Runtime Error
p03421
Input is given from Standard Input in the following format: N A B
N, A, B = map(int,input().split()) if A+B > N+1: print(-1) else: ans1 = [i+1 for i in range(A-1)] ans2 = [j for j in range(N,A-1,-1)] print(ans1+ans2)
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s905519459
Wrong Answer
p03421
Input is given from Standard Input in the following format: N A B
n, a, b = input().split() n, a, b = int(n), int(a), int(b) toshow = [] flag = False if a + b > n + 1 or (a != n and b == 1) or (b != n and a == 1): toshow = [-1] elif n % 2 == 0: if a < n // 2: a, b = b, a flag = True i = -1 for i in range(a - n // 2): toshow.append(i * 2 + 1) toshow.append(i * 2 + 2) buf = [] j = i for j in range(i + 1, i + b - 1): buf.append(j * 2 + 1) toshow.append(j * 2 + 2) buf.reverse() for k in range(j + 1, n // 2): toshow.append(k * 2 + 2) toshow.append(k * 2 + 1) for l in buf[:-1]: toshow.append(l) if len(buf) > 0: toshow.append(buf[-1]) if flag: toshow.reverse() else: if a < (n + 1) // 2: a, b = b, a flag = True buf = [] i = -1 for i in range(b - 2): buf.append(i * 2 + 1) toshow.append(i * 2 + 2) buf.reverse() j = i for j in range(i + 1, i + a - (n + 1) // 2): toshow.append(j * 2 + 1) toshow.append(j * 2 + 2) for k in range(j + 1, (n + 1) // 2): if k * 2 + 1 < n: toshow.append(k * 2 + 2) toshow.append(k * 2 + 1) for l in buf[:-1]: toshow.append(l) if len(buf) > 0: toshow.append(buf[-1]) if flag: toshow.reverse() for i in toshow[:-1]: print(i, end=" ") print(toshow[-1])
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
If there are no sequences that satisfy the conditions, print `-1`. Otherwise, print N integers. The i-th integer should be the i-th element of the sequence that you constructed. * * *
s389621732
Wrong Answer
p03421
Input is given from Standard Input in the following format: N A B
from collections import defaultdict, Counter from itertools import product, groupby, count, permutations, combinations from math import pi, sqrt from collections import deque from bisect import bisect, bisect_left, bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF = float("inf") YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no" dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0] dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1] def inside(y, x, H, W): return 0 <= y < H and 0 <= x < W def ceil(a, b): return (a + b - 1) // b def lis(A): N = len(A) LIS = [] for i in range(N): index = bisect_left(LIS, A[i]) if index >= len(LIS): LIS.append(A[i]) else: LIS[index] = A[i] return len(LIS) def func(A): return lis(A), lis([-1 * a for a in A]) def solve(N, A, B): if abs(N - (A + B)) > 1: return [-1] ans = [] now = 1 num = 0 while now <= N: for i in range(min(N, now + B - 1), now - 1, -1): ans.append(i) now += B num += 1 rest = N - now + 1 if 1 + rest - B < A - num: break for _ in range(A - num - 1): ans.append(now) now += 1 num += 1 if now == N: break use = False for i in range(N, now - 1, -1): ans.append(i) use = True if num + use != A: return [-1] return ans def check(N, A, B): for p in permutations(range(1, N + 1)): if (A, B) == func(list(p)): return list(p) return [-1] def main(): N, A, B = map(int, input().split()) ans = solve(N, A, B) print(*ans) if __name__ == "__main__": main()
Statement Determine if there exists a sequence obtained by permuting 1,2,...,N that satisfies the following conditions: * The length of its longest increasing subsequence is A. * The length of its longest decreasing subsequence is B. If it exists, construct one such sequence.
[{"input": "5 3 2", "output": "2 4 1 5 3\n \n\nOne longest increasing subsequence of this sequence is {2,4,5}, and one\nlongest decreasing subsequence of it is {4,3}.\n\n* * *"}, {"input": "7 7 1", "output": "1 2 3 4 5 6 7\n \n\n* * *"}, {"input": "300000 300000 300000", "output": "-1"}]
Print the maximum number of coins you can get. * * *
s158560364
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
A, B = int(input()) h = [2 * A - 1, 2 * B - 1, A + B] maxvalue = 0 for i in range(len(h)): if h[i] >= maxvalue: maxvalue = h[i] print(maxvalue)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s540185755
Accepted
p03071
Input is given from Standard Input in the following format: A B
A, B = map(int, input().rstrip().split(" ")) print(max(A + B, A * 2 - 1, B * 2 - 1))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s318086330
Accepted
p03071
Input is given from Standard Input in the following format: A B
c = [int(i) for i in input().split()] print(max(sum(c), 2 * max(c) - 1))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s747848241
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
print(max(list(map(int, input().split()))) * 2 - 1)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s754161092
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
q = list(map(int, input().split())) print(max(q) * 2 - (q[1] != q[2]))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s592808468
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
A, B = map(int, input()) print(max(A, B) + max(A, B) - 1)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s837312124
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
s = list(input()) N = len(s) cont = 0 for i in range(1, N): if s[i - 1] == s[i]: cont += 1 if s[i] == "0": del s[i] s.insert(i, "1") else: del s[i] s.insert(i, "0") print(cont)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s940729039
Accepted
p03071
Input is given from Standard Input in the following format: A B
X = [int(x) for x in input().split()] X.append(X[0] - 1) X.append(X[1] - 1) X.sort() print(X[-1] + X[-2])
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s656184745
Accepted
p03071
Input is given from Standard Input in the following format: A B
n = list(map(int, input().split())) b1 = max(n) n[n.index(b1)] -= 1 print(b1 + max(n))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s379342424
Accepted
p03071
Input is given from Standard Input in the following format: A B
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 A, B = MAP() if A == B: print(A * 2) else: print(max(A, B) * 2 - 1)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s464743186
Accepted
p03071
Input is given from Standard Input in the following format: A B
import sys read = sys.stdin.readline def read_ints(): return list(map(int, read().split())) def read_a_int(): return int(read()) def read_matrix(H): """ H is number of rows """ return [list(map(int, read().split())) for _ in range(H)] def read_map(H): """ H is number of rows 文字列で与えられた盤面を読み取る用 """ return [read() for _ in range(H)] def read_col(H, n_cols): """ H is number of rows n_cols is number of cols A列、B列が与えられるようなとき """ ret = [[] for _ in range(n_cols)] for _ in range(H): tmp = list(map(int, read().split())) for col in range(n_cols): ret[col].append(tmp[col]) return ret A, B = read_ints() if A == B: print(A + B) else: tmp = max(A, B) print(tmp + tmp - 1)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s211875237
Accepted
p03071
Input is given from Standard Input in the following format: A B
a = 0 b = 0 s = list(map(int, input().split())) if s[0] == s[1]: print(2 * s[0]) b = 1 elif s[0] > s[1]: a = s[0] s[0] = s[0] - 1 else: a = s[1] s[1] = s[1] - 1 if s[0] == s[1]: a = a + s[0] elif s[0] > s[1]: a = a + s[0] else: a = a + s[1] if b == 0: print(a)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s101931815
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
N, K = [int(c) for c in input().split()] S = [int(c) for c in input()] longest = 0 for bgn_flip in range(len(S)): S_copy = S[:] zero = False icluster = -1 for i, s in enumerate(S): if s == 0 and zero == False: zero = True icluster += 1 if s == 1: zero = False if s == 0 and icluster >= bgn_flip and icluster < bgn_flip + K: S_copy[i] = 1 seq = 0 for sc in S_copy: if sc == 1: seq += 1 if sc == 0: seq = 0 if seq > longest: longest = seq print(longest)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s688635569
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
s = list(input()) count = 0 n = len(s) if n % 2 == 0: for i in range(0, int(n / 2)): if s[(2 * i) + 1] == "0": count = count + 1 print(i) for j in range(0, int(n / 2)): if s[2 * j] == "1": count = count + 1 print(j) else: for i in range(0, int((n - 1) / 2) + 1): if s[2 * i] == "0": count = count + 1 for j in range(0, int(((n - 1) / 2))): if s[2 * j + 1] == "1": count = count + 1 count2 = n - count print(min(count, count2))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s695316383
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
S = list(input()) N = len(S) A = [] B = [] for i in range(N): A.append(str(i % 2)) B.append(str((i + 1) % 2)) countA = 0 countB = 0 for x in range(N): if A[x] != S[x]: countA += 1 else: countB += 1 print(min(countA, countB))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s417691642
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
bt = input() bt_A, bt_B = bt.split() bt_max, bt_min = max(bt_A, bt_B), min(bt_A, bt_B) max_num = bt_max + max(bt_max - 1, bt_min) print(max_num)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s630603982
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
A = int(input("ボタンA")) B = int(input("ボタンB")) get1 = A m = A - 1 get2 = B m = B - 1 sum = get1 + get2 print("合計の最大値は{}です".format(sum))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s355815044
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
x = int(input()) y = int(input()) if x > y: print(int(2 * x - 1)) elif x < y: print(int(2 * y - 1)) elif x == y: print(int(x + y))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s348245721
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
aa, bb = list(map(int, input().split())) if aa > bb: print(2 * aa + 1) elif aa < bb: print(2 * bb + 1) else: print(2 * aa)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s897890017
Accepted
p03071
Input is given from Standard Input in the following format: A B
ary1 = list(map(int, input().split())) ary2 = ary1 + [x - 1 for x in ary1] ary2.sort() print(ary2[2] + ary2[3])
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s533008313
Accepted
p03071
Input is given from Standard Input in the following format: A B
x = input() a = int(x.split(" ")[0]) b = int(x.split(" ")[1]) c = a + a - 1 d = a + b e = b + b - 1 print(max([c, d, e]))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s569851195
Accepted
p03071
Input is given from Standard Input in the following format: A B
# ABC 124: A – Buttons a, b = [int(s) for s in input().split()] print(max(a * 2 - 1, a + b, b * 2 - 1))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s882812858
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
A, B = map(int, input().split()) r =0 if A > B: r+=A A-=1 else: r += B B-=1 r+=max(A,B) print(r)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s731907009
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
print(2 * max(list(map(int, input().split()))) - 1)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s852023968
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
a,b=map(int,input().split()) coins = [a+b,2a-1,2b-1] print(max(coins))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s095525543
Accepted
p03071
Input is given from Standard Input in the following format: A B
button = input().split() A = button[0] B = button[1] full = [] A = int(A) B = int(B) if A >= 3 and B <= 20: if A + A - 1 >= A + B and A + A - 1 >= B + B - 1: full.append(A + A - 1) elif A + B >= A + A - 1 and A + B >= B + B - 1: full.append(A + B) else: full.append(B + B - 1) else: full.append(0) print(max(full))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s156256076
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
N, K = map(int, input().split()) S = input() if S[0] == "0": divide = [] else: divide = [0] tmp = 1 for i in range(1, N): if S[i] == S[i - 1]: tmp += 1 else: divide += [tmp] tmp = 1 divide += [tmp] le = len(divide) zero = [0] * 2 * le + divide + [0] * 2 * le su = [0] for i in range(0, 5 * le): su += [su[-1] + zero[i]] del su[0] lle = len(su) mxm = 0 for k in range(K, lle): if 2 * k + 1 >= lle: break cd = su[2 * k + 1] - su[2 * k - 2 * K] if cd > mxm: mxm = cd print(mxm)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s909589708
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
class CreateList: def __init__(self, flg, cnt): self.flg = flg self.cnt = cnt def main(): n, k = map(int, input().split()) s = list(map(int, input())) slist = [] # Sを使いやすいように加工した配列 bkflg = s[0] # 一つ前の連続する値が「1」か「0」かを持ってるやつ scnt = 0 # 「1」「0」の連続する数 ecnt = 0 # 終了判定のカウンター # 配列作成 for i in s: ecnt += 1 # 同じ数字が続く場合はカウントアップ if i == bkflg: scnt += 1 # 数字が変わったら配列にこれまでの合計数を入れてカウンターを初期化 else: slist.append(CreateList(bkflg, scnt)) scnt = 1 bkflg = i # 最後の1回が拾えないのでここで強引に配列に突っ込む if ecnt == len(s): slist.append(CreateList(bkflg, scnt)) # 本ちゃんで使う勇者たち maxsum = 0 # 最大合計値の変数 skipcnt = k # 連続する「0」を「1」としてカウント出来る回数 cursor = 0 # Sの配列変数の開始位置 cursorsum = 0 # 一時的な「1」の合計数 tmpcnt = 0 # 一時的なカーソル位置 # 本ちゃんスタート while tmpcnt <= len(slist) - 1: # Sの配列を左からスライドしながら数字を拾ってくので、最初にカウンターとカーソル位置を初期化 tmpcnt = cursor skipcnt = k cursorsum = 0 # ここで「1」の合計をSの配列の左からスライドさせながらカウントしていく while tmpcnt <= len(slist) - 1: if slist[tmpcnt].flg == 0: if skipcnt == 0: break else: skipcnt -= 1 cursorsum = cursorsum + slist[tmpcnt].cnt tmpcnt += 1 # これまでの最大合計数を拾う if maxsum < cursorsum: maxsum = cursorsum cursor += 1 print(maxsum) if __name__ == "__main__": main()
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s927755026
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
def init(a): cf = a[0] cc = 0 z = [] for it in a: if it == cf: cc += 1 else: if cf == "0": z.append(-cc) else: z.append(cc) cf = it cc = 1 z.append(cc) return z p = [] def solve(a, K): if K == 0: p.append(max(a)) return N = len(a) if K % 2 == 0: if a[0] > 0: b = [] b.append(a[1] - a[0]) for j in range(2, N): b.append(a[j]) solve(b, K - 1) if a[N - 1] > 0: b = [] for j in range(2, N): b.append(a[j]) b.append(a[N - 2] - a[N - 1]) solve(b, K - 1) for i in range(1, N - 1): if a[i] > 0: b = [] for j in range(0, i - 1): b.append(a[j]) b.append(a[i - 1] - a[i] + a[i + 1]) for j in range(i + 2, N): b.append(a[j]) solve(b, K - 1) else: if a[0] < 0: b = [] b.append(a[1] - a[0]) for j in range(2, N): b.append(a[j]) solve(b, K - 1) if a[N - 1] < 0: b = [] for j in range(2, N): b.append(a[j]) b.append(a[N - 2] - a[N - 1]) solve(b, K - 1) for i in range(1, N - 1): if a[i] < 0: b = [] for j in range(0, i - 1): b.append(a[j]) b.append(a[i - 1] - a[i] + a[i + 1]) for j in range(i + 2, N): b.append(a[j]) solve(b, K - 1) N, K = list(map(int, input().split(" "))) a = str(input()) z = init(a) L = len(a) Q = 0 if z[0] < 0: Q = N // 2 + 1 else: Q = N // 2 if K >= Q: print(N) else: solve(z, K) print(max(p))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s139530720
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
import sys def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) sys.setrecursionlimit(10**9) INF = float("inf") MOD = 10**9 + 7 N, K = LIST() S = input() # stand = [] # reverse = [] # state = None # count = 0 # tmp = None # for i in S: # if i == "0": # state = "stand" # else: # state = "reverse" # if tmp == "stand" and state == "reverse": # stand.append(count) # count = 1 # elif tmp == "reverse" and state == "stand": # reverse.append(count) # count = 1 # else: # 状態が前と同じ # count += 1 # tmp = state # if state == "stand": # stand.append(count) # else: # reverse.append(count) # if "0" not in S: # print(len(S)) # else: # if K >= len(stand): # 全員逆立ちにできる # print(len(S)) # else: # if len(stand) > len(reverse): # reverse.append(0) # reverse.insert(0, 0) # if len(stand) == len(reverse) and S[0] == "0": # reverse.insert(0, 0) # if len(stand) == len(reverse) and S[0] == "1": # reverse.append(0) # # print(stand) # # print(reverse) # max_ = 0 # for i in range(max(1, 1+len(reverse)-(K+1))): # # print(reverse[i:i+K+1],stand[i:i+K]) # tmp = sum(reverse[i:i+K+1]+stand[i:i+K]) # if tmp > max_: # max_ = tmp # print(max_) indexes = [] tmp = "" for i in range(len(S)): if S[i] == "0": state = "stand" else: state = "reverse" if tmp != state: indexes.append(i) else: # 状態が前と同じ pass tmp = state indexes.append(N) ans = [] # print(indexes) for i in range(len(indexes)): # print(i) if S[indexes[i]] == "0": if i + 2 * K >= len(indexes): pass ans.append(indexes[i + 2 * K] - indexes[i]) else: if i + 2 * K + 1 >= len(indexes): pass ans.append(indexes[i + 2 * K + 1] - indexes[i]) if ans == []: print(len(S)) else: print(max(ans))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s923436454
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
n, k = map(int, input().split()) s = input() s_list = [] first = s[0] last = s[n - 1] state = first length = 1 for i in range(1, n): if (state == "0" and s[i] == "0") or (state == "1" and s[i] == "1"): state = s[i] length = length + 1 else: state = s[i] s_list.append(length) length = 1 s_list.append(length) if first == "0": if last == "0": number0 = (len(s_list) + 1) / 2 else: number0 = len(s_list) / 2 else: if last == "0": number0 = len(s_list) / 2 else: number0 = (len(s_list) - 1) / 2 if first == "0" and last == "0": if number0 <= k: Max = n else: p_list = s_list[0 : 2 * k] Max = sum(p_list) i = 1 while i + 2 * k + 1 < n - 1: p_list = s_list[i : i + 2 * k + 1] if sum(p_list) > Max: Max = sum(p_list) i = i + 2 p_list = s_list[n - 2 * k :] if sum(p_list) > Max: Max = sum(p_list) elif first == "0" and last == "1": if number0 <= k: Max = n else: p_list = s_list[0 : 2 * k] Max = sum(p_list) i = 1 while i + 2 * k + 1 <= n - 1: p_list = s_list[i : i + 2 * k + 1] if sum(p_list) > Max: Max = sum(p_list) i = i + 2 elif first == "1" and last == "0": if number0 <= k: Max = n else: p_list = s_list[0 : 2 * k + 1] Max = sum(p_list) i = 2 while i + 2 * k + 1 < n - 1: p_list = s_list[i : i + 2 * k + 1] if sum(p_list) > Max: Max = sum(p_list) i = i + 2 p_list = s_list[n - 2 * k :] if sum(p_list) > Max: Max = sum(p_list) elif first == "1" and last == "1": if number0 <= k: Max = n else: p_list = s_list[0 : 2 * k + 1] Max = sum(p_list) i = 2 while i + 2 * k + 1 <= n - 1: p_list = s_list[i : i + 2 * k + 1] if sum(p_list) > Max: Max = sum(p_list) i = i + 2 print(Max)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s270758744
Accepted
p03071
Input is given from Standard Input in the following format: A B
A, B = [int(i) for i in input().split()] tmp1 = A + (A - 1) tmp2 = B + (B - 1) tmp3 = A + B print(max(max(tmp1, tmp2), tmp3))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s333048879
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
l = input().split() l.append(str(int(l[0]) - 1)) l.append(str(int(l[1]) - 1)) l.sort(reverse=True) print(int(l[0]) + int(l[1]))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s888815317
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
A,B = map(int,input().rstrip().split()) if A == B: print(A*A) else: print(max(A,B) * (max(A,B) - 1)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s857366870
Accepted
p03071
Input is given from Standard Input in the following format: A B
A, B = [int(a) for a in input().split()] print(2 * A if A == B else 2 * max(A, B) - 1)
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s538154831
Runtime Error
p03071
Input is given from Standard Input in the following format: A B
a = map(int, input().split()) print(max([2 * a[0] - 1, 2 * a[1] - 1, a[0] + a[1]]))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the maximum number of coins you can get. * * *
s612909218
Wrong Answer
p03071
Input is given from Standard Input in the following format: A B
a, b = [int(v) for v in input().split()] print(max(a + b, a * 2 + 1, b * 2 + 1))
Statement There are two buttons, one of size A and one of size B. When you press a button of size X, you get X coins and the size of that button decreases by 1. You will press a button twice. Here, you can press the same button twice, or press both buttons once. At most how many coins can you get?
[{"input": "5 3", "output": "9\n \n\nYou can get 5 + 4 = 9 coins by pressing the button of size 5 twice, and this\nis the maximum result.\n\n* * *"}, {"input": "3 4", "output": "7\n \n\n* * *"}, {"input": "6 6", "output": "12"}]
Print the minimum possible value displayed in the board after N operations. * * *
s009998201
Accepted
p03564
Input is given from Standard Input in the following format: N K
N, K = (int(input()) for T in range(0, 2)) Num = 1 for TN in range(0, N): Num = min(2 * Num, Num + K) print(Num)
Statement Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the minimum possible value displayed in the board after N operations.
[{"input": "4\n 3", "output": "10\n \n\nThe value will be minimized when the operations are performed in the following\norder: A, A, B, B. \nIn this case, the value will change as follows: 1 \u2192 2 \u2192 4 \u2192 7 \u2192 10.\n\n* * *"}, {"input": "10\n 10", "output": "76\n \n\nThe value will be minimized when the operations are performed in the following\norder: A, A, A, A, B, B, B, B, B, B. \nIn this case, the value will change as follows: 1 \u2192 2 \u2192 4 \u2192 8 \u2192 16 \u2192 26 \u2192 36 \u2192\n46 \u2192 56 \u2192 66 \u2192 76.\n\nBy the way, this contest is AtCoder Beginner Contest 076."}]