結果

問題 No.3501 Digit Products 2
コンテスト
ユーザー dayo ZOI
提出日時 2026-04-18 22:59:20
言語 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,588 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,939 ms
コンパイル使用メモリ 179,688 KB
実行使用メモリ 30,320 KB
平均クエリ数 11.29
最終ジャッジ日時 2026-04-18 22:59:57
合計ジャッジ時間 10,281 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 47 WA * 12 RE * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int sqrt(ll)':
main.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^

ソースコード

diff #
raw source code

#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <cassert>

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < n; ++i)

int sqrt(ll x)
{
    for (int i = 1; i < 10; i++)
        if (x == i * i)
            return i;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> res(10, n);
    vector<ll> non_zero;
    rep(i, n - 1)
    {
        cout << "? " << i << " " << n - 1 << endl;
        cin >> res[i];
        if (res[i] != 0)
            non_zero.emplace_back(i);
    }
    if (non_zero.size() == 0)
    {
        cout << "! -1" << endl;
        return 0;
    }
    if (non_zero.size() == 1)
    {
        ll ret = res[non_zero[0]];
        if (ret == 1)
        {
            cout << "! 11" << endl;
        }
        else if (ret == 25)
        {
            cout << "! 55" << endl;
        }
        else if (ret == 49)
        {
            cout << "! 77" << endl;
        }
        else if (ret == 64)
        {
            cout << "! 88" << endl;
        }
        else if (ret == 81)
        {
            cout << "! 99" << endl;
        }
        else
        {
            cout << "! -1" << endl;
            return 0;
        }
    }
    cout << "? " << non_zero[0] << " " << non_zero[1] << endl;
    ll res01;
    cin >> res01;
    res[n - 1] = res[non_zero[0]] * res[non_zero[1]] / res01;
    ll a_back = sqrt(res[n - 1]);
    cout << "! ";
    rep(i, n)
    {
        ll num = res[n - 1 - i] / a_back;
        cout << res[n - 1 - i] / a_back;
        assert(0 <= num && num <= 9);
    }
    cout << endl;
}
0