結果

問題 No.3501 Digit Products 2
コンテスト
ユーザー V_Melville
提出日時 2026-04-17 22:29:17
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,077 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,641 ms
コンパイル使用メモリ 335,640 KB
実行使用メモリ 29,936 KB
平均クエリ数 10.44
最終ジャッジ日時 2026-04-17 22:29:30
合計ジャッジ時間 12,223 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 43 WA * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

int main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> p(n, -1);
    
    for (int i = 1; i < n; ++i) {
        cout << "? 0 " << i << endl;
        cin >> p[i];
    }

    vector<int> cands;
    vector<int> ans(n, -1);
    
    for (int d = 1; d <= 9; ++d) {
        bool ok = true;
        vector<int> a(n, -1);
        a[0] = d;
        
        for (int i = 1; i < n; ++i) {
            if (p[i]%d) {
                ok = false;
                break;
            }
            int x = p[i]/d;
            if (x < 0 or x > 9) {
                ok = false;
                break;
            }
            a[i] = x;
        }
        
        if (ok) {
            cands.push_back(d);
            ans = a;
        }
    }
    
    if (cands.size() != 1) {
        cout << "! -1" << endl;
        return 0;
    }

    cout << "! ";
    rep(i, n) cout << ans[i];
    cout << endl;
    
    return 0;
}
0