結果
問題 | No.3018 目隠し宝探し |
ユーザー |
|
提出日時 | 2025-02-11 22:05:54 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 1,762 bytes |
コンパイル時間 | 978 ms |
コンパイル使用メモリ | 79,304 KB |
実行使用メモリ | 25,984 KB |
平均クエリ数 | 2.68 |
最終ジャッジ日時 | 2025-02-11 22:06:03 |
合計ジャッジ時間 | 3,681 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 21 |
ソースコード
#include <iostream> #include <cstdint> using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int32_t H, W, d[2]; cin >> H >> W; if (H == 1) { if (W == 1) cout << "! 1 1" << endl; else { cout << "? 1 1" << endl; cin >> d[0]; if (d[0] == -1) return 0; int32_t l = 0, r = W; while (l + 1 < r) { const auto c = (l + r) >> 1; if (c * c <= d[0]) l = c; else r = c; } cout << "! 1 " << 1 + l << endl; } } else { if (W == 1) { cout << "? 1 1" << endl; cin >> d[0]; if (d[0] == -1) return 0; int32_t l = 0, r = H; while (l + 1 < r) { const auto c = (l + r) >> 1; if (c * c <= d[0]) l = c; else r = c; } cout << "! " << 1 + l << " 1" << endl; } else { cout << "? 1 1" << endl; cin >> d[0]; if (d[0] == -1) return 0; cout << "? 1 " << W << endl; cin >> d[1]; if (d[1] == -1) return 0; int32_t l = 0, r = W; while (1) { const auto c = (l + r) >> 1; if (c * c > d[0]) r = c; else if ((W - 1 - c) * (W - 1 - c) > d[1]) l = c; else { int32_t _l = 0, _r = H; while (_l + 1 < _r) { const auto _c = (_l + _r) >> 1; if (c * c + _c * _c <= d[0]) { if ((W - 1 - c) * (W - 1 - c) + _c * _c <= d[1]) _l = _c; else { l = c; break; } } else { if ((W - 1 - c) * (W - 1 - c) + _c * _c <= d[1]) { r = c; break; } else _r = _c; } } if (c * c + _l * _l == d[0] && (W - 1 - c) * (W - 1 - c) + _l * _l == d[1]) { cout << "! " << 1 + _l << ' ' << 1 + c << endl; break; } } } } } return 0; }