結果
問題 | No.323 yuki国 |
ユーザー | ki_ki33 |
提出日時 | 2015-12-16 17:34:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 474 ms / 5,000 ms |
コード長 | 3,652 bytes |
コンパイル時間 | 2,806 ms |
コンパイル使用メモリ | 90,660 KB |
実行使用メモリ | 54,536 KB |
最終ジャッジ日時 | 2024-06-28 12:24:01 |
合計ジャッジ時間 | 11,692 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 132 ms
40,916 KB |
testcase_01 | AC | 130 ms
41,136 KB |
testcase_02 | AC | 132 ms
41,396 KB |
testcase_03 | AC | 147 ms
41,680 KB |
testcase_04 | AC | 137 ms
41,140 KB |
testcase_05 | AC | 159 ms
40,936 KB |
testcase_06 | AC | 130 ms
41,204 KB |
testcase_07 | AC | 143 ms
41,064 KB |
testcase_08 | AC | 223 ms
50,180 KB |
testcase_09 | AC | 219 ms
50,112 KB |
testcase_10 | AC | 132 ms
41,228 KB |
testcase_11 | AC | 133 ms
41,200 KB |
testcase_12 | AC | 131 ms
41,156 KB |
testcase_13 | AC | 203 ms
48,280 KB |
testcase_14 | AC | 207 ms
47,772 KB |
testcase_15 | AC | 376 ms
52,136 KB |
testcase_16 | AC | 313 ms
51,208 KB |
testcase_17 | AC | 240 ms
49,568 KB |
testcase_18 | AC | 283 ms
46,640 KB |
testcase_19 | AC | 217 ms
46,292 KB |
testcase_20 | AC | 204 ms
49,260 KB |
testcase_21 | AC | 243 ms
49,460 KB |
testcase_22 | AC | 474 ms
54,536 KB |
testcase_23 | AC | 226 ms
49,496 KB |
testcase_24 | AC | 266 ms
50,444 KB |
testcase_25 | AC | 289 ms
50,912 KB |
testcase_26 | AC | 272 ms
50,668 KB |
testcase_27 | AC | 282 ms
50,580 KB |
testcase_28 | AC | 336 ms
52,944 KB |
testcase_29 | AC | 376 ms
53,336 KB |
testcase_30 | AC | 133 ms
41,644 KB |
testcase_31 | AC | 128 ms
41,172 KB |
testcase_32 | AC | 131 ms
41,248 KB |
testcase_33 | AC | 126 ms
40,144 KB |
testcase_34 | AC | 118 ms
41,404 KB |
testcase_35 | AC | 139 ms
41,296 KB |
testcase_36 | AC | 131 ms
41,468 KB |
testcase_37 | AC | 131 ms
41,180 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(); } }