結果

問題 No.1588 Connection
ユーザー chocorusk
提出日時 2021-07-08 23:08:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,643 bytes
コンパイル時間 3,663 ms
コンパイル使用メモリ 185,188 KB
最終ジャッジ日時 2025-01-22 19:13:39
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

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