結果

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

ソースコード

diff #
raw source code

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

long long ask(int a, int b) {
    cout << "? " << a << " " << b << endl;
    cout.flush();

    long long x;
    cin >> x;
    if (x == -1) exit(0);
    return x;
}

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

    int N;
    cin >> N;

    vector<long long> d(N);

    int i = 0;
    while (i + 2 < N) {
        long long ab = ask(i, i+1);
        long long ac = ask(i, i+2);
        long long bc = ask(i+1, i+2);

        long long A = sqrt((ab * ac) / bc);
        long long B = ab / A;
        long long C = ac / A;

        d[i] = A;
        d[i+1] = B;
        d[i+2] = C;

        i += 3;
    }

    // Handle remaining 1 or 2 digits
    if (i < N) {
        // Use previous digit if exists
        if (i > 0) {
            long long p = ask(i-1, i);
            d[i] = p / d[i-1];
        } else {
            // N = 1 edge (not possible here since N ≥ 2)
        }
    }

    if (i + 1 < N) {
        long long p = ask(i, i+1);
        d[i+1] = p / d[i];
    }

    // Build number
    long long X = 0, pw = 1;
    for (int i = 0; i < N; i++) {
        X += d[i] * pw;
        pw *= 10;
    }

    cout << "! " << X << endl;
    cout.flush();
}
0