結果

問題 No.1588 Connection
ユーザー chocoruskchocorusk
提出日時 2021-07-08 23:08:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 3,610 ms
コンパイル使用メモリ 192,404 KB
実行使用メモリ 24,480 KB
平均クエリ数 562.59
最終ジャッジ日時 2023-09-24 11:32:37
合計ジャッジ時間 6,958 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,324 KB
testcase_01 AC 27 ms
23,664 KB
testcase_02 AC 26 ms
23,532 KB
testcase_03 AC 25 ms
23,508 KB
testcase_04 AC 26 ms
24,324 KB
testcase_05 AC 27 ms
23,400 KB
testcase_06 AC 28 ms
23,796 KB
testcase_07 AC 26 ms
24,036 KB
testcase_08 AC 28 ms
24,036 KB
testcase_09 AC 29 ms
24,312 KB
testcase_10 AC 29 ms
24,024 KB
testcase_11 AC 29 ms
23,652 KB
testcase_12 AC 58 ms
24,036 KB
testcase_13 AC 64 ms
23,364 KB
testcase_14 AC 27 ms
23,532 KB
testcase_15 AC 28 ms
24,048 KB
testcase_16 AC 28 ms
24,480 KB
testcase_17 AC 27 ms
24,048 KB
testcase_18 AC 27 ms
23,640 KB
testcase_19 AC 28 ms
24,012 KB
testcase_20 AC 29 ms
24,024 KB
testcase_21 AC 111 ms
23,628 KB
testcase_22 AC 110 ms
23,640 KB
testcase_23 AC 61 ms
23,376 KB
testcase_24 AC 44 ms
23,784 KB
testcase_25 AC 70 ms
24,324 KB
testcase_26 AC 69 ms
23,628 KB
testcase_27 AC 44 ms
23,388 KB
testcase_28 AC 39 ms
24,048 KB
testcase_29 AC 110 ms
23,364 KB
testcase_30 AC 108 ms
23,784 KB
testcase_31 AC 26 ms
24,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
int n, m;
int d[505][505];
int c[505][505];
int main()
{
    cin>>n>>m;
    const int INF=1e9;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            d[i][j]=INF;
        }
    }
    d[0][0]=0;
    c[0][0]=c[n-1][n-1]=1;
    queue<P> que;
    que.push({0, 0});
    int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};
    while(!que.empty()){
        auto p=que.front(); que.pop();
        int x=p.first, y=p.second;
        for(int k=0; k<4; k++){
            int x1=x+dx[k], y1=y+dy[k];
            if(x1<0 || x1>=n || y1<0 || y1>=n) continue;
            if(c[x1][y1]==0){
                cout<<x1+1<<" "<<y1+1<<endl;
                string t; cin>>t;
                if(t=="Black") c[x1][y1]=1;
                else c[x1][y1]=-1;
            }
            if(c[x1][y1]==1){
                if(d[x1][y1]>d[x][y]+1){
                    d[x1][y1]=d[x][y]+1;
                    que.push({x1, y1});
                }
            }
        }
    }
    if(d[n-1][n-1]<INF) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}
0