結果
| 問題 | No.3529 2p Teleportations |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2026-06-22 06:25:49 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,437 bytes |
| 記録 | |
| コンパイル時間 | 302 ms |
| コンパイル使用メモリ | 85,456 KB |
| 実行使用メモリ | 88,324 KB |
| 最終ジャッジ日時 | 2026-06-22 06:26:10 |
| 合計ジャッジ時間 | 18,787 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 11 WA * 38 |
ソースコード
import sys
input = sys.stdin.readline
T=int(input())
for tests in range(T):
N,P=list(map(int,input().split()))
A=list(map(int,input().split()))
for i in range(N):
A[i]-=1
A_INV=[-1]*N
for i in range(N):
A_INV[A[i]]=i
USE=[0]*N
ANS=[0]*N
for i in range(N):
if USE[i]==0:
now=i
L=[now]
while True:
USE[now]=1
now=A[now]
if now==L[0]:
break
L.append(now)
#print(L)
c=-1
if len(L)%2==0:
c=L.pop()
k=2*P%len(L)
if k==0:
for x in L:
ANS[x]=x
continue
X=[-1]*len(L)
X[0]=A[i]
X[k]=i
#print(X)
ind=k
while True:
now=X[ind]
c=A_INV[now]
if X[(ind+k)%len(L)]==-1:
X[(ind+k)%len(L)]=c
ind=(ind+k)%len(L)
else:
break
#print("!",X)
for i in range(len(X)):
ANS[X[i]]=X[(i+1)%len(X)]
#print(X[i],X[(i+1)%len(X)])
#print(ANS)
for i in range(N):
ANS[i]+=1
print(*ANS)
titia