結果

問題 No.3018 目隠し宝探し
ユーザー bolero
提出日時 2025-01-25 14:17:23
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 2,284 bytes
コンパイル時間 6,811 ms
コンパイル使用メモリ 332,448 KB
実行使用メモリ 75,632 KB
平均クエリ数 2.59
最終ジャッジ日時 2025-01-25 23:14:40
合計ジャッジ時間 12,500 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>

// 可変引数repマクロ https://trap.jp/post/1224/
#define rep1(a) for (long long i = 0; i < (long long)a; i++)
#define rep2(i, a) for (long long i = 0; i < (long long)a; i++)
#define rep3(i, a, b) for (long long i = (long long)a; i <= (long long)b; i++)
#define rep4(i, a, b, c) for (long long i = (long long)a; i <= (long long)b; i += (long long)c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define printYesNo(is_ok) puts(is_ok ? "Possible" : "Impossible")
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(RALL(v))
#define REVERSE(v) reverse(ALL(v))

template <class T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using pq_des = priority_queue<T>;

template <typename T>
void printlnVector(T v)
{
  for (auto n : v)
  {
    cout << n << endl;
  }
}

template <typename T>
void printVector(T v)
{
  for (auto n : v)
  {
    cout << n << " ";
  }
  cout << endl;
}

int main()
{
  long long H, W;
  cin >> H >> W;

  if (H == 1 && W == 1)
  {
    cout << "! " << 1 << " " << 1 << endl;
    flush(cout);
    return 0;
  }

  set<pair<int, int>> rest_pos;
  rep(h, H) rep(w, W)
  {
    rest_pos.insert({h, w});
  }

  random_device rd;
  mt19937 gen(rd());

  while (true)
  {
    /*
    uniform_int_distribution<int> distribution(0, rest_pos.size() - 1);
    auto [h, w] = vector<pair<int, int>>(rest_pos.begin(), rest_pos.end())[distribution(gen)];
    */
    auto [h, w] = *rest_pos.begin();
    cout << "? " << h + 1 << " " << w + 1 << endl;
    flush(cout);
    long long d;
    cin >> d;

    if (d == -1)
    {
      break;
    }

    vector<pair<int, int>> erase_pos;
    for (auto [hh, ww] : rest_pos)
    {
      long long dist = (hh - h) * (hh - h) + (ww - w) * (ww - w);
      if (dist != d)
      {
        erase_pos.push_back({hh, ww});
      }
    }

    for (auto p : erase_pos)
    {
      rest_pos.erase(p);
    }

    if (rest_pos.size() == 1)
    {
      auto ans = *rest_pos.begin();
      cout << "! " << ans.first + 1 << " " << ans.second + 1 << endl;
      flush(cout);
      break;
    }
  }

  return 0;
}
0