結果

問題 No.1588 Connection
ユーザー merlinmerlin
提出日時 2021-07-09 00:09:31
言語 Java21
(openjdk 21)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 2,010 bytes
コンパイル時間 4,290 ms
コンパイル使用メモリ 80,156 KB
実行使用メモリ 73,236 KB
平均クエリ数 562.31
最終ジャッジ日時 2023-09-24 11:52:02
合計ジャッジ時間 11,517 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
66,016 KB
testcase_01 WA -
testcase_02 AC 105 ms
68,260 KB
testcase_03 AC 105 ms
69,176 KB
testcase_04 AC 106 ms
68,304 KB
testcase_05 AC 107 ms
68,944 KB
testcase_06 AC 110 ms
68,640 KB
testcase_07 AC 116 ms
68,240 KB
testcase_08 AC 124 ms
68,828 KB
testcase_09 AC 126 ms
69,028 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 249 ms
70,668 KB
testcase_14 AC 109 ms
68,660 KB
testcase_15 AC 122 ms
69,116 KB
testcase_16 AC 108 ms
68,968 KB
testcase_17 AC 108 ms
69,200 KB
testcase_18 AC 108 ms
68,880 KB
testcase_19 AC 108 ms
68,572 KB
testcase_20 AC 112 ms
68,312 KB
testcase_21 WA -
testcase_22 AC 320 ms
72,780 KB
testcase_23 AC 236 ms
69,764 KB
testcase_24 AC 199 ms
69,412 KB
testcase_25 AC 265 ms
69,464 KB
testcase_26 AC 261 ms
70,232 KB
testcase_27 AC 195 ms
68,904 KB
testcase_28 AC 163 ms
69,064 KB
testcase_29 AC 338 ms
70,996 KB
testcase_30 AC 338 ms
70,640 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int n=Integer.parseInt(s[0]),m=Integer.parseInt(s[1])-2;
        boolean b[][]=new boolean[n+1][n+1];
        b[1][1]=b[n][n]=true;

        int di[][]={{-1,0},{0,1},{1,0},{0,-1}};
        boolean vis[][]=new boolean[n+1][n+1],ask[][]=new boolean[n+1][n+1];
        vis[1][1]=true;
        Queue<Pair> q=new LinkedList<>();
        q.add(new Pair(1,1));
        while(!q.isEmpty() && m>0)
        {
            Pair p=q.poll();
            for(int d[]:di)
            {
                int tx=p.x+d[0],ty=p.y+d[1];
                if(tx>0 && tx<=n && ty>0 && ty<=n && !vis[tx][ty])
                {
                    if(b[tx][ty])
                    {
                        q.add(new Pair(tx,ty));
                        vis[tx][ty]=true;
                    }
                    else if(!ask[tx][ty] && m>0)
                    {
                        System.out.print(tx+" "+ty+"\n");
                        System.out.flush();
                        String ver=bu.readLine();
                        if(ver.charAt(0)=='-') return;
                        if(ver.charAt(0)=='B')
                        {
                            q.add(new Pair(tx,ty));
                            b[tx][ty]=true;
                            vis[tx][ty]=true;
                            m--;
                        }
                        ask[tx][ty]=true;
                    }
                }
            }
        }

        if(vis[n][n]) sb.append("Yes\n");
        else sb.append("No\n");
        System.out.print(sb);
        System.out.flush();
        return;
    }

    static class Pair
    {
        int x,y;
        Pair(int a,int b)
        {
            x=a;
            y=b;
        }
    }
}
0