結果

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

ソースコード

diff #
raw source code

#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);

  if (nz.size() < 2) {
    cout << "! -1\n";
    cout.flush();
    return 0;
  }

  int a = nz[0], b = nz[1];
  cout << "? " << nz[0] << " " << nz[1] << '\n';
  cout.flush();

  int q;
  cin >> q;
  if (q == -1) return 0;

  int keta = sqrt(1LL * p[a] * p[b] / q);
  vi d(N);
  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;
}
0