結果

問題 No.2967 Nana's Plus Permutation Game
ユーザー tassei903tassei903
提出日時 2024-11-16 23:14:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 794 ms / 2,000 ms
コード長 3,153 bytes
コンパイル時間 391 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 95,072 KB
平均クエリ数 4170.09
最終ジャッジ日時 2024-11-16 23:15:17
合計ジャッジ時間 32,824 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
68,968 KB
testcase_01 AC 300 ms
89,312 KB
testcase_02 AC 164 ms
80,128 KB
testcase_03 AC 218 ms
82,656 KB
testcase_04 AC 365 ms
92,512 KB
testcase_05 AC 294 ms
85,984 KB
testcase_06 AC 245 ms
84,704 KB
testcase_07 AC 324 ms
92,640 KB
testcase_08 AC 119 ms
70,496 KB
testcase_09 AC 368 ms
93,024 KB
testcase_10 AC 278 ms
87,656 KB
testcase_11 AC 129 ms
70,248 KB
testcase_12 AC 128 ms
70,248 KB
testcase_13 AC 275 ms
85,480 KB
testcase_14 AC 324 ms
87,400 KB
testcase_15 AC 219 ms
83,432 KB
testcase_16 AC 156 ms
80,104 KB
testcase_17 AC 357 ms
93,032 KB
testcase_18 AC 258 ms
83,304 KB
testcase_19 AC 143 ms
75,624 KB
testcase_20 AC 215 ms
82,536 KB
testcase_21 AC 452 ms
94,340 KB
testcase_22 AC 475 ms
94,048 KB
testcase_23 AC 432 ms
93,752 KB
testcase_24 AC 489 ms
94,576 KB
testcase_25 AC 469 ms
94,696 KB
testcase_26 AC 483 ms
94,440 KB
testcase_27 AC 389 ms
93,984 KB
testcase_28 AC 574 ms
94,160 KB
testcase_29 AC 477 ms
94,312 KB
testcase_30 AC 528 ms
94,056 KB
testcase_31 AC 423 ms
94,220 KB
testcase_32 AC 436 ms
94,400 KB
testcase_33 AC 449 ms
93,612 KB
testcase_34 AC 393 ms
93,288 KB
testcase_35 AC 503 ms
94,440 KB
testcase_36 AC 455 ms
93,256 KB
testcase_37 AC 520 ms
94,560 KB
testcase_38 AC 486 ms
94,440 KB
testcase_39 AC 500 ms
94,824 KB
testcase_40 AC 467 ms
94,152 KB
testcase_41 AC 667 ms
94,296 KB
testcase_42 AC 614 ms
94,432 KB
testcase_43 AC 628 ms
94,552 KB
testcase_44 AC 669 ms
94,944 KB
testcase_45 AC 659 ms
94,808 KB
testcase_46 AC 768 ms
94,176 KB
testcase_47 AC 747 ms
94,560 KB
testcase_48 AC 720 ms
94,808 KB
testcase_49 AC 564 ms
94,432 KB
testcase_50 AC 679 ms
94,504 KB
testcase_51 AC 655 ms
94,560 KB
testcase_52 AC 704 ms
94,560 KB
testcase_53 AC 557 ms
94,816 KB
testcase_54 AC 544 ms
95,072 KB
testcase_55 AC 631 ms
95,072 KB
testcase_56 AC 794 ms
94,432 KB
testcase_57 AC 742 ms
94,560 KB
testcase_58 AC 734 ms
94,944 KB
testcase_59 AC 683 ms
94,048 KB
testcase_60 AC 719 ms
94,816 KB
testcase_61 AC 102 ms
69,088 KB
testcase_62 AC 101 ms
69,088 KB
testcase_63 AC 108 ms
69,472 KB
testcase_64 AC 113 ms
69,472 KB
testcase_65 AC 120 ms
69,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

class scc_graph:

    def __init__(self, N):
        self.N = N
        self.edges = []
        self.start = [0] * (N + 1)

    def csr(self):
        for i in range(1, self.N + 1):
            self.start[i] += self.start[i - 1]
        counter = self.start[:]
        self.elist = [0] * len(self.edges)
        for a, b in self.edges:
            self.elist[counter[a]] = b
            counter[a] += 1

    def add_edge(self, a, b):
        self.edges.append((a, b))
        self.start[a + 1] += 1

    def scc(self):
        self.csr()
        N = self.N
        now_ord = group_num = 0
        visited = []
        low = [0] * N
        order = [-1] * N
        ids = [0] * N
        parent = [-1] * N
        stack = []
        groups = []
        for i in range(N):
            if order[i] == -1:
                stack.append(i)
                stack.append(i)
                while stack:
                    v = stack.pop()
                    if order[v] == -1:
                        low[v] = order[v] = now_ord
                        now_ord += 1
                        visited.append(v)
                        for i in range(self.start[v], self.start[v + 1]):
                            to = self.elist[i]
                            if order[to] == -1:
                                stack.append(to)
                                stack.append(to)
                                parent[to] = v
                            else:
                                low[v] = min(low[v], order[to])
                    else:
                        if low[v] == order[v]:
                            group = []
                            while True:
                                u = visited.pop()
                                order[u] = N
                                ids[u] = group_num
                                group.append(u)
                                if u == v:
                                    break
                            groups.append(group)
                            group_num += 1
                        if parent[v] != -1:
                            low[parent[v]] = min(low[parent[v]], low[v])
        for i, x in enumerate(ids):
            ids[i] = group_num - 1 - x
        return group_num, ids, groups[::-1]

def ask(i, j):
    print("1", i, j, flush=True)
    return ni()

n = ni()

p = [-1] + [ask(i, i) for i in range(1, n + 1)]

scc = scc_graph(n + 1)
for i in range(1, n + 1):
    if p[i] != -1:
        scc.add_edge(p[i], i)

group_num, ids, groups = scc.scc()

dp = [0] * (n + 1)

for i in groups:
    x = i[0]
    if p[x] == -1:
        continue
    dp[x] = dp[p[x]] + 1
i = dp.index(max(dp))
ans = [-1] * (1 + n)
ans[i] = 1
now = i
for j in range(n - 1):
    k = ask(now, i)
    ans[k] = j + 2
    now = k

print(2, *ans[1:])
0