結果

問題 No.1306 Exactly 2 Digits
ユーザー Wizist
提出日時 2020-12-04 03:36:15
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,462 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 399,076 KB
平均クエリ数 352.47
最終ジャッジ日時 2024-07-17 09:23:37
合計ジャッジ時間 43,339 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49 RE * 33 TLE * 4 -- * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
#
# No.1306 Exactly 2 Digits
#
import sys, os, math

def read_int(): return int(input())
def read_ints(): return list(map(int, input().split()))

n = read_int()
m = n * n - n
a = [None for _ in range(m)]

z = {}
for i in range(n, n * n):
	for j in range(n, n * n):
		if i != j:
			p, q = i // n - j // n, i % n - j % n
			if p > q: p, q = q, p
			if (p, q) not in z: z[(p, q)] = []
			z[(p, q)].append((i, j))
# print(z)
d = {}
i = 0
for j in range(i + 1, m):
	print("? {} {}".format(i + 1, j + 1), flush=True)
	p, q = read_ints()
	s1, s2 = set(), set()
	for x, y in z[(p, q)]:
		if (not a[i] or x in a[i]) and (not a[j] or y in a[j]):
			s1.add(x); s2.add(y)
	a[i] = s1; a[j] = s2
	if len(a[i]) == 1: d[list(a[i])[0]] = i
	if len(a[j]) == 1: d[list(a[j])[0]] = j
	# print(a[i], a[j], d, file=sys.stderr)

t = []
for i, s in enumerate(a):
	if len(s) > 1:
		for x in list(s):
			if x in d: s.remove(x)
		if len(s) == 1:
			d[list(s)[0]] = i
	if len(s) > 1: t.append(i)

while len(t) > 0:
	j = t.pop()
	for k, i in d.items():
		if i == 0: continue
		print("? {} {}".format(i + 1, j + 1), flush=True)
		p, q = read_ints()
		s = set()
		for x, y in z[(p, q)]:
			if (not a[i] or x in a[i]) and (not a[j] or y in a[j]):
				s.add(y)
		a[j] = s
		# print(a[i], a[j], file=sys.stderr)
		if len(a[j]) == 1: break
	if len(a[j]) == 1: d[list(a[j])[0]] = j
	else: t.append(j)

print("! {}".format(" ".join([str(list(x)[0]) for x in a])), flush=True)
0