Submission #59174983
Source Code Expand
Copy
# import sys, itertools, bisect, pypyjitfrom ast import Strimport sys, math, heapq, itertoolsfrom collections import Counter, defaultdict, dequefrom itertools import permutationssys.setrecursionlimit(1000000)# import pypyjit# pypyjit.set_param("max_unroll_recursion=-1")readline = sys.stdin.readline# N=2*(10^5)# A=[10^9]*N# S = list(readline().rstrip())# N= int(readline().rstrip())N, K = map(int, readline().rstrip().split())# M = int(readline().rstrip())P = list(map(int, readline().rstrip().split()))# markets = []NP = [p - 1 for p in P]
# import sys, itertools, bisect, pypyjit from ast import Str import sys, math, heapq, itertools from collections import Counter, defaultdict, deque from itertools import permutations sys.setrecursionlimit(1000000) # import pypyjit # pypyjit.set_param("max_unroll_recursion=-1") readline = sys.stdin.readline # N=2*(10^5) # A=[10^9]*N # S = list(readline().rstrip()) # N= int(readline().rstrip()) N, K = map(int, readline().rstrip().split()) # M = int(readline().rstrip()) P = list(map(int, readline().rstrip().split())) # markets = [] NP = [p - 1 for p in P] # for _ in range(M): # T, P = map(int, readline().rstrip().split()) # markets.append((T, P)) visited = [False] * N result = [0] * N for i in range(N): if not visited[i]: cycle = [] x = i while not visited[x]: visited[x] = True cycle.append(x) x = NP[x] L = len(cycle) if L == 0: continue shift = pow(2, K, L) for idx in range(L): new_idx = (idx + shift) % L result[cycle[idx]] = cycle[new_idx] + 1 print(" ".join(map(str, result)))
Submission Info
Submission Time | |
---|---|
Task | E - Permute K times 2 |
User | imuraya |
Language | Python (PyPy 3.10-v7.3.12) |
Score | 475 |
Code Size | 1180 Byte |
Status | AC |
Exec Time | 179 ms |
Memory | 135128 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 475 / 475 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 108 ms | 82668 KB |
00_sample_01.txt | AC | 108 ms | 82744 KB |
00_sample_02.txt | AC | 104 ms | 82740 KB |
01_random_03.txt | AC | 119 ms | 87876 KB |
01_random_04.txt | AC | 132 ms | 101968 KB |
01_random_05.txt | AC | 164 ms | 123748 KB |
01_random_06.txt | AC | 160 ms | 123984 KB |
01_random_07.txt | AC | 166 ms | 123912 KB |
01_random_08.txt | AC | 164 ms | 123584 KB |
01_random_09.txt | AC | 164 ms | 124068 KB |
01_random_10.txt | AC | 161 ms | 122656 KB |
01_random_11.txt | AC | 157 ms | 122460 KB |
01_random_12.txt | AC | 160 ms | 126012 KB |
01_random_13.txt | AC | 123 ms | 90904 KB |
01_random_14.txt | AC | 120 ms | 87588 KB |
01_random_15.txt | AC | 137 ms | 102176 KB |
01_random_16.txt | AC | 163 ms | 124072 KB |
01_random_17.txt | AC | 169 ms | 123668 KB |
01_random_18.txt | AC | 177 ms | 126700 KB |
01_random_19.txt | AC | 174 ms | 125980 KB |
01_random_20.txt | AC | 126 ms | 93484 KB |
01_random_21.txt | AC | 169 ms | 135128 KB |
01_random_22.txt | AC | 168 ms | 134884 KB |
01_random_23.txt | AC | 171 ms | 135012 KB |
01_random_24.txt | AC | 162 ms | 135096 KB |
01_random_25.txt | AC | 176 ms | 135092 KB |
01_random_26.txt | AC | 174 ms | 131392 KB |
01_random_27.txt | AC | 171 ms | 132472 KB |
01_random_28.txt | AC | 170 ms | 133504 KB |
01_random_29.txt | AC | 167 ms | 134740 KB |
01_random_30.txt | AC | 179 ms | 133264 KB |
01_random_31.txt | AC | 177 ms | 132852 KB |
01_random_32.txt | AC | 172 ms | 135016 KB |
01_random_33.txt | AC | 168 ms | 130568 KB |
01_random_34.txt | AC | 172 ms | 134100 KB |
01_random_35.txt | AC | 168 ms | 132268 KB |
01_random_36.txt | AC | 171 ms | 132084 KB |
01_random_37.txt | AC | 167 ms | 132000 KB |
01_random_38.txt | AC | 165 ms | 131512 KB |
01_random_39.txt | AC | 173 ms | 133288 KB |
01_random_40.txt | AC | 166 ms | 131924 KB |
01_random_41.txt | AC | 170 ms | 134136 KB |
01_random_42.txt | AC | 108 ms | 82756 KB |
01_random_43.txt | AC | 109 ms | 82692 KB |
01_random_44.txt | AC | 108 ms | 82792 KB |
01_random_45.txt | AC | 108 ms | 82536 KB |
01_random_46.txt | AC | 107 ms | 82700 KB |
01_random_47.txt | AC | 108 ms | 82576 KB |
01_random_48.txt | AC | 106 ms | 82996 KB |
01_random_49.txt | AC | 107 ms | 82656 KB |