結果
問題 | No.3018 目隠し宝探し |
ユーザー |
|
提出日時 | 2025-01-25 14:51:00 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 97 ms / 2,000 ms |
コード長 | 2,536 bytes |
コンパイル時間 | 3,384 ms |
コンパイル使用メモリ | 281,460 KB |
実行使用メモリ | 26,228 KB |
平均クエリ数 | 2.59 |
最終ジャッジ日時 | 2025-01-25 23:31:02 |
合計ジャッジ時間 | 6,284 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge11 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> typedef long long ll; typedef std::pair<long long, long long> P; typedef std::priority_queue<P, std::vector<P>, std::greater<P>> PQ; int main() { int h, w; std::cin >> h >> w; if (h == 1 && w == 1) { std::cout << "! 1 1" << std::endl; return 0; } std::cout << "? 1 1" << std::endl; ll d; std::cin >> d; std::vector<std::vector<bool>> grid(h + 1, std::vector<bool>(w + 1, false)); int count = 0; int tempi = 0, tempj = 0; for (int i = 1; i <= h; ++i) { for (int j = 1; j <= w; ++j) { if ((i - 1) * (i - 1) + (j - 1) * (j - 1) == d) { count++; tempi = i; tempj = j; grid[i][j] = true; } } } if (count == 1) { std::cout << "! " << tempi << " " << tempj << std::endl; return 0; } int tw = 2; std::cout << "? " << 1 << " " << tw << std::endl; std::cin >> d; count = 0; tempi = 0, tempj = 0; for (int i = 1; i <= h; ++i) { for (int j = 1; j <= w; ++j) { if (grid[i][j] && (1 - i) * (1 - i) + (tw - j) * (tw - j) == d) { count++; tempi = i; tempj = j; } else { grid[i][j] = false; } } } if (count == 1) { std::cout << "! " << tempi << " " << tempj << std::endl; return 0; } std::cout << "? " << 1 << " " << w << std::endl; std::cin >> d; count = 0; tempi = 0, tempj = 0; for (int i = 1; i <= h; ++i) { for (int j = 1; j <= w; ++j) { if (grid[i][j] && (i - 1) * (i - 1) + (w - j) * (w - j) == d) { count++; tempi = i; tempj = j; } else { grid[i][j] = false; } } } if (count == 1) { std::cout << "! " << tempi << " " << tempj << std::endl; return 0; } std::cout << "? " << h << " " << 1 << std::endl; std::cin >> d; count = 0; tempi = 0, tempj = 0; for (int i = 1; i <= h; ++i) { for (int j = 1; j <= w; ++j) { if (grid[i][j] && (h - i) * (h - i) + (1 - j) * (1 - j) == d) { count++; tempi = i; tempj = j; } else { grid[i][j] = false; } } } if (count == 1) { std::cout << "! " << tempi << " " << tempj << std::endl; return 0; } }