結果
| 問題 | No.3501 Digit Products 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-18 00:41:21 |
| 言語 | C++23(gnu拡張) (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,679 bytes |
| 記録 | |
| コンパイル時間 | 4,545 ms |
| コンパイル使用メモリ | 376,232 KB |
| 実行使用メモリ | 30,064 KB |
| 平均クエリ数 | 10.89 |
| 最終ジャッジ日時 | 2026-04-18 00:42:12 |
| 合計ジャッジ時間 | 12,286 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 68 WA * 4 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
using mint = atcoder::modint998244353;
// isqrt
long long isqrt(long long n) {
if (n <= 0) return 0;
long long x = sqrt(n);
if (x * x > n) x--;
return x;
}
void solve() {
int n;
cin >> n;
int qn = 0;
auto query = [&](int a, int b) {
if (qn == n) {
cout << "! -1" << endl;
exit(0);
}
qn++;
if (a > b) swap(a, b);
cout << "? " << a << " " << b << endl;
int p;
cin >> p;
assert(p != -1);
return p;
};
vector<ll> v(n, -1);
rep(i, 0, n - 1) v[i] = query(i, n - 1);
vector<int> t;
rep(i, 0, n - 1) if (v[i] > 0) t.push_back(i);
if (t.size() < 2) {
if (t.size() == 1) {
int x = v[t[0]];
for (int y : {1, 5, 6, 7, 8, 9})
if (x == y * y) {
v[n - 1] = y;
v[t[0]] = y;
cout << "! ";
rep(i, 0, n) cout << v[n - 1 - i];
cout << "\n";
return;
}
}
cout << "! -1\n";
return;
}
ll p = query(t[0], t[1]);
ll tmp = p * v[t[0]] * v[t[1]];
ll sq = isqrt(tmp);
assert(sq * sq == tmp && sq % p == 0);
v[n - 1] = sq / p;
assert(v[n - 1] < 10);
rep(i, 0, n - 1) {
assert(v[i] % v[n - 1] == 0);
v[i] /= v[n - 1];
assert(v[i] < 10);
}
cout << "! ";
rep(i, 0, n) cout << v[n - 1 - i];
cout << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int t = 1;
// cin >> t;
while (t--) solve();
}