結果

問題 No.3501 Digit Products 2
コンテスト
ユーザー nagasan0210
提出日時 2026-04-17 21:34:01
言語 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
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 2,511 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,108 ms
コンパイル使用メモリ 335,020 KB
実行使用メモリ 30,320 KB
平均クエリ数 10.89
最終ジャッジ日時 2026-04-17 21:34:42
合計ジャッジ時間 6,982 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 72
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(a); i > (int)(b); i--)
#define ll long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define PQ priority_queue<int, vector<int>, greater<int>>
#define PQ_g priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
const int d4[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
const int d8[8][2] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};
void Yes(bool b) {cout << (b ? "Yes" : "No") << endl;}

int determine_2_dig(int prod) {
    vector<int> cand;
    rep(i, 10, 100) {
        if ((i % 10) * (i / 10) == prod) cand.push_back(i);
    }

    if (cand.size() >= 2) {
        return -1;
    } else {
        return cand[0];
    }
}

int int_sqrt(int n) {
    int l = 0, r = 1000;
    while (r - l > 1) {
        int m = (l + r) >> 1;
        if (n < m * m) r = m;
        else l = m;
    }
    return l;
}

int main() {
    int n; cin >> n;
    vector<int> ans(n);
    rep(i, 0, n - 1) {
        cout << "? " << i << ' ' << (n - 1) << endl;
        cin >> ans[i];
    }
    if (n == 2) {
        int ans_num = determine_2_dig(ans[0]);
        cout << "! " << ans_num << endl;
    } else {
        vector<int> not_0_ind;
        rep(i, 0, n - 1) {
            if (ans[i] != 0) not_0_ind.push_back(i);
            if (not_0_ind.size() == 2) break;
        }

        bool determined = false;

        if (not_0_ind.size() == 0) {
            cout << "! -1" << endl;
        } else if (not_0_ind.size() == 1) {
            int ind = not_0_ind[0];
            int ans_num = determine_2_dig(ans[ind]);
            if (ans_num == -1) cout << "! -1" << endl;
            else {
                determined = true;
                ans[n - 1] = ans_num / 10;
                ans[ind] = ans_num % 10;
            }
        } else {
            determined = true;
            int ind1 = not_0_ind[0];
            int ind2 = not_0_ind[1];
            cout << "? " << ind1 << ' ' << ind2 << endl;
            int p; cin >> p;
            int leader_ans = int_sqrt(ans[ind1] * ans[ind2] / p);

            ans[n - 1] = leader_ans;
            rep(i, 0, n - 1) ans[i] /= leader_ans;
        }

        if (determined) {
            cout << "! ";
            rrep(i, n - 1, -1) cout << ans[i];
            cout << endl;
        }
    }
}
0