結果
| 問題 | No.3501 Digit Products 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 15:15:28 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,428 bytes |
| 記録 | |
| コンパイル時間 | 3,304 ms |
| コンパイル使用メモリ | 334,516 KB |
| 実行使用メモリ | 30,320 KB |
| 平均クエリ数 | 9.44 |
| 最終ジャッジ日時 | 2026-04-18 15:15:59 |
| 合計ジャッジ時間 | 25,823 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 1 |
| other | RE * 72 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
int ref = 0;
vector<int> prod(N, -1);
for (int i = 1; i < N; i++) {
cout << "? " << ref << ' ' << i << '\n';
cout.flush();
int p;
cin >> p;
if (p == -1) return 0; // judge says wrong / too many queries
prod[i] = p;
}
// Try all possible digits for the reference position.
vector<int> candidates;
for (int d = 0; d <= 9; d++) {
bool ok = true;
for (int i = 1; i < N; i++) {
int p = prod[i];
if (p % d != 0) {
ok = false;
break;
}
int x = p / d;
if (x < 0 || x > 9) {
ok = false;
break;
}
}
if (ok) candidates.push_back(d);
}
if ((int)candidates.size() != 1) {
cout << "! -1\n";
cout.flush();
return 0;
}
int d0 = candidates[0];
vector<int> dig(N);
dig[0] = d0;
for (int i = 1; i < N; i++) dig[i] = prod[i] / d0;
// Build the number from least significant digit to most significant digit.
long long X = 0;
long long pw = 1;
for (int i = 0; i < N; i++) {
X += pw * dig[i];
pw *= 10;
}
cout << "! " << X << '\n';
cout.flush();
return 0;
}