結果

問題 No.1588 Connection
ユーザー tarattata1tarattata1
提出日時 2021-07-09 00:03:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 2,377 bytes
コンパイル時間 836 ms
コンパイル使用メモリ 98,344 KB
実行使用メモリ 24,432 KB
平均クエリ数 561.34
最終ジャッジ日時 2023-09-24 11:51:23
合計ジャッジ時間 3,988 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 23 ms
23,460 KB
testcase_06 AC 23 ms
23,340 KB
testcase_07 AC 24 ms
23,664 KB
testcase_08 AC 24 ms
24,240 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 24 ms
23,304 KB
testcase_15 AC 24 ms
23,280 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 37 ms
24,252 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 43 ms
23,304 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 24 ms
23,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0