結果

問題 No.3161 Find Presents
ユーザー 橋本ヒデヒコ
提出日時 2025-07-10 12:15:50
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 235 ms / 4,000 ms
コード長 2,252 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 146,776 KB
実行使用メモリ 26,072 KB
平均クエリ数 3402.09
最終ジャッジ日時 2025-07-10 12:16:06
合計ジャッジ時間 16,731 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 80
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iterator>


using namespace std;

using i64 = int64_t;
// using u64 = uint64_t;

template<class T>
using VV = vector<vector<T>>;

#define REP(i, n) for(i64 i = 0; i < i64(n); i++)
#define REP1(i, n) for(i64 i = 1; i <= i64(n); i++)

i64 INF = 100100100100100L;

i64 direct[8][2] = {
  {1, 0}, {0, -1}, {-1, 0}, {0, 1},
  {1, -1}, {-1, -1}, {-1, 1}, {1, 1}
};


template<class T, class S>
ostream &operator<<(ostream &os, pair<T, S> p);


template<class T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
  for(i64 i = 0; i < i64(v.size()); i++) {
    if (i > 0) os << ' ';
    os << v[i];
  }

  return os;
}

template<class T>
ostream &operator<<(ostream &os, const set<T> &st)
{
  bool first = true;
  for(const T &it: st)
  if (first) {
      first = false;
      os << it;
  } else{
    os << ' ' << it;
  }

  return os;
}

template<class T, class S>
ostream &operator<<(ostream &os, map<T, S> &mp)
{
  bool first = true;
  for(const auto &[f, l]: mp)
  if (first) {
      first = false;
      os << '{' << f << "-> " << l << '}';
  } else{
    os << ", {" << f << "-> " << l << '}';
  }

  return os;
}


template<class T, class S>
ostream &operator<<(ostream &os, pair<T, S> p)
{
  os << '{' << p.first << ", " << p.second << '}';

  return os;
}

vector<pair<i64, i64>> ans;


void X_dfs(i64 y, i64 xl, i64 xr)
{
  cout << "? " << xl << ' ' << (xr - 1) << ' ' << y << ' ' << y << endl;
  i64 t;
  cin >> t;

  if (t == 0)
    return;

  if (xr - xl == 1) {
    ans.push_back({xl, y});
  } else {
    i64 mid = (xl + xr) / 2;
    X_dfs(y, xl, mid);
    X_dfs(y, mid, xr);
  }
}


void Y_dfs(i64 yl, i64 yr)
{
  cout << "? 0 1000000 " << yl << ' ' << (yr - 1) << endl;
  i64 t;
  cin >> t;

  if (t == 0)
    return;

  if (yr - yl == 1) {
    X_dfs(yl, 0, 500'001);
    X_dfs(yl, 500'001, 1'000'001);
  } else {
    i64 mid = (yl + yr) / 2;
    Y_dfs(yl, mid);
    Y_dfs(mid, yr);
  }
}


int main()
{
  Y_dfs(0, 500'001);
  Y_dfs(500'001, 1'000'001);
  
  cout << "! " << ans.size() << endl;
  for(auto [X, Y]: ans)
    cout << X << ' ' << Y << endl;
  
  return 0;
}
0