結果

問題 No.1588 Connection
ユーザー merlinmerlin
提出日時 2021-07-08 23:23:04
言語 Java21
(openjdk 21)
結果
WA  
(最新)
QLE  
(最初)
実行時間 -
コード長 2,756 bytes
コンパイル時間 2,681 ms
コンパイル使用メモリ 78,024 KB
実行使用メモリ 82,664 KB
平均クエリ数 425.47
最終ジャッジ日時 2023-09-24 11:38:16
合計ジャッジ時間 9,542 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
69,224 KB
testcase_01 AC 97 ms
68,144 KB
testcase_02 AC 96 ms
68,828 KB
testcase_03 AC 98 ms
68,632 KB
testcase_04 AC 98 ms
68,616 KB
testcase_05 AC 95 ms
66,940 KB
testcase_06 AC 111 ms
68,352 KB
testcase_07 AC 101 ms
68,444 KB
testcase_08 AC 106 ms
68,332 KB
testcase_09 AC 115 ms
68,412 KB
testcase_10 AC 113 ms
68,768 KB
testcase_11 AC 114 ms
68,780 KB
testcase_12 AC 225 ms
68,920 KB
testcase_13 AC 212 ms
70,288 KB
testcase_14 AC 110 ms
68,904 KB
testcase_15 AC 118 ms
68,364 KB
testcase_16 AC 100 ms
68,720 KB
testcase_17 AC 103 ms
69,216 KB
testcase_18 AC 108 ms
69,696 KB
testcase_19 AC 116 ms
72,304 KB
testcase_20 AC 227 ms
79,580 KB
testcase_21 AC 365 ms
80,892 KB
testcase_22 AC 372 ms
80,980 KB
testcase_23 AC 230 ms
73,676 KB
testcase_24 AC 165 ms
70,092 KB
testcase_25 AC 427 ms
82,236 KB
testcase_26 AC 458 ms
82,664 KB
testcase_27 AC 241 ms
72,976 KB
testcase_28 AC 156 ms
69,408 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 99 ms
68,572 KB
権限があれば一括ダウンロードができます

ソースコード

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]);
        boolean b[][]=new boolean[n+1][n+1];
        b[1][1]=b[n][n]=true;
        m-=2;
        ArrayList<Pair> g[]=new ArrayList[2*n+1];
        int i,j;
        for(i=0;i<=2*n;i++) g[i]=new ArrayList<>();
        for(i=1;i<=n;i++)
        for(j=1;j<=n;j++) g[i+j].add(new Pair(i,j));

        int l=2,r=2*n; boolean vis[][]=new boolean[n+1][n+1];
        while(l<=r)
        {
            Queue<Pair> q=new LinkedList<>();
            for(Pair x:g[l])
            {
                if(b[x.x][x.y] && x.x+1<=n && !vis[x.x+1][x.y])
                {
                    vis[x.x+1][x.y]=true;
                    q.add(new Pair(x.x+1,x.y));
                }
                if(b[x.x][x.y] && x.y+1<=n && !vis[x.x][x.y+1])
                {
                    vis[x.x][x.y+1]=true;
                    q.add(new Pair(x.x,x.y+1));
                }
            }

            for(Pair x:g[r])
            {
                if(b[x.x][x.y] && x.x-1>0 && !vis[x.x-1][x.y])
                {
                    vis[x.x-1][x.y]=true;
                    q.add(new Pair(x.x-1,x.y));
                }
                if(b[x.x][x.y] && x.y-1>0 && !vis[x.x][x.y-1])
                {
                    vis[x.x][x.y-1]=true;
                    q.add(new Pair(x.x,x.y-1));
                }
            }

            while(!q.isEmpty())
            {
                Pair p=q.poll();
                System.out.print(p.x+" "+p.y+"\n");
                System.out.flush();
                String ver=bu.readLine();
                if(ver.charAt(0)=='-') return;
                if(ver.charAt(0)=='B')
                {
                    m--;
                    b[p.x][p.y]=true;
                }
                if(m==0) break;
            }

            if(m==0) break;
            l++; r--;
        }

        for(i=1;i<=n;i++) Arrays.fill(vis[i],false);
        vis[1][1]=true;
        for(i=2;i<=n;i++)
        {
            vis[1][i]=vis[1][i-1]&b[1][i];
            vis[i][1]=vis[i-1][1]&b[i][1];
        }

        for(i=2;i<=n;i++)
        for(j=2;j<=n;j++)
        vis[i][j]=b[i][j]&(vis[i-1][j]|vis[i][j-1]);

        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