結果
問題 | No.323 yuki国 |
ユーザー | ki_ki33 |
提出日時 | 2015-12-16 17:34:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 440 ms / 5,000 ms |
コード長 | 3,652 bytes |
コンパイル時間 | 2,713 ms |
コンパイル使用メモリ | 85,760 KB |
実行使用メモリ | 69,400 KB |
最終ジャッジ日時 | 2023-09-10 21:19:37 |
合計ジャッジ時間 | 11,537 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 125 ms
55,916 KB |
testcase_01 | AC | 125 ms
55,632 KB |
testcase_02 | AC | 127 ms
56,352 KB |
testcase_03 | AC | 145 ms
55,596 KB |
testcase_04 | AC | 128 ms
55,636 KB |
testcase_05 | AC | 141 ms
55,640 KB |
testcase_06 | AC | 125 ms
55,772 KB |
testcase_07 | AC | 138 ms
55,688 KB |
testcase_08 | AC | 232 ms
62,924 KB |
testcase_09 | AC | 231 ms
63,484 KB |
testcase_10 | AC | 127 ms
55,768 KB |
testcase_11 | AC | 125 ms
55,688 KB |
testcase_12 | AC | 126 ms
55,992 KB |
testcase_13 | AC | 195 ms
59,912 KB |
testcase_14 | AC | 196 ms
60,084 KB |
testcase_15 | AC | 388 ms
66,708 KB |
testcase_16 | AC | 317 ms
64,332 KB |
testcase_17 | AC | 250 ms
63,444 KB |
testcase_18 | AC | 285 ms
60,756 KB |
testcase_19 | AC | 230 ms
63,108 KB |
testcase_20 | AC | 208 ms
62,136 KB |
testcase_21 | AC | 239 ms
63,072 KB |
testcase_22 | AC | 440 ms
69,400 KB |
testcase_23 | AC | 241 ms
63,140 KB |
testcase_24 | AC | 274 ms
64,332 KB |
testcase_25 | AC | 265 ms
64,780 KB |
testcase_26 | AC | 270 ms
64,848 KB |
testcase_27 | AC | 283 ms
64,476 KB |
testcase_28 | AC | 325 ms
65,796 KB |
testcase_29 | AC | 365 ms
66,744 KB |
testcase_30 | AC | 127 ms
55,428 KB |
testcase_31 | AC | 127 ms
55,672 KB |
testcase_32 | AC | 127 ms
55,632 KB |
testcase_33 | AC | 127 ms
55,828 KB |
testcase_34 | AC | 130 ms
55,756 KB |
testcase_35 | AC | 127 ms
55,652 KB |
testcase_36 | AC | 128 ms
55,768 KB |
testcase_37 | AC | 126 ms
55,432 KB |
ソースコード
import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.io.BufferedInputStream; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; import java.util.*; import java.util.Map.Entry; import java.util.concurrent.ConcurrentSkipListSet; import javax.swing.ImageIcon; public class Main { static final long C = 1000000007; static final int CY = 1000000000; //long[] F; public void calc() { long fTime = System.currentTimeMillis(); StringBuilder sb = new StringBuilder(); BufferedInputStream bs = new BufferedInputStream(System.in); Scanner sc = new Scanner(bs); int h = sc.nextInt(); int w = sc.nextInt(); int f = sc.nextInt(); Point fp = new Point(sc.nextInt(), sc.nextInt()); g = sc.nextInt(); gp = new Point(sc.nextInt(), sc.nextInt()); map = new char[h][]; for (int i=0; i < h; i++) { map[i] = sc.next().toCharArray(); } memo = new boolean[h][w][1501]; boolean ans = false; memo[fp.x][fp.y][f] = true; HashSet<Point> ps = new HashSet<Point>(); ps.add(fp); do { HashSet<Point> rent = new HashSet<Point>(); for (Point p:ps) { rent.addAll(msd(p.x, p.y)); } ps = rent; }while(ps.size() > 0); ans = memo[gp.x][gp.y][g]; System.out.println(ans?"Yes":"No"); } //static int N = 1500; boolean[][][] memo ; char[][] map; int g; Point gp; HashSet<Point> msd(int x, int y) { HashSet<Point> ret = new HashSet<Point>(); if (memo[gp.x][gp.y][g]) { return ret; } int nx = x+1, ny = y; boolean isUp = false; boolean isDown = false; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } nx = x-1;ny = y; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } nx = x;ny = y+1; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } nx = x;ny = y-1; if (isIn(nx, ny)) { char nc = map[nx][ny]; if (nc == map[x][y]) { if (nc == '.' ) { isDown = true; }else { isUp = true; } } } if (isDown) { int max = 0; for (int i=1499;i >= 0; i--) { if (memo[x][y][i] ){ max = i; break; } } for (int i=max;i >= 0; i-=2) { memo[x][y][i]= true; } } if (isUp ) { int max = 1500; for (int i=0;i < 1500; i++) { if (memo[x][y][i] ){ max = i; break; } } for (int i=max;i < 1500; i+=2) { memo[x][y][i]= true; } } nx = x+1;ny = y; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } nx = x-1;ny = y; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } nx = x;ny = y+1; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } nx = x;ny = y-1; if (check(x, y, nx, ny)) { ret.add(new Point(nx,ny)); } return ret; } private boolean check(int x, int y, int nx, int ny) { int add; if (isIn(nx, ny)) { char nc = map[nx][ny]; add = nc == '.'?-1:1; boolean flag = false; for (int i=1; i < 1500; i++) { if (memo[x][y][i]) { if (!memo[nx][ny][i+add]) { memo[nx][ny][i+add] = true; flag = true; } } } return flag; } return false; } boolean isIn(int x, int y) { return !(x < 0 || y < 0 || map.length <= x || map[0].length <= y); } public static void main(String[] args) { Main main = new Main(); main.calc(); } }