結果
問題 | No.1588 Connection |
ユーザー |
![]() |
提出日時 | 2021-07-09 00:03:30 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
QLE
(最初)
|
実行時間 | - |
コード長 | 2,377 bytes |
コンパイル時間 | 1,018 ms |
コンパイル使用メモリ | 99,900 KB |
実行使用メモリ | 25,716 KB |
平均クエリ数 | 561.34 |
最終ジャッジ日時 | 2024-07-17 12:46:08 |
合計ジャッジ時間 | 4,283 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 WA * 23 |
ソースコード
#include <iostream> #include <string> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <iterator> #include <cassert> #include <numeric> #include <functional> #include <ctime> #include <bitset> #pragma warning(disable:4996) //#define ATCODER #ifdef ATCODER #include <atcoder/all> #endif typedef long long ll; typedef unsigned long long ull; #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 //const long long MOD = 1000000007; const long long MOD = 998244353; using namespace std; #ifdef ATCODER using namespace atcoder; #endif int n, m; int cnt; vector<vector<int>> z; int ask(int i, int j) { if (i < 0 || i >= n || j < 0 || j >= n) { return 1; } if (z[i][j] >= 0) { return z[i][j]; } printf("%d %d\n", i + 1, j + 1); fflush(stdout); char str[10] = { 0 }; scanf("%s", str); if (str[0] == 'B') { z[i][j] = 1; return 1; } else if (str[0] == 'W') { z[i][j] = 0; return 0; } else { return -1; } } int dx[4] = {1,0,-1,0}; int dy[4] = {0,1,0,-1}; void solve() { scanf("%d%d", &n, &m); z.resize(n, vector<int>(n, -1)); z[0][0] = 0; z[n - 1][n-1] = 0; int i = 0, j = 0; int k = 0; // dir while (1) { int knext = -1; for (int p = 3; p <= 6; p++) { int k2 = (k + p) % 4; int i2 = i + dx[k2]; int j2 = j + dy[k2]; int ret = ask(i2, j2); if (ret == -1) { printf("error\n"); return; } else if (ret == 0) { k = k2; i = i2; j = j2; break; } } if (k < 0) { printf("error\n"); return; } if (i == 0 && j == 0) { printf("No\n"); return; } if (i == n - 1 && j == n - 1) { printf("Yes\n"); return; } } return; } int main() { #if 1 solve(); #else int T, t; scanf("%d", &T); for (t = 0; t < T; t++) { //printf("Case #%d: ", t + 1); solve(); } #endif return 0; }