結果
| 問題 | No.3501 Digit Products 2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-17 23:54:34 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 2,320 bytes |
| 記録 | |
| コンパイル時間 | 4,182 ms |
| コンパイル使用メモリ | 336,552 KB |
| 実行使用メモリ | 30,320 KB |
| 平均クエリ数 | 10.89 |
| 最終ジャッジ日時 | 2026-04-17 23:55:04 |
| 合計ジャッジ時間 | 8,111 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 72 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v) is >> in;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++)
os << v[i] << (i + 1 != (int)v.size() ? " " : "");
return os;
}
#define OVERLOAD_REP(_1, _2, _3, name, ...) name
#define REP1(i, n) for (auto i = std::decay_t<decltype(n)>{}; (i) != (n); ++(i))
#define REP2(i, l, r) for (auto i = (l); (i) != (r); ++(i))
#define rep(...) OVERLOAD_REP(__VA_ARGS__, REP2, REP1)(__VA_ARGS__)
#define sum(l) accumulate(l.begin(), l.end(), 0)
#define all(...) std::begin(__VA_ARGS__), std::end(__VA_ARGS__)
#define rall(...) std::rbegin(__VA_ARGS__), std::rend(__VA_ARGS__)
using ull = unsigned long long;
using ll = long long;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using pii = pair<int, int>;
using vpii = vector<pii>;
int main() {
cin.tie(0); ios::sync_with_stdio(false);
int N;
cin >> N;
int nm1 = N - 1;
vi p(N - 1);
rep(i, N - 1) {
cout << "? " << i << " " << nm1 << '\n';
cout.flush();
cin >> p[i];
if (p[i] == -1) return 0;
}
vi nz;
rep(i, N - 1) if (p[i]) nz.push_back(i);
vi d(N, 0);
if (nz.size() == 0) {
cout << "! -1\n";
cout.flush();
return 0;
}
if (nz.size() == 1) {
int i = nz[0];
int prod = p[i];
pii cand = {-1, -1};
rep(a, 1, 10) rep(b, 1, 10) {
if (a * b != prod) continue;
if (cand.first != -1) {
cout << "! -1\n";
cout.flush();
return 0;
}
cand = {a, b};
}
if (cand.first == -1) {
cout << "! -1\n";
cout.flush();
return 0;
}
d[nm1] = cand.first;
d[i] = cand.second;
} else {
int a = nz[0], b = nz[1];
cout << "? " << a << " " << b << '\n';
cout.flush();
int q;
cin >> q;
if (q == -1) return 0;
int keta = sqrt(1LL * p[a] * p[b] / q);
d[nm1] = keta;
rep(i, N - 1) if (p[i]) d[i] = p[i] / keta;
}
string ans;
for (int i = N - 1; i >= 0; --i) ans += char('0' + d[i]);
cout << "! " << ans << '\n';
cout.flush();
return 0;
}