結果
問題 | No.1588 Connection |
ユーザー | merlin |
提出日時 | 2021-07-09 00:01:26 |
言語 | Java21 (openjdk 21) |
結果 |
WA
(最新)
QLE
(最初)
|
実行時間 | - |
コード長 | 2,994 bytes |
コンパイル時間 | 2,190 ms |
コンパイル使用メモリ | 81,496 KB |
実行使用メモリ | 87,312 KB |
平均クエリ数 | 425.47 |
最終ジャッジ日時 | 2023-09-24 11:50:53 |
合計ジャッジ時間 | 9,741 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 102 ms
68,356 KB |
testcase_01 | WA | - |
testcase_02 | AC | 100 ms
69,052 KB |
testcase_03 | AC | 99 ms
68,648 KB |
testcase_04 | AC | 102 ms
68,620 KB |
testcase_05 | AC | 97 ms
68,172 KB |
testcase_06 | AC | 103 ms
68,376 KB |
testcase_07 | AC | 96 ms
68,912 KB |
testcase_08 | AC | 104 ms
69,196 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 110 ms
68,476 KB |
testcase_15 | AC | 115 ms
68,420 KB |
testcase_16 | AC | 105 ms
68,660 KB |
testcase_17 | AC | 107 ms
69,268 KB |
testcase_18 | AC | 108 ms
69,336 KB |
testcase_19 | AC | 123 ms
72,560 KB |
testcase_20 | AC | 222 ms
79,616 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 414 ms
84,424 KB |
testcase_26 | AC | 426 ms
84,436 KB |
testcase_27 | AC | 229 ms
72,468 KB |
testcase_28 | AC | 166 ms
69,300 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
ソースコード
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; 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; int di[][]={{-1,0},{0,1},{1,0},{0,-1}}; Queue<Pair> q=new LinkedList<>(); q.add(new Pair(1,1)); while(!q.isEmpty()) { 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] && b[tx][ty]) { q.add(new Pair(tx,ty)); vis[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; } } }