結果

問題 No.1588 Connection
ユーザー merlinmerlin
提出日時 2021-07-09 00:13:39
言語 Java21
(openjdk 21)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 1,919 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 81,300 KB
実行使用メモリ 71,184 KB
平均クエリ数 485.91
最終ジャッジ日時 2023-09-24 11:52:19
合計ジャッジ時間 8,842 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
65,640 KB
testcase_01 WA -
testcase_02 AC 102 ms
68,888 KB
testcase_03 AC 105 ms
68,200 KB
testcase_04 AC 106 ms
68,612 KB
testcase_05 AC 102 ms
68,704 KB
testcase_06 AC 115 ms
68,360 KB
testcase_07 AC 113 ms
67,892 KB
testcase_08 AC 114 ms
68,512 KB
testcase_09 AC 110 ms
68,968 KB
testcase_10 AC 103 ms
68,144 KB
testcase_11 AC 104 ms
68,332 KB
testcase_12 AC 118 ms
68,584 KB
testcase_13 AC 132 ms
69,376 KB
testcase_14 AC 98 ms
68,288 KB
testcase_15 AC 113 ms
66,512 KB
testcase_16 AC 97 ms
68,344 KB
testcase_17 AC 99 ms
68,348 KB
testcase_18 AC 98 ms
68,768 KB
testcase_19 AC 107 ms
68,356 KB
testcase_20 AC 109 ms
68,044 KB
testcase_21 WA -
testcase_22 AC 302 ms
71,056 KB
testcase_23 AC 233 ms
69,732 KB
testcase_24 AC 186 ms
71,184 KB
testcase_25 AC 259 ms
70,412 KB
testcase_26 AC 252 ms
70,304 KB
testcase_27 AC 187 ms
68,452 KB
testcase_28 AC 162 ms
68,632 KB
testcase_29 AC 319 ms
70,820 KB
testcase_30 AC 309 ms
70,548 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;
        Stack<Pair> q=new Stack<>();
        q.add(new Pair(1,1));
        while(!q.isEmpty() && m>0)
        {
            Pair p=q.pop();
            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])
                {
                    vis[tx][ty]=true;
                    if(b[tx][ty]) q.add(new Pair(tx,ty));
                    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;
                            m--;
                        }
                        ask[tx][ty]=true;
                    }
                }
            }
            if(vis[n][n]) break;
        }

        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