結果

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

ソースコード

diff #
raw source code

#include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
#include <random>
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
// #include "Src/DataStructure/DisjointSetUnion/DisjointSetUnion.hpp"
// #include "Src/DataStructure/Heap/BinaryHeap.hpp"
// #include "Src/Number/LinearSieve.hpp"
namespace zawa {}
using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
// #include <array>
// #include <bit>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <set>
// #include <unordered_set>
// #include <map>
// #include <unordered_map>
// #include <optional>
// #include <queue>
// #include <stack>
// #include <deque>
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0 ; i < ssize(v) ; i++)
        os << v[i] << (i + 1 == ssize(v) ? "" : " ");
    return os;
}
/*
 * n桁に対してn回クエリがある
 * S[1]は正だから、S[2],...,S[N]をS[1]と一緒に聞くと、全部S[1]の倍数になる (ついでに0の桁がわかる)
 * 0がN-1桁あるとダメ
 * 0がN-2桁で非零を聞いたときに1より大きいとダメ
 * それ以外はなんとかなっている?
 * それ以外は非零の二けたで最後の一回を聞くことで、先頭桁が特定できて、全部特定できる
 * WA: まじ?
 * WA: 42ケース。
 * X = 110は特定できる?
 */
int main() {
    // cin.tie(0);
    // cout.tie(0);
    // ios::sync_with_stdio(0);
    // cout << fixed << setprecision(20);
#if !defined DEBUG
    int N;
    cin >> N;
    vector<int> dat(N), pos;
    int g = 0;
    for (int i = 1 ; i < N ; i++) {
        cout << "? " << 0 << ' ' << i << endl;
        cin >> dat[i];
        if (dat[i] == -1)
            exit(0);
        if (dat[i] > 0)
            pos.push_back(i);
        g = gcd(g,dat[i]);
    }
    if (g == 0) {
        cout << "! -1" << endl;
        return 0;
    }
    else if (g == 1) {
        dat[0] = 1;
        cout << "! ";
        for (int i = 0 ; i < N ; i++)
            cout << dat[i];
        cout << endl;
        return 0;
    }
    if (ssize(pos) < 2) {
        cout << "! -1" << endl;
        return 0;
    }
    cout << "? " << pos[0] << ' ' << pos[1] << endl;
    int v;
    cin >> v;
    int cnt = 0;
    vector<int> ans(N);
    for (int i = 1 ; i <= g ; i++)
        if (g % i == 0 and dat[pos[0]]/i*dat[pos[1]]/i == v) {
            cnt++;
            ans[0] = i;
        }
    if (cnt != 1)
        cout << "! -1" << endl;
    else {
        for (int i = 1 ; i < N ; i++)
            ans[i] = dat[i]/ans[0];
        cout << "! ";
        for (int i = 0 ; i < N ; i++)
            cout << ans[i];
        cout << endl;
    }
#else
    mt19937_64 mt{random_device{}()};
    for (int testcase = 0 ; ; ) {
        cerr << "----------" << ++testcase << "----------" << endl;
        
        auto a = solve(), b = naive();
        if (a != b) {
            // print testcase

            cerr << "you: " << a << endl;
            cout << "correct: " << b << endl;
            exit(0);
        }
    }
#endif
}
0