結果

問題 No.3501 Digit Products 2
コンテスト
ユーザー praddumna12
提出日時 2026-04-18 04:36:53
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 920 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 518 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 222,832 KB
平均クエリ数 4.89
最終ジャッジ日時 2026-04-18 04:38:10
合計ジャッジ時間 24,375 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other AC * 27 WA * 33 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

N = int(input())

# Step 1: queries
p = []
for i in range(N-1):
    print(f"? {i} {i+1}", flush=True)
    x = int(input())
    if x == -1:
        exit()
    p.append(x)

# Step 2: enumerate all sequences
candidates = []

def dfs(i, digits):
    if i == N:
        candidates.append(digits[:])
        return
    
    for d in range(10):
        if digits[i-1] * d == p[i-1]:
            digits[i] = d
            dfs(i+1, digits)

# try all starting pairs
for d0 in range(10):
    for d1 in range(10):
        if d0 * d1 != p[0]:
            continue
        
        digits = [0]*N
        digits[0] = d0
        digits[1] = d1
        
        dfs(2, digits)

# Step 3: deduplicate
unique = set(tuple(d) for d in candidates)

# Step 4: output
if len(unique) == 1:
    ans = list(unique)[0]
    print(f"! {''.join(map(str, ans))}", flush=True)
else:
    print("! -1", flush=True)
0