結果
| 問題 | No.3501 Digit Products 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 01:18:05 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 196 ms / 2,000 ms |
| コード長 | 1,594 bytes |
| 記録 | |
| コンパイル時間 | 435 ms |
| コンパイル使用メモリ | 20,824 KB |
| 実行使用メモリ | 35,340 KB |
| 平均クエリ数 | 10.89 |
| 最終ジャッジ日時 | 2026-04-18 01:18:25 |
| 合計ジャッジ時間 | 15,243 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 72 |
ソースコード
import sys
def ask(a, b):
print(f"? {a} {b}", flush=True)
x = int(sys.stdin.readline())
if x == -1:
sys.exit()
return x
def done(ans):
if ans is None:
print("! -1", flush=True)
else:
print("! " + ''.join(map(str, ans[::-1])), flush=True)
sys.exit()
def main():
n = int(sys.stdin.readline())
ways = [[] for _ in range(82)]
for a in range(1, 10):
for b in range(1, 10):
ways[a * b].append((a, b))
top_mul = [0] * (n - 1)
pos = []
for i in range(n - 1):
top_mul[i] = ask(i, n - 1)
if top_mul[i] > 0:
pos.append(i)
if len(pos) >= 2:
a, b = pos[0], pos[1]
mid = ask(a, b)
top = -1
for d in range(1, 10):
if d * d * mid != top_mul[a] * top_mul[b]:
continue
ok = True
for x in top_mul:
if x % d:
ok = False
break
if x // d > 9:
ok = False
break
if ok:
top = d
break
if top == -1:
done(None)
ans = [0] * n
ans[-1] = top
for i in range(n - 1):
ans[i] = top_mul[i] // top
done(ans)
if len(pos) == 1:
i = pos[0]
p = top_mul[i]
if len(ways[p]) == 1:
a, b = ways[p][0]
ans = [0] * n
ans[-1] = a
ans[i] = b
done(ans)
done(None)
if __name__ == "__main__":
main()