結果
| 問題 |
No.3018 目隠し宝探し
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2025-01-28 17:46:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,394 bytes |
| コンパイル時間 | 670 ms |
| コンパイル使用メモリ | 56,624 KB |
| 実行使用メモリ | 26,228 KB |
| 平均クエリ数 | 2.59 |
| 最終ジャッジ日時 | 2025-01-28 17:46:50 |
| 合計ジャッジ時間 | 4,098 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int query(int, int)’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d", &d);
| ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:48:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
48 | scanf("%d%d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 3018.cc: No.3018 逶ョ髫縺怜ョ晄爾縺・- yukicoder
*/
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
/* typedef */
using pii = pair<int,int>;
using vpii = vector<pii>;
/* global variables */
/* subroutines */
int query(int y, int x) {
printf("? %d %d\n", y, x); fflush(stdout);
int d;
scanf("%d", &d);
return d;
}
void fin(int y, int x) { printf("! %d %d\n", y, x); fflush(stdout); }
vpii calcps(int h, int w, int y0, int x0, int d0) {
vpii ps;
for (int y = 1; y <= h; y++)
for (int x = 1; x <= w; x++) {
int dy = y - y0, dx = x - x0;
int d = dy * dy + dx * dx;
if (d == d0) ps.push_back({y, x});
}
return ps;
}
/* main */
int main() {
int h, w;
scanf("%d%d", &h, &w);
int ty = 0, tx = 0;
int d0 = query(1, 1);
if (d0 < 0) return 0;
auto ps0 = calcps(h, w, 1, 1, d0);
if (ps0.size() == 1)
ty = ps0[0].first, tx = ps0[0].second;
else {
int d1 = query(h, 1);
if (d1 < 0) return 0;
auto ps1 = calcps(h, w, h, 1, d1);
auto vit0 = ps0.begin(), vit1 = ps1.begin();
for (;;) {
if (*vit0 < *vit1) vit0++;
else if (*vit0 > *vit1) vit1++;
else {
ty = vit0->first, tx = vit1->second;
break;
}
}
}
fin(ty, tx);
//for (int i = 0; i < 1000000000; i++);
return 0;
}
tnakao0123