結果

問題 No.1588 Connection
ユーザー HaaHaa
提出日時 2021-07-08 23:41:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 2,131 bytes
コンパイル時間 3,543 ms
コンパイル使用メモリ 175,896 KB
実行使用メモリ 24,324 KB
平均クエリ数 657.84
最終ジャッジ日時 2023-09-24 11:44:12
合計ジャッジ時間 5,434 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,448 KB
testcase_01 AC 24 ms
24,240 KB
testcase_02 AC 26 ms
23,976 KB
testcase_03 AC 25 ms
23,580 KB
testcase_04 AC 24 ms
23,292 KB
testcase_05 AC 25 ms
23,304 KB
testcase_06 AC 26 ms
24,216 KB
testcase_07 AC 25 ms
23,460 KB
testcase_08 WA -
testcase_09 AC 27 ms
23,544 KB
testcase_10 AC 28 ms
23,892 KB
testcase_11 AC 29 ms
23,532 KB
testcase_12 AC 55 ms
24,324 KB
testcase_13 AC 60 ms
23,604 KB
testcase_14 AC 32 ms
23,940 KB
testcase_15 AC 26 ms
23,580 KB
testcase_16 AC 26 ms
23,352 KB
testcase_17 AC 26 ms
24,264 KB
testcase_18 AC 25 ms
23,988 KB
testcase_19 AC 25 ms
23,424 KB
testcase_20 AC 27 ms
23,256 KB
testcase_21 AC 109 ms
23,724 KB
testcase_22 AC 108 ms
23,352 KB
testcase_23 AC 59 ms
23,544 KB
testcase_24 AC 41 ms
23,400 KB
testcase_25 AC 107 ms
23,532 KB
testcase_26 AC 110 ms
23,304 KB
testcase_27 AC 59 ms
23,568 KB
testcase_28 AC 43 ms
24,276 KB
testcase_29 AC 110 ms
23,712 KB
testcase_30 AC 111 ms
23,292 KB
testcase_31 AC 25 ms
23,772 KB
権限があれば一括ダウンロードができます

ソースコード

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,1});
    q.push({1,0});
    q.push({n-2,n-1});
    q.push({n-1,n-2});
    VVI f(n,VI(n,0));
    f[0][0]=1;
    f[n-1][n-1]=1;
    f[0][1]=1;
    f[1][0]=1;
    f[n-2][n-1]=1;
    f[n-1][n-2]=1;
    string s;
    while(!q.empty()){
        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<0||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;
        }
    }
    cout << "No" << endl;
    return 0;
}
0