結果
問題 | No.2496 LCM between Permutations |
ユーザー | naut3 |
提出日時 | 2023-10-06 23:12:26 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,896 bytes |
コンパイル時間 | 275 ms |
コンパイル使用メモリ | 82,220 KB |
実行使用メモリ | 103,272 KB |
平均クエリ数 | 953.07 |
最終ジャッジ日時 | 2024-07-26 16:57:11 |
合計ジャッジ時間 | 5,846 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 67 ms
71,908 KB |
testcase_01 | AC | 64 ms
71,288 KB |
testcase_02 | AC | 64 ms
72,320 KB |
testcase_03 | AC | 64 ms
71,348 KB |
testcase_04 | AC | 63 ms
71,116 KB |
testcase_05 | AC | 62 ms
71,860 KB |
testcase_06 | AC | 62 ms
71,700 KB |
testcase_07 | AC | 63 ms
72,108 KB |
testcase_08 | RE | - |
testcase_09 | AC | 62 ms
72,040 KB |
testcase_10 | AC | 66 ms
72,560 KB |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | AC | 64 ms
72,356 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | AC | 167 ms
95,276 KB |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | AC | 251 ms
101,360 KB |
testcase_27 | RE | - |
testcase_28 | RE | - |
ソースコード
from math import lcm, gcd import random def main(): N = int(input()) A = [-1 for _ in range(N)] B = [-1 for _ in range(N)] res = [[-1 for _ in range(N)] for __ in range(N)] b_lcm_azero = [] r = random.randint(0, N - 1) for i in range(N): print("? {} {}".format(r + 1, i + 1), flush=True) x = int(input()) b_lcm_azero.append(x) res[r][i] = x a_r = min(b_lcm_azero) A[r] = a_r b_one_cand = [] for i in range(N): if b_lcm_azero[i] == a_r: b_one_cand.append(i) cand = [i for i in range(N)] random.shuffle(cand) for i in range(N): r = cand[i] if A[r] != -1: continue values = [] for c in b_one_cand: print("? {} {}".format(r + 1, c + 1), flush=True) x = int(input()) values.append(x) res[r][c] = x b_one_cand_nxt = [] m = min(values) A[r] = m for j in range(len(b_one_cand)): if values[j] == m: b_one_cand_nxt.append(b_one_cand[j]) b_one_cand = b_one_cand_nxt if len(b_one_cand) == 1: break j = b_one_cand[0] B[j] = 1 for i in range(N): if A[i] != -1: continue if res[i][j] != -1: A[i] = res[i][j] continue print("? {} {}".format(i + 1, j + 1), flush=True) x = int(input()) res[i][j] = x A[i] = x j = -1 for i in range(N): if A[i] == 1: j = i for i in range(N): if B[i] != -1: continue if res[j][i] != -1: B[i] = res[j][i] continue print("? {} {}".format(j + 1, i + 1), flush=True) x = int(input()) B[i] = x res[j][i] = x print("!", *A, *B, flush=True) main()