結果

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

ソースコード

diff #
raw source code

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;

// マクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define each(x, v) for (auto &x : v)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(x) ((int)(x).size())
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 998244353;

const int MAX_SIZE = 9000000;

int mySqrt(int x){
    for(int i = 0; i < 10; i++){
        if(x == i * i){
            return i;
        }
    }
    return -1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    if(n == 2){
        cout << "? " << 0 << " " << 1 << endl;
        cout.flush();
        int special;
        cin >> special;
        if(special == 1){
            cout << "! 11" << endl;
            cout.flush();
        } else if(special == 49){
            cout << "! 77" << endl;
            cout.flush();
        } else if(special == 64){
            cout << "! 88" << endl;
            cout.flush();
        } else if(special == 81){
            cout << "! 99" << endl;
            cout.flush();
        } else {
            cout << "! -1" << endl;
            cout.flush();
        }
        return 0;
    }
    int x[n];
    int idx = 1;
    int a = n-2;
    int b = n-3;
    int x0a, x0b;
    cout << "? " << n-1 << " " << a << endl;
    cin >> x0a;
    cout << "? " << n-1 << " " << b << endl;
    cin >> x0b;
    int i;
    if(x0a != 0 && x0b != 0) {
        cout << "? " << a << " " << b << endl;
        cout.flush();
        int xab;
        cin >> xab;
        x[n-1] = mySqrt(x0a * x0b / xab);
        x[a] = x0a / x[n-1];
        x[b] = x0b / x[n-1];
    }
    for(i = n-4; i >= 0; i--){
        if(x0a == 0){
            x[a] = 0;
            a = i;
            cout << "? " << n-1 << " " << a << endl;
            cout.flush();
            cin >> x0a;
        } else if(x0b == 0){
            x[b] = 0;
            b = i;
            cout << "? " << n-1 << " " << b << endl;
            cout.flush();
            cin >> x0b;
        }
        if(x0a != 0 && x0b != 0) {
            cout << "? " << a << " " << b << endl;
            cout.flush();
            int xab;
            cin >> xab;
            x[n-1] = mySqrt(x0a * x0b / xab);
            x[a] = x0a / x[n-1];
            x[b] = x0b / x[n-1];
            i -= 1;
            break;
        }
    }
    if(x0a == 0 && x0b == 0){
        cout << "! -1" << endl;
        cout.flush();
        return 0;
    } else if(x0a == 0){
        cout << "? " << n-1 << " " << b << endl;
        cout.flush();
        int special;
        cin >> special;
        if(special == 1){
            x[n-1] = 1;
            x[b] = 1;
        }
        if(special == 49){
            x[n-1] = 7;
            x[b] = 7;
        } else if(special == 64){
            x[n-1] = 8;
            x[b] = 8;
        } else if(special == 81){
            x[n-1] = 9;
            x[b] = 9;
        } else {
            cout << "! -1" << endl;
            cout.flush();
            return 0;
        }
    } else if(x0b == 0){
        cout << "? " << n-1 << " " << a << endl;
        cout.flush();
        int special;
        cin >> special;
        if(special == 1){
            x[n-1] = 1;
            x[a] = 1;
        }
        if(special == 49){
            x[n-1] = 7;
            x[a] = 7;
        } else if(special == 64){
            x[n-1] = 8;
            x[a] = 8;
        } else if(special == 81){
            x[n-1] = 9;
            x[a] = 9;
        } else {
            cout << "! -1" << endl;
            cout.flush();
            return 0;
        }
    }

    for(; i >= 0; i--){
        cout << "? " << n-1 << " " << i << endl;
        cout.flush();
        int x0i;
        cin >> x0i;
        x[i] = x0i / x[n-1];
    }

    cout << "! ";
    for(int i = n-1; i >= 0; i--){
        cout << x[i];
    }
    cout << endl;
    cout.flush();

    return 0;
}
0