結果

問題 No.3501 Digit Products 2
コンテスト
ユーザー Naru820
提出日時 2026-03-28 05:01:13
言語 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  
(最新)
AC  
(最初)
実行時間 -
コード長 1,439 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,469 ms
コンパイル使用メモリ 333,128 KB
実行使用メモリ 30,320 KB
平均クエリ数 10.44
最終ジャッジ日時 2026-04-17 19:49:30
合計ジャッジ時間 19,418 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 72
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;

int n,cnt;
int query(int a,int b){
    cout << "? " << a << " " << b << endl;
    int x;
    cin >> x;
    return x;
}
int main(){
    cin >> n;
    vector<int> a(n - 1);
    for(int i = 0; i < n - 1; i++){
        a[i] = query(n - 1,i);
    }
    int cnt = 0,t = 0;
    for(int i = 1;i <= 9; i++){
        int valid = 1;
        for(int j = 0; j < n - 1; j++){
            if(a[j] % i || (a[j] / i > 9)){
                valid = 0;
                break;
            }
        }
        cnt += valid;
        if(valid) t = i;
    }
    if(cnt == 1){
        cout << "! " << t;
        for(int i = n - 2; i >= 0; i--){
            cout << a[i] / t;
        }
        cout << endl;
    }
    else{
        int c = 0,x = 0,y = 0;
        for(int i = 0; i < n - 1; i++){
            if(a[i]) c++,x = y,y = i;
        }
        if(c <= 1){
            cout << "! " << -1 << endl;
            return 0; 
        }
        else{
            cout << "? " << y << " " << x << endl;
            int z;
            cin >> z;
            for(int i = 1; i <= 9; i++){
                if(a[x] % i == 0 && a[y] % i == 0 && (a[x] / i) * (a[y] / i) == z){
                    t = i;
                    break;
                }
            }
            cout << "! " << t;
            for(int i = n - 2; i >= 0; i--){
                cout << a[i] / t;
            }
            cout << endl;
        }
    }
}
0