結果

問題 No.3018 目隠し宝探し
ユーザー t98slidert98slider
提出日時 2025-01-25 13:36:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,680 bytes
コンパイル時間 2,164 ms
コンパイル使用メモリ 198,496 KB
実行使用メモリ 25,856 KB
平均クエリ数 2.59
最終ジャッジ日時 2025-01-25 22:51:46
合計ジャッジ時間 5,502 ms
ジャッジサーバーID
(参考情報)
judge8 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int h, w, d;
cin >> h >> w;
if(h == 1 && w == 1){
cout << "! 1 1" << endl;
return 0;
}
cout << "? 1 1" << endl;
cin >> d;
vector<pair<int,int>> cand, cand2;
for(int y = 1; y <= h; y++){
for(int x = 1; x <= w; x++){
if((y - 1) * (y - 1) + (x - 1) * (x - 1) == d){
cand.emplace_back(y, x);
}
}
}
if(cand.size() == 1){
auto [y, x] = cand[0];
cout << "! " << y << ' ' << x << endl;
return 0;
}
if(h != 1){
cout << "? " << h << ' ' << 1 << endl;
cin >> d;
for(auto [y, x] : cand){
if((y - h) * (y - h) + (x - 1) * (x - 1) == d){
cand2.emplace_back(y, x);
}
}
}else{
cout << "? " << 1 << ' ' << w << endl;
cin >> d;
for(auto [y, x] : cand){
if((y - 1) * (y - 1) + (x - w) * (x - w) == d){
cand2.emplace_back(y, x);
}
}
}
swap(cand, cand2);
if(cand.size() == 1){
auto [y, x] = cand[0];
cout << "! " << y << ' ' << x << endl;
return 0;
}
cand2.clear();
cout << "? " << 1 << ' ' << w << endl;
cin >> d;
for(auto [y, x] : cand){
if((y - 1) * (y - 1) + (x - w) * (x - w) == d){
cand2.emplace_back(y, x);
}
}
swap(cand, cand2);
if(cand.size() == 1){
auto [y, x] = cand[0];
cout << "! " << y << ' ' << x << endl;
return 0;
}
assert(false);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0