problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p02684
u797572808
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = map(int,input().split())\n\na = [0]*n\n\na = [int(s) for s in input().split()]\n\nnxt = a[0]\n\nseen = [0]\n#load = []\nres = 0\nflag = 0\nfor i in range(k-1):\n #print(nxt)\n if not(nxt in seen):\n seen.append(nxt)\n nxt = a[nxt-1]\n else:\n root = i - seen.index(nxt) + 1\n ...
['Wrong Answer', 'Runtime Error', 'Accepted']
['s160925239', 's239806874', 's697071800']
[33752.0, 33756.0, 33832.0]
[2206.0, 2206.0, 160.0]
[488, 530, 543]
p02684
u801049006
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\ns = [0] * N\np = 1\nh = []\nwhile True:\n h.append(p)\n s[p-1] = 1\n p = A[p-1]\n\n if s[p-1] != 0:\n break\nprint(h, p)\nlast = h.index(p)\nleng = len(h) - last\nrem = (K - last) % leng\nprint(h[last:][rem])\n', 'n, k = map(i...
['Wrong Answer', 'Accepted']
['s624129243', 's602133000']
[32392.0, 32100.0]
[202.0, 133.0]
[284, 356]
p02684
u805552010
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = map(int,input().split())\na = list(map(int,input().split()))\n\nt = 1\ntl = [1]\nts = {1}\nfor i in range(len(a)):\n\n t = a[t-1]\n if t in ts:\n break\n else:\n tl.append(t)\n ts.add(t)\n\ntl2 = tl[tl.index(t):len(tl)]\n\nprint(tl)\nprint(tl2)\n\nif k < len(tl):\n ans = tl[k]\n...
['Wrong Answer', 'Accepted']
['s797830430', 's320410162']
[32652.0, 32272.0]
[200.0, 205.0]
[384, 363]
p02684
u807028974
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
["# import sys\n# import math #sqrt,gcd,pi\n\n\n\n# import heapq # priolity-queue\n\n# from itertools import product,permutations,\\\n# combinations,combinations_with_replacement\n\n\n# from operator import itemgetter,mul\n# from fractions import Fraction\n# from functools import reduce\n\nmod = int(1e9+7)\nINF = 1...
['Runtime Error', 'Runtime Error', 'Accepted']
['s267430591', 's762157747', 's933195770']
[32716.0, 32380.0, 32644.0]
[198.0, 68.0, 234.0]
[1052, 351, 351]
p02684
u811202694
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['import sys\n\nsys.setrecursionlimit(10000000)\nN,K = [int(v) for v in input().split()]\nA = [int(v) for v in input().split()]\nprint(N,K)\n\n\nloop = []\n\ndef dfs(now):\n loop.append(now)\n if A[now-1] == 1:\n return\n else:\n dfs(A[now-1])\ndfs(1)\n\nprint(loop[K%len(loop)])\n', 'import sys\n...
['Runtime Error', 'Accepted']
['s573543403', 's701733923']
[612288.0, 191740.0]
[746.0, 341.0]
[283, 582]
p02684
u811436126
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map(int, input().split())\na = list(map(int, input().split()))\n\nvisited = [0] * (n + 1)\nnow = 1\ncheck = 2 * n\nloop_start = 1\nwhile check > 0:\n if visited[now - 1] == 1:\n loop_start = now\n break\n else:\n visited[now - 1] += 1\n now = a[now - 1]\n check -= 1\n\n...
['Wrong Answer', 'Accepted']
['s537014510', 's077104351']
[32404.0, 32408.0]
[216.0, 241.0]
[773, 672]
p02684
u811817592
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['# -*- coding: utf-8 -*-\nN, K = map(int, input().split())\nA_list = list(map(int, input().split()))\n\nans_list = [1]\nhistory_list = [0 for _ in range(N)]\nbefore_town = 1\nloop_start_town = 10 ** 10\nfor i in range(N):\n now_town = A_list[before_town - 1]\n if history_list[now_town - 1] == 1\n break\n ...
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s240706618', 's685028204', 's821243815', 's962129992']
[9044.0, 32260.0, 9040.0, 32376.0]
[24.0, 139.0, 22.0, 190.0]
[634, 635, 634, 634]
p02684
u813993459
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = list(map(int,input().split()))\n# a = list(map(int,input().split()))\n\ntmp_city=[]\nc=0\ncount=0\ninit_city=0\n\nwhile (1):\n count+=1\n tmp=a[c]\n if k==count:\n tmp_city.append(tmp)\n tmp_city=[1]+tmp_city\n break\n if tmp == 1:\n init_city=0\n tmp_city=[1]+tmp...
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s192005535', 's339733584', 's513960485', 's269920248']
[9168.0, 32312.0, 32360.0, 32368.0]
[21.0, 2206.0, 2206.0, 127.0]
[603, 419, 425, 375]
p02684
u816265237
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['#167\n#d\nn,k = map(int, input().split())\nln = list(map(int, input().split()))\n\n# n,k = 10*4,10**18\n# ln = list(range(2,n+1))\n# ln.append(1)\n\nvisit = [0]*n \nnow= 1 \nbefore =[] \nroop =[] \nwhile visit[now -1] != 2:\n if visit[now -1] == 0:\n before.append(now)\n elif visit [now-1] == 1:\n ...
['Wrong Answer', 'Accepted']
['s761641834', 's271699043']
[32000.0, 32368.0]
[261.0, 241.0]
[602, 602]
p02684
u822662438
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map(int, input().split())\n\na = list(map(int, input().split()))\n\nvisited = [1]\nis_visited = [0] * n\nnow = 1\nstep = 0\nfor i in range(k):\n now = a[now-1]\n step += 1\n if is_visited[now-1] == 0:\n is_visited[now-1] = 1\n else:\n ind = visited.index(now)\n loop = visited[i...
['Runtime Error', 'Runtime Error', 'Accepted']
['s013093541', 's570115519', 's824522642']
[32364.0, 32300.0, 32260.0]
[143.0, 127.0, 136.0]
[393, 393, 421]
p02684
u825186577
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N,K = map(int,input().split())\nA = list(map(int,input().split()))\n\npos = 0\nvisited = [0]*N\nmove = []\nloop = []\n\nwhile visited[pos]!=2:\n if visited[pos] ==0:\n move.append(pos)\n else:\n loop.append(pos)\n visited[pos] += 1\n pos = A[pos]-1\n\nif len(move)>k:\n print(move[k]+1)\nelse:\n print(roop...
['Runtime Error', 'Accepted']
['s271857748', 's231111522']
[32668.0, 32840.0]
[257.0, 257.0]
[339, 352]
p02684
u830054172
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\n\nA = list(map(int, input().split()))\n\ncnt = [0 for _ in range(N)]\ncnt[0] += 1\n\nwarp_rireki= [A[0]]\nroop = []\n# c = 0\n# print(cnt)\nwarp = A[0]\nwhile True:\n # print(cnt[warp-1])\n if cnt[warp-1] == 2:\n break\n warp_rireki.append(A[warp-1])\n if cnt[warp-...
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s053534298', 's460651000', 's597840443', 's927648820']
[32384.0, 32388.0, 32068.0, 33396.0]
[289.0, 336.0, 304.0, 176.0]
[560, 544, 554, 880]
p02684
u833492079
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['#-------------------------------------------------------------------\nimport sys\ndef p(*_a):\n _s=" ".join(map(str,_a))\n #print(_s)\n sys.stderr.write(_s+"\\n")\n#-------------------------------------------------------------------\nN,K = map(int, input().split())\t\t# 5 7 2\nA = [0] + list( map(int, input().spli...
['Runtime Error', 'Runtime Error', 'Accepted']
['s689039794', 's837662701', 's899592121']
[8792.0, 50128.0, 49316.0]
[26.0, 389.0, 916.0]
[716, 711, 646]
p02684
u834224054
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['tmp = input().split()\nN = int(tmp[0])\nK = int(tmp[1])\n\ntmp = input().split()\n\nMap = [0]*N\nK = K%N\nrt = [0]*K\n\nfor i in range(N):\n Map[i] = int(tmp[i])\n\ndef trip(self, steps):\n ntown = Map[self-1]\n if steps == K:\n return ntown\n rt[steps]=trip(ntown,steps+1)\n\n\n \nFt = trip(1,1)...
['Runtime Error', 'Accepted']
['s092663010', 's192802502']
[33352.0, 32400.0]
[107.0, 212.0]
[313, 502]
p02684
u838644735
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
["def main():\n N, K, *A = map(int, open(0).read().split())\n visited = [0]*N\n pos = A[0]\n visited[0] = visited[pos - 1] = 1\n while visited[pos - 1] < 2:\n pos = A[pos - 1]\n visited[pos - 1] += 1\n # print(pos)\n begin = pos\n step_to_begin = 0\n if begin != 0:\n pos ...
['Wrong Answer', 'Accepted']
['s893908460', 's796415233']
[31824.0, 31808.0]
[2206.0, 1896.0]
[903, 119]
p02684
u841856382
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n = input().split()\nN = int(n[0])\nK = int(n[1])\n\nlista = []\nlistb = [1]\nC = 1\nA = list(map(int, input().split()))\n\nfor i in range(N):\n lista.append(int(A[i]))\n \nfor j in range(20000000):\n C = lista[C-1]\n if C not in listb:\n listb.append(C)\n else:\n break\n ...
['Wrong Answer', 'Accepted']
['s674936731', 's686571863']
[32388.0, 33888.0]
[2206.0, 175.0]
[582, 483]
p02684
u843318346
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = map(int,input().split())\nan = list(map(int, input().split()))\ncopyan = an[:]\ni = copyan[0]\ncopyan[0]=10**6\nmovecount = 1\nroopstart = 0\nif i != 1:\n while True:\n memo = i\n i = copyan[i-1]\n copyan[memo-1]=10**6 + movecount\n \n \n if i >=30000:\n y...
['Runtime Error', 'Accepted']
['s124137275', 's774731843']
[32300.0, 32300.0]
[2206.0, 143.0]
[723, 567]
p02684
u845536647
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['print(kari)', 'N, K = map(int, input().split())\nA = list(map(int, input().split()))\nl=[1] \nseen={}\nk=1\nfor i in range (K):\n if not k in seen.keys():\n seen[k]=i\n k=A[k-1]\n l.append(k)\n else:\n r_start=seen[k]\n roop=i-r_start\n K=(K-r_start)%roop+r_start\n break\nans=l[...
['Runtime Error', 'Accepted']
['s025530436', 's599112167']
[9132.0, 32320.0]
[24.0, 165.0]
[11, 301]
p02684
u845620905
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map(int, input().split())\na = list(map(int, input().split()))\n\nk += 1\npos = -1\nseen = [False] * n\nlast = [0] * n\nhist = []\ncycle = []\ni = 0\ncnt = 0\nwhile(seen[i] == False):\n seen[i] = True\n last[i] = cnt\n cnt += 1\n hist.append(i)\n ne = a[i]-1\n i = ne\n if (seen[i] == True)...
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s183318237', 's916046830', 's865898897']
[35496.0, 32388.0, 34460.0]
[189.0, 2206.0, 193.0]
[516, 524, 472]
p02684
u850390157
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\nA = list(map(lambda x: x - 1, map(int, input().split())))\nprint(A)\ncurrent = 0\nmemo = {\n 0: 0\n}\nfor i in range(1, K + 1):\n current = A[current]\n if current in memo:\n # loop length\n length = i - memo[current]\n tmp = (K - memo[current]) % length...
['Wrong Answer', 'Accepted']
['s177413994', 's958069329']
[32252.0, 32368.0]
[154.0, 130.0]
[467, 428]
p02684
u859059120
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k=map(int,input().split())\nseq=list(map(int,input().split()))\nv=[False]*n\npath=[]\ni=seq.index(1)\nwhile True:\n if v[seq[i]-1]==False:\n v[seq[i]-1]=True\n path.append(seq[i])\n i=seq[i]-1\n \n else:\n break\nprint(path[(k%...
['Runtime Error', 'Accepted']
['s931740911', 's542489602']
[32376.0, 32264.0]
[161.0, 185.0]
[347, 534]
p02684
u866949333
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
["from collections import defaultdict\nimport math\n\n\ndef comb(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\n\ndef main():\n N, M, K = map(int, input().split())\n const = 998244353\n\n def hoge(k):\n return comb(N - 1, k) * M * ((M - 1) ** (N - k - 1))\n\n a...
['Runtime Error', 'Accepted']
['s332165626', 's930494841']
[9528.0, 32572.0]
[24.0, 155.0]
[409, 791]
p02684
u867408000
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['\nN,K = map(int,input().split())\nA = list(map(int,input().split()))\npos = 0\nvisit = [0] * N\nmove = []\nloop = []\nwhile visit[pos]!=2:\n if visit[pos]==0:\n move.append(pos)\n else:\n loop.append(pos)\n visit[pos] += 1\n pos = A[pos] - 1\n print(visit)\nprint(move)\nprint(loop)\nif le...
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s094323779', 's793816227', 's171027934']
[150488.0, 32360.0, 32620.0]
[2421.0, 231.0, 216.0]
[402, 626, 361]
p02684
u870736713
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N,K=map(int,input().split())\nN=list(map(int,input().split()))\na={}\n \nb=1\na[1]=1\ncount=0\nwhile(count<=K):\n count+=1\n b=N[b-1]\n #print(b)\n if b in a:\n print(a)\n print(b)\n print(count)\n cycle=count-a[b]\n rest=K-count+1\n ans=rest%cycle\n for i in range(ans-1):\n b=N[b-1]\n ...
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s010544253', 's089811065', 's146045889', 's200825428', 's281500717', 's325488481', 's433263363', 's563981386', 's724957098', 's893880798', 's940696183', 's318297021']
[32580.0, 38804.0, 32352.0, 32360.0, 32372.0, 32300.0, 32352.0, 9152.0, 32372.0, 9072.0, 32380.0, 32384.0]
[204.0, 185.0, 162.0, 141.0, 139.0, 148.0, 156.0, 22.0, 146.0, 21.0, 132.0, 151.0]
[341, 329, 380, 373, 460, 426, 380, 415, 376, 364, 370, 440]
p02684
u872271866
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['\ndef main():\n n, k = map(int, input().split(" "))\n a = list(map(lambda i: int(i)-1, input().split(" ")))\n s = [0]\n u = [0]\n f = True\n loop_len = 1\n z = 0\n x = a[0]\n while f:\n if x in s:\n f = False\n z = s.index(x)\n s = s[z:]\n ...
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s013872538', 's234114695', 's834428431', 's280437703']
[32324.0, 32308.0, 33804.0, 33820.0]
[2206.0, 2206.0, 136.0, 141.0]
[495, 511, 976, 978]
p02684
u872538555
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['def search(now, teleporter, limit):\n visit = [-1] * len(teleporter)\n cnt = 0\n \n while visit[now] == -1:\n if limit <= cnt:\n break\n \n visit[now] = cnt\n cnt += 1\n now = teleporter[now]\n \n \n return now, cnt, cnt - visit[now]\n \n\nn, k...
['Wrong Answer', 'Accepted']
['s803795490', 's662428896']
[32220.0, 32264.0]
[141.0, 144.0]
[590, 616]
p02684
u873616440
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\ne = [False] * (N+1)\nidx = 1\nmove = []\nwhile True:\n if e[idx]:\n break\n move.append(idx)\n e[idx] = True\n idx = A[idx-1]\nm = move.index(idx)\nc = len(move) - m\n\nif K <= m:\n print(D[K])\nelse:\n print(D[m+(K-m) % c])', 'N, K =...
['Runtime Error', 'Accepted']
['s021312022', 's963198130']
[32300.0, 32380.0]
[150.0, 135.0]
[291, 298]
p02684
u875541136
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nt_zero = [-1] * N\n\nt = 0\na = 1\n\nwhile t_zero[a-1] == -1:\n if t == K:\n break\n t_zero[a-1] = t\n t += 1\n a = A[a-1]\nelse:\n k = (K - t_zero[a-1]) % (t - t_zero[a-1])\n a = t_zero.index(t_zero[a] + k)\nprint(a)', 'N, K = map(int,...
['Runtime Error', 'Accepted']
['s191973717', 's197697637']
[32372.0, 32388.0]
[130.0, 140.0]
[282, 288]
p02684
u891516200
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['import sys\n\nN, K = map(int, input().split())\ntown_list = list(map(int, input.split()))\n\nroop = 0\nqueue = [1]\n\nstart = -1\n\nfor now_town in queue:\n if not town_list[now_town - 1] in queue:\n queue.append(town_list[now_town - 1])\n\n \n else:\n start = town_list[now_town - 1]\n b...
['Runtime Error', 'Runtime Error', 'Accepted']
['s627534436', 's967399771', 's604674248']
[8976.0, 38816.0, 32316.0]
[34.0, 195.0, 165.0]
[488, 564, 548]
p02684
u894521144
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
["def main(N, K, A):\n i = 0 \n lst_memo = []\n set_memo = {}\n while i not in set_memo:\n lst_memo.append(i)\n set_memo.append(i)\n i = A[i] - 1 \n key = lst_memo.index(i)\n roop = memo[key:]\n print(roop[(K - key) % len(roop)] + 1) \n\n\nif __name__ == '__main__':\n ...
['Runtime Error', 'Accepted']
['s369878112', 's146474986']
[32240.0, 35668.0]
[66.0, 121.0]
[465, 536]
p02684
u896451538
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['import collections\n\nn,k = list(map(int,input().split()))\na = list(map(int,input().split()))\na = [int(i)-1 for i in a]\n\nex = collections.defaultdict(lambda:-1)\nstep=1\ncur=0\nex[0]=0\nwhile 1:\n if ex[a[cur]]!=-1:\n cycle = step-ex[a[cur]]\n k-=ex[a[cur]]-1\n #print(k%cycle)\n bre...
['Wrong Answer', 'Accepted']
['s268024960', 's295647283']
[42232.0, 33900.0]
[305.0, 198.0]
[444, 514]
p02684
u896741788
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k=map(int,input().split())\na=list(map(int,input().split()))\nok=set()\nnow=0\nl=[]\nwhile now not in ok and k:\n l.append(now)\n ok.add(now)\n now=a[now]-1\n k-=1\nlength=len(ok)-(h:=l.index(now))\nl=l[h:]\nprint(l,h,length)\nk=(k)%length\n\nprint(l[k]+1)', 'n,k=map(int,input().split())\na=list(map(int...
['Runtime Error', 'Wrong Answer', 'Accepted']
['s304845654', 's510372099', 's355969015']
[35088.0, 35384.0, 32328.0]
[167.0, 160.0, 1587.0]
[255, 283, 259]
p02684
u898058223
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k=map(int,input().split())\na=list(map(int,input().split()))\nnext=a[0]\ntown=[0]*n\ntown[0]+=1\nfor i in range(n):\n if town[next-1]==0:\n town[next-1]+=1\n next=a[next-1]\n else:\n start=next\n break\nnext=a[start-1]\ncnt=1\nfor i in range(n):\n if a[next-1]!=start:\n next=a[next-1]\n cnt+=1\...
['Wrong Answer', 'Accepted']
['s105662062', 's658853325']
[32244.0, 32400.0]
[178.0, 236.0]
[407, 584]
p02684
u899782392
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\nA = list(map(lambda x:int(x)-1, input().split()))\n\ncnts = [None] * N\n\npos = 0\ncnt = 0\n\nwhile cnt < K:\n print(cnts)\n if cnts[pos] != None:\n loop_size = cnt - cnts[pos]\n cnt += ((K-cnt) // loop_size - 1) * loop_size\n cnts = [None] * N\n cnts[po...
['Runtime Error', 'Time Limit Exceeded', 'Accepted']
['s768670945', 's897019848', 's280731117']
[152100.0, 32356.0, 32264.0]
[2255.0, 2206.0, 196.0]
[356, 340, 340]
p02684
u907223098
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k=(int(i) for i in input().split())\nr=[0 for i in range(n)]\nl=[int(i) for i in input().split()]\nwazap=[]\ncount=1\nsaver=None\ntemp=0\nwhile r[temp]==0:\n r[temp]=count\n wazap.append(temp)\n temp=l[temp]-1\nstart=wazap[-1]\nfor i in range(len(wazap)):\n if wazap[i]==start-1:\n left=i\n break\nloop=len...
['Runtime Error', 'Accepted']
['s459641289', 's648389506']
[33888.0, 33896.0]
[142.0, 175.0]
[388, 401]
p02684
u909991537
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['import numpy as np\nN, K = (int(i) for i in input().split()) \nA = [int(i) for i in input().split()] \n\ndef has_duplicates(seq):\n return len(seq) != len(set(seq))\n\nlis = [1]\nidx = 0\n\ncheck_l = [0] * N\nfor i in range(N):\n lis.append(A[idx])\n if check_l[A[idx]] != 1:\n lis.pop(-1)\n found = lis.inde...
['Runtime Error', 'Accepted']
['s356474175', 's774354532']
[51052.0, 57864.0]
[174.0, 247.0]
[439, 416]
p02684
u915879510
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
["#!/usr/bin/env python3\n\n\n# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n # Failed to predict input format\n N, K = list(map(int, input().split()))\n A = list(map(int, input(...
['Wrong Answer', 'Accepted']
['s288407211', 's300946537']
[31020.0, 32388.0]
[216.0, 145.0]
[948, 956]
p02684
u920977317
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['from collections import deque\n\ndef main():\n N,K=map(int,input().split())\n\n A=list(map(lambda x:int(x)-1,input().split()))\n\n loop=[]\n\n slack_que=deque([])\n flag=0\n t=0\n start=0\n counter=0\n while flag==0:\n slack_que.append(t)\n t=A[t]\n A[t]=-1\n if ...
['Wrong Answer', 'Accepted']
['s590218965', 's696915375']
[33916.0, 33924.0]
[82.0, 138.0]
[782, 848]
p02684
u927282564
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['from collections import deque\n\nN, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\ndef func1(lst, value):\n return [i for i, x in enumerate(lst) if x == value]\n \ntemp=1\ntrace=deque()\ntrace.append(1)\n#trace=[1]\ncircle=[]\nfor i in range(K):\n temp=A[temp-1]\n ans=func1(trace,te...
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s310332570', 's922102829', 's700995899']
[33916.0, 32260.0, 32380.0]
[2206.0, 2206.0, 197.0]
[684, 497, 439]
p02684
u933129390
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map(int, input().split())\na = list(map(int, input().split()))\nlog = []\nvisited = [False for i in range(n)]\nnow = a[0]-1\nloop = False\nfor i in range(k-1):\n if visited[now] == True:\n loop = True\n break\n log.append(now)\n visited[now] = True\n now = a[now]-1\nelse:\n print(n...
['Wrong Answer', 'Accepted']
['s070285054', 's726704739']
[32300.0, 32376.0]
[160.0, 138.0]
[569, 554]
p02684
u935016954
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
["from copy import copy, deepcopy\nfrom collections import Counter\nfrom math import sqrt, floor, factorial\nfrom itertools import permutations, combinations, combinations_with_replacement\nfrom operator import mul\nfrom functools import reduce\nimport bisect\n\nMOD = 10**9 + 7\nINF = float('inf')\n\nN, K = list(map(in...
['Wrong Answer', 'Accepted']
['s800937886', 's983496682']
[32208.0, 32252.0]
[209.0, 175.0]
[902, 883]
p02684
u935241425
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map( int, input().split() )\na = [ int( i ) for i in input().split() ]\n\nleg = [ 0 ] * n\nleg[ 0 ] = 1\n\np = 0\ncity_old = 1\nfor x in range( k ):\n city_new = a[ city_old-1 ]\n if leg[ city_new-1 ] == 0:\n leg[ city_new-1 ] += x + 1\n else:\n loop = x + 1 - leg[ city_new-1 ]\n ...
['Runtime Error', 'Accepted']
['s265543670', 's292507755']
[32324.0, 32172.0]
[157.0, 181.0]
[550, 596]
p02684
u941644149
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\nway = A[0]\nList = [0 for n in range(N)]\nList[way-1] += 1\ncount = 0\nstring = f"{way}"\n#print(f"string:{string}")\n#print(f"way:{way}")\n\nfor i in range(10**7):\n way = A[way-1]\n List[way-1] += 1 \n count += 1\n #print(f"way:{way}...
['Wrong Answer', 'Runtime Error', 'Accepted']
['s457071922', 's617158903', 's373680862']
[32380.0, 32276.0, 32268.0]
[2206.0, 2206.0, 172.0]
[693, 696, 609]
p02684
u946517952
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
["n,k = map(int,input().split())\nalist = list(map(int,input().split()))\n\nmemo = []\np = 1\nvis = ['.']*n\n\nwhile vis[p-1] == '.':\n memo.appened(p)\n vis[p-1] = 'v'\n p = alist[p-1]\n\nloopstart = alist.index(p)\nif k < len(alist):\n print(memo[k])\nelse:\n print(memo[loopstart+(k-loopstart)%(len(ali...
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s085914072', 's273004999', 's716759230', 's989506386']
[32296.0, 32696.0, 32352.0, 32132.0]
[73.0, 150.0, 172.0, 150.0]
[319, 396, 250, 293]
p02684
u948911484
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = map(int,input().split())\na = [0]+list(map(int,input().split()))\nvisited = [0]*(n+1)\nturn = [0]*(n+1)\nvisited[1] = 0\nnxt = 1\ni = 1\nwhile True:\n if visited[a[nxt]]:\n nxt2 = a[nxt]\n break\n turn[a[nxt]] = i\n visited[nxt] = 1\n i += 1\n nxt = a[nxt]\n\n\n\nloop = i-turn[nxt2]\nif turn[nxt2] ==...
['Wrong Answer', 'Accepted']
['s119536604', 's360321578']
[32292.0, 32200.0]
[151.0, 162.0]
[439, 512]
p02684
u955125992
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map(int, input().split())\na = list(map(int, input().split()))\n\ns = 1\nplace = [s]\nfirst = set(place)\n\nfor i in range(n):\n s = a[s-1]\n if s in first:\n loops = place.index(s)\n loope = len(place)\n ans = loops + (k-loope) % (loope-loops)\n print(place(ans))\n bre...
['Runtime Error', 'Accepted']
['s079010729', 's870741529']
[32228.0, 32364.0]
[190.0, 148.0]
[380, 377]
p02684
u962330718
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N,K=map(int,input().split())\nA=list(map(int,input().split()))\n\nl=K%N\nans=1\nfor i in range(l):\n ans=A[ans-1]\n \nprint(ans)', 'N,K=map(int,input().split())\nA=list(map(int,input().split()))\nB=[0]*N\npoint=1\nm,l=0,0\nif K>N:\n for i in range(N):\n if B[point-1]==0:\n B[point-1]=i+1\n ...
['Wrong Answer', 'Accepted']
['s024837721', 's534464200']
[32252.0, 32280.0]
[99.0, 169.0]
[122, 464]
p02684
u962718741
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['def main():\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n A_cnt = [0] * N\n telepo = [1]\n i = 0\n A_cnt[i] = 1\n roop = 0\n while True:\n if A_cnt[i] > 1:\n roop = telepo.index(A[i]) - 1\n break\n A_cnt[A[i] - 1] += 1\n t...
['Wrong Answer', 'Accepted']
['s362445309', 's206778288']
[32368.0, 32248.0]
[143.0, 143.0]
[460, 570]
p02684
u968404618
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map(int, input().split())\nA = list(map(int, input().split()))\n\nTown = []\n\nrec = [-1] * (n+1)\nidx = 1\n\nwhile (rec[idx] == -1):\n rec[idx] = len(Town)\n Town.append(idx)\n idx = A[idx-1]\n\nExce = rec.index(idx)\nCycl = len(Town) - Exce\n\nif Cycl > k:\n print(Town[k])\nelse:\n k -= Exce\n...
['Runtime Error', 'Accepted']
['s233318907', 's837770701']
[32248.0, 33364.0]
[178.0, 150.0]
[402, 781]
p02684
u970082363
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = (int(x) for x in input().split())\ntown = [int(i) for i in input().split()]\nwarp = [1]\nchecklist = [0]+[-1]*n\ni = 0\nj = 0\nwhile j<=n:\n #print(town[i])\n warp.append(town[i])\n #print(warp,checklist)\n if checklist[town[i]-1]!=-1:\n s = checklist[town[i]-1]\n warp = warp[s:j]\n ...
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s209728179', 's288103790', 's963708298', 's643635833']
[32248.0, 32328.0, 32332.0, 32272.0]
[225.0, 185.0, 184.0, 208.0]
[475, 365, 370, 410]
p02684
u970197315
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N,K = map(int,input().split())\na = list(map(int,input().split()))\n\nd = 60\ndp = [[-1]*N for _ in range(d+1)]\nfor i in range(n):\n dp[0][i] = a[i]-1\n\nfor i in range(d):\n for j in range(n):\n dp[i+1] = dp[i][dp[i][j]]\n\nans = 0\n\nfor i in range(d):\n if K & (1<<i):\n ans = dp[i][ans]\n\n...
['Runtime Error', 'Accepted']
['s524672081', 's186689057']
[114276.0, 32360.0]
[187.0, 152.0]
[313, 273]
p02684
u970267139
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n, k = map(int, input().split())\na = list(map(int, input().split()))\n\nt = [1]\nfor i in range(n):\n t.append(a[t[-1] - 1])\n\nt_sort = sorted(t)\nfor i in range(n):\n if t_sort[i] == t_sort[i + 1]:\n b = t_sort[i]\n break\n\ncount = 0\nfor i in range(n):\n if t[i] == b:\n if count ==...
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s327558490', 's424048331', 's769963558', 's644358635']
[32176.0, 32312.0, 32372.0, 32160.0]
[274.0, 238.0, 2206.0, 156.0]
[562, 566, 348, 374]
p02684
u970598682
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N,K=map(int,input().split())\n\narray=map(int,input().split())\n\nA=list(array)\nA.insert(0,0)\n\nvisit=0\nroot=[]\nvisited=1\nonce=0\nwhile True:\n if visit & (0b1<<visited):\n break\n root.append(visited)\n visit|=0b1<<visited\n once+=1\n visited=A[visited]\n\nroop=root[root.index(visited):]\n...
['Runtime Error', 'Accepted']
['s196385533', 's961182706']
[32384.0, 32328.0]
[1753.0, 1750.0]
[396, 383]
p02684
u971124021
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = list(map(int,input().split()))\nA = list(map(int,input().split()))\n\nif k == 1:exit(print(A[0]))\nt = 0\ndp = [-1] * n\ndp[0] = 0\nfor i in range(1,k+1):\n t = A[t]-1\n if dp[t] != -1:break\n dp[t] = i\n \nl = i - dp[t]\nK = (k-dp[t])%l + dp[t]\nprint(dp)\nfor i in range(n):\n if dp[i] == K:exit(print(i+1...
['Runtime Error', 'Runtime Error', 'Accepted']
['s622899748', 's651062444', 's310891835']
[32372.0, 32320.0, 32352.0]
[164.0, 145.0, 137.0]
[304, 333, 385]
p02684
u975445930
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = map(int, input().split())\nl = list(map(int, input().split()))\n\nkeys = range(1,n+1)\nvalues = [-1]*n\ndic = dict(zip(keys,values))\ndic[1] = 0\nt = 1\ni = 1\n\ndef inverse_lookup(d, x):\n for k,v in d.items():\n if x == v:\n return k\n\nwhile i <= k:\n t = l[t-1]\n if dic[t] != -1:\...
['Wrong Answer', 'Accepted']
['s705837541', 's051821097']
[41088.0, 41000.0]
[199.0, 178.0]
[486, 523]
p02684
u982030663
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split(" "))\nA = [i for i in map(int, input().split(" "))]\n\nhist = [0 for i in range(N)]\nroute = []\nloop = []\n\njump = 1\ncur = A[0] - 1\nroute.append(0)\nhist[0] = jump\nwhile hist[cur] == 0:\n jump = jump + 1\n route.append(cur)\n hist[cur] = jump\n cur = A[cur] - 1\n\nloop ...
['Runtime Error', 'Wrong Answer', 'Accepted']
['s192138965', 's415989606', 's172888215']
[34720.0, 37020.0, 33960.0]
[182.0, 250.0, 175.0]
[437, 498, 501]
p02684
u982591663
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N, K = map(int, input().split())\nA = list(map(int, input().split()))\nmemo = [-1] * N\nchecked_num = {}\n\nteleporter = A[0]\nmemo[0] = teleporter\nrepeat_point = -1\nflag = False\n\nfor i in range(1, N):\n memo[i] = A[teleporter-1]\n teleporter = A[teleporter-1]\n checked_num[memo[i]] = None\n if memo[i...
['Runtime Error', 'Accepted']
['s383020276', 's794190856']
[36560.0, 36852.0]
[181.0, 190.0]
[591, 758]
p02684
u987326700
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k = map(int,input().split())\na = list(map(int,input().split()))\nl = [1]\nfor i in range(n): \n l.append(a[l[i]])\n \np = l.index(l[-1])\nif k<=n:\n print(l[k])\n exit()\n \nx = (k-n+1)%(n-p)\nif x==0:\n print(l[n-1])\nelse:\n print(l[x+p-1])\n', 'n,k = map(int,input().split())\na = list(map(int,input(...
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s212194425', 's251096519', 's390060930', 's405301813', 's579001902', 's961453210']
[32168.0, 32372.0, 8920.0, 32264.0, 32384.0, 32384.0]
[95.0, 2206.0, 24.0, 2207.0, 94.0, 124.0]
[243, 355, 377, 376, 243, 245]
p02684
u991567869
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['import sys\ninput = sys.stdin.readline\n\ndef main():\n n, k = map(int, input().split())\n a = list(map(int, input().split()))\n l = [-1]*200010\n now = 0\n l[0] = 0\n ans = -100\n\n for i in range(n):\n k -= 1\n now = a[now] - 1 \n l[now] += 1\n if l[now] == 2: \n ...
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s627586984', 's919505336', 's976927305', 's092734454']
[31344.0, 31268.0, 32380.0, 32328.0]
[2206.0, 987.0, 909.0, 255.0]
[491, 602, 514, 357]
p02684
u991619971
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['#N=int(input())\nN,K = map(int,input().split())\n#N=int(input())\nA = list(map(int,input().split()))\n#S=str(input())\n\nnow=1\nflag=[0]+[-1]*(N-1)\n\nfor i in range(N):\n now = A[now-1]\n if flag[now-1]==-1:\n flag[now-1]+=i+2\n else:\n loop = i+1 - flag[now-1]\n zan=(K-i-1) - (K-i-1)//...
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s035349115', 's907296751', 's171179555']
[32300.0, 32360.0, 32384.0]
[175.0, 189.0, 155.0]
[385, 423, 405]
p02684
u992471673
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['n,k=map(int,input().split())\n\na=input().split()\n\nl=len(a)\n\nfor i in range(0,l):\n a[i]=int(a[i])\n\np=1\nh=[]\ngo=0\ni=0\nwhile(go==0):\n i+=1\n \n \n\n h.append(p)\n p=a[p-1]\n if i==k:\n break\n if p in h:\n l=len(h)\n for j in range(0,l):\n if h[j]==p:\...
['Wrong Answer', 'Runtime Error', 'Accepted']
['s732825777', 's954887965', 's065212481']
[25524.0, 32380.0, 32372.0]
[2207.0, 126.0, 143.0]
[413, 353, 334]
p02684
u993435350
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['N,K = map(int,input().split())\nA = list(map(int,input().split()))\ntown = [[] for _ in range(N)]\nvisited = [0]\n\nfor i in range(N):\n town[i] = [i,A[i] - 1]\n\ndef teleport(i,con):\n goal = town[i][1]\n if goal in visited or con == K:\n return goal\n else:\n visited.append(goal)\n return teleport(goal...
['Runtime Error', 'Accepted']
['s365466668', 's251347718']
[47640.0, 50452.0]
[171.0, 285.0]
[573, 457]
p02684
u996665352
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['def main():\n N,K = map(int,input().split())\n As = list(map(int,input().split()))\n route = [0]\n pre = 0\n i = 0\n r_append = route.append\n for _ in range(N):\n i = As[i]-1\n if i in route:\n pre = route.index(i)\n route = route[pre:]\n break\n ...
['Runtime Error', 'Accepted']
['s925308734', 's929352307']
[32296.0, 32376.0]
[70.0, 124.0]
[455, 327]
p02684
u999482355
2,000
1,048,576
The Kingdom of Takahashi has N towns, numbered 1 through N. There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i. Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K...
['from time import time\nN, K = list(map(int, input().split()))\nA = list(map(int, input().split()))\nL = [-1 for i in range(N)]\n\nvisited = []\nnow = 0\nloopstarts = None\nlooplength = None\nt0 = time()\n\nfor i in range(N):\n if L[now] != -1:\n break\n else:\n L[now] = i\n visited.append(n...
['Wrong Answer', 'Accepted']
['s014869576', 's325181203']
[33472.0, 33584.0]
[189.0, 192.0]
[525, 527]
p02685
u030726788
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['from math import factorial\n\n\n# return(factorial(n) // (factorial(n-r) * factorial(r)))\n\ndef comb(n,k,p):\n if n<0 or k<0 or n<k: return 0\n if n==0 or k==0: return 1\n a=factorial(n) %p\n b=factorial(k) %p\n c=factorial(n-k) %p\n return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p\ndef pow...
['Time Limit Exceeded', 'Accepted']
['s966620673', 's252536579']
[127632.0, 33236.0]
[2211.0, 1581.0]
[1131, 698]
p02685
u036104576
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['import sys\nimport itertools\nimport numpy as np\n\nMOD = 998244353\nMAX = 10 ** 5 * 2 + 5\n\nfac = [0 for i in range(MAX)]\nfinv = [0 for i in range(MAX)]\ninv = [0 for i in range(MAX)]\n\ndef comInit(mod):\n fac[0], fac[1] = 1, 1\n finv[0], finv[1] = 1, 1\n inv[1] = 1\n for i in range(2, MAX):\n ...
['Runtime Error', 'Wrong Answer', 'Accepted']
['s107569072', 's749940532', 's464056409']
[50956.0, 50944.0, 50888.0]
[305.0, 400.0, 463.0]
[852, 873, 922]
p02685
u078181689
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['N,M,K = list(map(int,input().split()))\n\nMOD = 998244353\nF = 10**5\ng1 = [1, 1] \ng2 = [1, 1] \ninverse = [0, 1] 計算用テーブル\n\nfor i in range( 2, F + 1 ):\n g1.append( ( g1[-1] * i ) % MOD )\n inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )\n g2.append( (g2[-1] * inverse[-1]) % MOD )\n\ndef cmb(n, r,...
['Runtime Error', 'Accepted']
['s601494973', 's148015327']
[28908.0, 48568.0]
[546.0, 734.0]
[609, 419]
p02685
u089142196
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['def combi(y,x,p=998244353):\n s=fac[y]\n t=fac[x]\n u=fac[y-x]\n ans= (s* pow(t,p-2,p)*pow(u,p-2,p))%p\n return ans\n\n###############################\n\nN,M,K=map(int,input().split())\np=998244353\nfac=[1,1]\nfor i in range(2,N+1):\n fac.append( (fac[-1]*i)%p )\nR = M*(M-1)**(N-K-2)\n\nans=0\nfor i in range(K,...
['Runtime Error', 'Accepted']
['s859535889', 's431642632']
[18600.0, 9212.0]
[1746.0, 1270.0]
[380, 215]
p02685
u184817817
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['#E\nn,m,k = list(map(int,input().split()))\nfac = [1,1]\nfinv = [1,1]\ninv = [1,1]\nMOD = 998244353\nfor i in range(2,n):\n fac[i].append(fac[i-1]*i%MOD)\n inv[i].append(MOD-inv[MOD%i]*(MOD//i)%MOD)\n finv[i].append(finv[i-1]*inv[i]%MOD)\ndef comb(n,k):\n return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD\nans = 0...
['Runtime Error', 'Accepted']
['s599419892', 's635252262']
[9224.0, 32616.0]
[22.0, 764.0]
[447, 426]
p02685
u201387466
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['import sys\ninput=sys.stdin.readline\nsys.setrecursionlimit(10 ** 6)\nfrom collections import defaultdict\nimport fractions\nimport math\nfrom collections import deque\nfrom bisect import bisect_left\nfrom bisect import insort_left\nimport itertools\nfrom heapq import heapify\nfrom heapq import heappop\nfrom heapq im...
['Wrong Answer', 'Accepted']
['s111118630', 's765299579']
[2541204.0, 50552.0]
[2275.0, 849.0]
[1116, 1194]
p02685
u221061152
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['n,m,k=map(int,input().split())\nmod = 998244353\nnCi = [1]\nfor i in range(n):\n next = nCi[i]*(n-1-i)*pow(i+1,mod-2,mod)\n next %= mod\n nCi.append(next)\nprint(nCi)\nans = 0\nfor i in range(k+1):\n ans += m*pow(m-1,n-i-1,mod)*nCi[i]\n ans %= mod\nprint(ans)', 'n,m,k=map(int,input().split())\nmod = 998244353\nn...
['Wrong Answer', 'Accepted']
['s540003301', 's301264133']
[21176.0, 16892.0]
[1337.0, 1313.0]
[287, 288]
p02685
u221998589
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['#import numpy as np\nimport math\n#from decimal import *\n#from numba import njit\n\ndef main():\n (N, M, K) = map(int, input().split())\n MOD = 998244353\n \n fact = [1]*(N+1)\n factinv = [1]*(N+1)\n for i in range(1,K+1):\n fact[i] = fact[i-1]*i % MOD\n factinv[i] = pow(fact[i], MOD-...
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s387703210', 's717130020', 's300775095']
[24644.0, 574952.0, 24604.0]
[1328.0, 2220.0, 1254.0]
[518, 438, 518]
p02685
u243714267
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['n, m, k = map(int, input().split())\nmod = 998244353\ndef powerDX(n, r, mod):\n if r == 0: return 1\n if r%2 == 0:\n return powerDX(n*n % mod, r//2, mod) % mod\n if r%2 == 1:\n return n * powerDX(n, r-1, mod) % mod\n\ndef combination(n, r, mod):\n n1, r = n+1, min(r, n-r)\n numer = denom = 1\n for i...
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s733342843', 's822803593', 's380736357']
[9084.0, 9056.0, 33156.0]
[2206.0, 31.0, 766.0]
[564, 63, 662]
p02685
u266014018
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
["class Combination():\n def __init__(self, n, mod=10**9+7):\n self.mod = mod\n self.fac = [1]*(n+1)\n for i in range(1,n+1):\n self.fac[i] = self.fac[i-1] * i % self.mod\n self.invfac = [1]*(n+1)\n self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)\n for i...
['Runtime Error', 'Accepted']
['s710346061', 's084223889']
[26220.0, 34044.0]
[131.0, 284.0]
[1210, 1210]
p02685
u276204978
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['import math\n\nN, M, K = map(int, input().split())\n\ndef combinations(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\nans = 0\ncol = m\nfor k in range(N-1, -1, -1):\n now = col\n now *= combinations(N-1, k);\n if k <= K:\n ans += now\n col *= m-1\n\nprint(ans...
['Runtime Error', 'Accepted']
['s699542804', 's950314224']
[9164.0, 24668.0]
[25.0, 669.0]
[303, 676]
p02685
u285891772
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
["import sys, re\nfrom collections import deque, defaultdict, Counter\nfrom math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2\nfrom itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby\nfrom operator import itemgetter, mul\nfrom copy import de...
['Wrong Answer', 'Accepted']
['s214202863', 's867046840']
[43544.0, 25436.0]
[2207.0, 670.0]
[1033, 1214]
p02685
u288430479
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['n,m,k = map(int,input().split())\nmod = 998244353\nans = 0\n\ndef comb(n,k,mod):\n nCk = 1\n\n for i in range(n-k+1, n+1):\n nCk *= i\n nCk %= mod\n \n for i in range(1,k+1):\n nCk *= pow(i,mod-2,mod)\n nCk %= mod\n return nCk\nfor i in range(k+1):\n a = pow(m-1, n-i-1, mod)...
['Wrong Answer', 'Accepted']
['s245395539', 's990225381']
[9224.0, 33168.0]
[2206.0, 748.0]
[380, 530]
p02685
u307622233
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['n, m, k = map(int, input().split())\nMOD = 998244353\n\nans = 0\nfor i in range(k + 1):\n ans += (ans + m * pow(m - 1, m - i - 1, MOD)) % MOD\n c = (c * (n - 1 - i) * pow(i + 1, MOD - 2, MOD)) % MOD\n\nprint(ans)\n', 'n, m, k = map(int, input().split())\nMOD = 998244353\n\nans = 0\nc = 1\nfor i in range(k + 1):...
['Runtime Error', 'Accepted']
['s010625163', 's366618014']
[9180.0, 9192.0]
[22.0, 1263.0]
[211, 252]
p02685
u324090406
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['from scipy.special import comb\n\nN, M, K = list(map(int, input().split()))\nmod = 998244353\n\nanswer = 0\nfor i in range(K+1):\n answer += (M * ((comb(N-1, i)) % mod) * (((M-1) ** (N-1-i)) % mod)) % mod\n answer = answer % mod\n\nprint(answer)', 'N, M, K = list(map(int, input().split()))\nmod = 998244353\n\nc...
['Wrong Answer', 'Accepted']
['s466720883', 's888809744']
[43928.0, 9100.0]
[2207.0, 1291.0]
[241, 241]
p02685
u408620326
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
["def main():\n import sys\n sys.setrecursionlimit(10**6)\n input = sys.stdin.readline\n N, M, K = [int(x) for x in input().strip().split()]\n MOD = 998244353\n if M == 1:\n if N == 1:\n print(1)\n exit()\n \n fact = [1] * (N+1)\n inv_fact = [1] * (N+1)\n for i...
['Wrong Answer', 'Accepted']
['s033910013', 's936746568']
[12152.0, 24584.0]
[564.0, 632.0]
[835, 850]
p02685
u461454424
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['#atcoder template\ndef main():\n import sys\n imput = sys.stdin.readline\n \n #input\n N, M, K = map(int, input().split())\n\n #output\n mod = 998244353\n\n n_ = 4*10**5 + 5\n fun = [1]*(n_+1)\n for i in range(1,n_+1):\n fun[i] = fun[i-1]*i%mod\n rev = [1]*(n_+1)\n rev[n_] =...
['Runtime Error', 'Accepted']
['s346210957', 's129469763']
[9176.0, 40528.0]
[24.0, 709.0]
[767, 753]
p02685
u476674874
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['import math\nmod = 998244353\n\nimport numpy as np\ndef create_modC(n, mod):\n if n == 0:\n return (lambda r: 1)\n b = int(math.log(mod-2, 2)) + 1\n fac = np.zeros((b, n+1), dtype=np.int64)\n print(fac.shape)\n inv = np.ones(n+1, dtype=np.int64)\n fac[0, 0], fac[0, 1] = 1, 1\n for i in ran...
['Time Limit Exceeded', 'Accepted']
['s060095185', 's473220464']
[78576.0, 78396.0]
[2208.0, 1450.0]
[3173, 3175]
p02685
u506689504
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['import itertools\nimport numpy as np\nfrom scipy.special import comb\n\nmod = 998244353\n\nN,M,K = map(int, input().split())\n\n# DP = [[0]*N for _ in range(N)]\n# DP[0][0] = M\n\n# DP = []\n\n\n# for n in range(1,N):\n# \tfor k in range(N):\n# \t\tif k==0:\n# \t\t\tDP[n][k] = DP[n-1][k]*(M-1) % mod\n# \t\telse:\n# \...
['Runtime Error', 'Runtime Error', 'Accepted']
['s573868538', 's675538271', 's663837991']
[43904.0, 43816.0, 69576.0]
[1507.0, 1491.0, 1045.0]
[485, 487, 750]
p02685
u521602455
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['N,M,K=map(int,input().split())\nP=998244353\nclass FactInv:\n def __init__(self,N,P):\n fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)\n for i in range(1,N):\n fact[i+1]=(fact[i]*(i+1))%P\n ifact[-1]=pow(fact[-1],P-2,P)\n for i in range(N,0,-1):\n ifact[i-1]=(ifac...
['Runtime Error', 'Accepted']
['s645478103', 's212470863']
[24708.0, 24608.0]
[107.0, 650.0]
[574, 575]
p02685
u537142137
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['#factorial\nmod = 998244353 \nN = 1000000\nmodinv_t = [0, 1]\nmodfact_t = [1, 1]\nmodfactinv_t = [1, 1]\nfor i in range(2,N+1):\n modfact_t.append(modfact_t[-1] * i % MOD)\n modinv_t.append(modinv_t[MOD%i] * (MOD-(MOD//i)) % MOD)\n modfactinv_t.append(modfactinv_t[-1] * modinv_t[-1] % MOD)\n\ndef nPr(n, r):\n ret...
['Runtime Error', 'Accepted']
['s281566067', 's054380469']
[9176.0, 127680.0]
[26.0, 1648.0]
[649, 655]
p02685
u539692012
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['MOD = 998244353\nclass mint:\n def __init__(self, i):\n self.i = i\n def __add__(self, m):\n t = self.i + (m.i if isinstance(m, mint) else m)\n if t > MOD:\n t -= MOD\n return mint(t)\n def __radd__(self, m):\n t = self.i + (m.i if isinstance(m, mint) else m)\n ...
['Wrong Answer', 'Accepted']
['s460514398', 's113261103']
[64284.0, 64428.0]
[1646.0, 1583.0]
[1530, 1513]
p02685
u578514593
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['mod = 998244353\n\nclass mod_combination:\n def __init__(self, N):\n self.fac = [1] * (N + 1)\n for i in range(1, N + 1):\n self.fac[i] = (self.fac[i - 1] * i) % mod\n self.invmod = [1] * (N + 1)\n self.invmod[N] = pow(self.fac[N], mod - 2, mod)\n for i in range(N, 0, ...
['Wrong Answer', 'Accepted']
['s395556801', 's649794543']
[24712.0, 24580.0]
[664.0, 675.0]
[681, 683]
p02685
u594956556
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['N, M, K = map(int, input().split())\n\nMOD = 998244353\ninvmod = [pow(i, MOD-2, MOD) for i in range(200002)]\n\nnow = M * pow(M-1, N-1, MOD)\nans = now\nif K == 1:\n print(ans)\n exit()\n\nfor ki in range(1, K+1):\n now = now * invmod[M-1] * (N-ki) * invmod[ki] % MOD\n ans += now\n \nprint(ans % MOD)\n', 'N, M, ...
['Wrong Answer', 'Accepted']
['s408810923', 's253661809']
[17052.0, 17092.0]
[894.0, 903.0]
[292, 402]
p02685
u609307781
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['# E\n\nN, M, K = list(map(int, input().split()))\n\nres = [0] * (K+1)\nres[0] = (M * (M-1)**(N-1 - K)) % p\np = 998244353\nfor n in range(1, K+1):\n res[n] = (res[n-1] * (N-n) * pow(n, p-2, p)) % p\n\nprint(sum(res) % p)', '60522 114575 7559', 'N, M, K = list(map(int, input().split()))\np = 998244353\ncomb = 1\nre...
['Runtime Error', 'Runtime Error', 'Accepted']
['s109189677', 's892387140', 's635942203']
[10624.0, 9068.0, 9204.0]
[242.0, 26.0, 1268.0]
[213, 17, 213]
p02685
u619144316
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['import math\n\nN ,M, K = map(int,input().split())\nMOD = 998244353\nSUM = 0\n\nfact = [1]\nfact_inv = [1]\nfor i in range(1,N+1):\n fact.append(fact[-1] * i)\n fact_inv.append(pow(fact[-1],MOD-2,MOD))\n\nprint(fact)\n\ndef combinations_count(n, r):\n return (fact[n] * fact_inv[n-r] * fact_inv[r])%MOD\n\n\nfo...
['Wrong Answer', 'Accepted']
['s704055874', 's808443580']
[564036.0, 26544.0]
[2223.0, 190.0]
[437, 430]
p02685
u659712937
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['N,M,K=map(int, input().split())\n\n\n\n# import sys\n\nnCr = {}\ndef cmb(n, r):\n if r == 0 or r == n: return 1\n if r == 1: return n\n if (n,r) in nCr: return nCr[(n,r)]\n nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)\n return nCr[(n,r)]\n\na = cmb(n,r)\n\nans=0\n\nfor i in range(K+1):\n temp=(M*(M-1)**(N-1...
['Runtime Error', 'Accepted']
['s321058610', 's297688254']
[9236.0, 26100.0]
[22.0, 204.0]
[1001, 791]
p02685
u664373116
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['#n=int(input())\n#n,m=list(map(int,input().split()))\n#a=list(map(int,input().split()))\nimport sys\nsys.setrecursionlimit(10**6)\nimport math\nimport itertools\nfrom collections import defaultdict\nfrom collections import Counter\nimport numpy as np\n\nimport heapq\n\n\nn,k,x=list(map(int,input().split()))\nod=99824...
['Wrong Answer', 'Accepted']
['s476972745', 's466334352']
[26816.0, 58340.0]
[113.0, 1544.0]
[357, 1043]
p02685
u667084803
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['N, M, K = map(int, input().split())\n\n\ndef power_func(a,n,p):\n bi = str(format(n,"b"))\n res = 1\n for i in range(len(bi)):\n res = (res*res) % p\n if bi[i] == "1":\n res = (res*a) % p\n return res\n\nP = 998244353\ninv_t = [0] + [1]\nfor i in range(2, N+2):\n inv_t += [inv_...
['Runtime Error', 'Accepted']
['s895912771', 's886902285']
[8992.0, 16944.0]
[22.0, 244.0]
[533, 651]
p02685
u669812251
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['# -*- coding: utf-8 -*-\n\n\nn, m, k = map(int,input().split())\n\ndef cmb(n, r, p):\n if (r < 0) or (n < r):\n return 0\n r = min(r, n - r)\n return fact[n] * factinv[r] * factinv[n-r] % p\n\np = 998244353\nN = n+1 \nfact = [1, 1] # fact[n] = (n! mod p)\nfactinv = [1, 1] # factinv[n] = ((n!)^(-1) m...
['Runtime Error', 'Accepted']
['s746591043', 's080863576']
[9104.0, 40592.0]
[21.0, 458.0]
[751, 750]
p02685
u686230543
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['mod = 998244353\n\nn, m, k = map(int, input().split())\ncount = 0\n\ncomb = 1\nfor i in range(k + 1):\n tmp = comb * m * pow(m-1, n-i-1, mod) % mod\n count = (count + tmp) % mod\n comb = comb * (n - i) * pow(i+1, mod-2, mod) % mod\nprint(count)', 'mod = 998244353\n\nn, m, k = map(int, input().split())\ncount = 0\n...
['Wrong Answer', 'Accepted']
['s120801355', 's262426952']
[9196.0, 9196.0]
[1270.0, 1284.0]
[237, 241]
p02685
u709304134
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['N,M,K = map(int,input().split())\n# dp = [[0]*(K+2) for _ in range(2)]\n\n# print (1)\n# dp[0][0] = M\n# MOD = 998244353\n# for n in range(N-1):\n# n = n % 2\n# a = (n+1) % 2\n\n# for k in range(K+1):\n \n \n \n# dp[a][k] += dp[n][k] * (M-1)\n# dp[a][k+1] += dp[n][k]\n...
['Runtime Error', 'Accepted']
['s629009683', 's775624331']
[29752.0, 24476.0]
[2206.0, 1420.0]
[619, 562]
p02685
u764956288
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['def inverse_mod(a, mod=10**9+7):\n """ Calculate inverse of the integer a modulo mod.\n """\n return pow(a, mod-2, mod)\n\n\ndef combination_mod(n, r, mod=10**9+7):\n \n\n r = min(r, n-r)\n numerator = denominator = 1\n for i in range(r):\n numerator = numerator * (n - i) % mod\n de...
['Runtime Error', 'Wrong Answer', 'Accepted']
['s074682871', 's166479111', 's377954695']
[10588.0, 16820.0, 16732.0]
[26.0, 173.0, 167.0]
[1198, 1228, 1314]
p02685
u781262926
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
["class Factorial():\n def __init__(self, mod=10**9 + 7):\n self.mod = mod\n self._factorial = [1]\n self._size = 1\n self._factorial_inv = [1]\n self._size_inv = 1\n \n def __call__(self, n):\n return self.fact(n)\n \n def fact(self, n):\n ''' n! % mod ''...
['Runtime Error', 'Accepted']
['s364516656', 's484581697']
[9212.0, 24472.0]
[26.0, 835.0]
[2451, 3000]
p02685
u785573018
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['n, m, k = map(int, input().split())\nif n <= k+1:\n print(m**n)\nelse:\n a = [m*((m-1)**(n-1))]\n b = [1]\n c = 0\n for i in range(k):\n b.append(int(b[-1]/(i+1)*(n-i-1)))\n for i in range(k):\n a.append(int((a[-1]*b[i+1])/b[i]/(m-1))\n for i in range(k+1):\n c += a[i]\n p...
['Runtime Error', 'Runtime Error', 'Accepted']
['s013339458', 's315019617', 's070072668']
[8996.0, 13872.0, 49644.0]
[23.0, 147.0, 395.0]
[322, 426, 588]
p02685
u788703383
2,000
1,048,576
There are N blocks arranged in a row. Let us paint these blocks. We will consider two ways to paint the blocks different if and only if there is a block painted in different colors in those two ways. Find the number of ways to paint the blocks under the following conditions: * For each block, use one of the M colo...
['M = 998244353\nn,m,K = map(int,input().split())\nans = 0\nc = 1\nfor k in range(K+1):\n ans += c * m * pow(m-1,n-k-1,M)\n c *= (n-k+1) * pow(k+1,M-2,M)\n ans %= M\n c %= M\nprint(ans)\n \n', 'M = 998244353\nn,m,K = map(int,input().split())\nans = 0\nc = 1\nfor k in range(K+1):\n ans += c * m * pow(m...
['Wrong Answer', 'Accepted']
['s433932695', 's700229452']
[9124.0, 9028.0]
[1273.0, 1274.0]
[192, 187]