結果

問題 No.1588 Connection
ユーザー HaaHaa
提出日時 2021-07-08 23:29:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,986 bytes
コンパイル時間 1,749 ms
コンパイル使用メモリ 176,212 KB
実行使用メモリ 24,468 KB
平均クエリ数 28.94
最終ジャッジ日時 2023-09-24 11:40:36
合計ジャッジ時間 9,848 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

struct Unionfind{
   vector<int> par, siz;
   Unionfind(int N):par(N), siz(N,1){
       for (int i=0;i<N;i++) par[i]=i;
   }
   int root(int x){
       while(par[x]!=x) x=par[x]=par[par[x]];
       return x;
   }
   void unite(int x, int y){
       x=root(x); y=root(y);
       if (x==y) return;
       if (siz[x]<siz[y]) swap(x,y);
       siz[x]+=siz[y];
       par[y]=x;
   }
   bool same(int x, int y){
       return root(x)==root(y);
   }
   int size(int x){
       return siz[root(x)];
   }
};

int main(){
    int n, m; cin >> n >> m; m-=2;
    Unionfind uf(n*n);
    queue<P> q;
    q.push({0,0});
    q.push({n-1,n-1});
    VVI f(n,VI(n,0));
    f[0][0]=1;
    f[n-1][n-1]=1;
    string s;
    while(1){
        int x=q.front().first, y=q.front().second;
        q.pop();
        cout << x+1 << " " << y+1 << endl;
        cin >> s;
        if(s=="Black"){
            REP(k,4){
                int tx=x+dx[k];
                int ty=y+dy[k];
                if(tx<0||tx>=n||ty<n||ty>=n)
                    continue;
                if(f[tx][ty]){
                    uf.unite(x*n+y,tx*n+ty);
                    continue;
                }
                f[tx][ty]=1;
                q.push({tx,ty});
            }
            m--;
        }
        else if(s=="-1")
            assert(0);
        if(uf.same(0,n*n-1)){
            cout << "Yes" << endl;
            break;
        }
        else if(m==0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}
0