Submission #1305951
Source Code Expand
import java.io.*; import java.util.*; public class Main { private static boolean debug = false; private static boolean elapsed = false; private void solve(Scanner sc, PrintWriter out) { int H = sc.nextInt(); int W = sc.nextInt(); sc.nextLine(); char[][] A = new char[H][W]; for (int i = 0; i < H; ++i) { String s = sc.nextLine(); for (int j = 0; j < W; ++j) { A[i][j] = s.charAt(j); } } int cx = 0; int cy = 0; if (A[cy][cx] != '#') { out.println("Impossible"); return; } while (cx + 1 < W || cy + 1 < H) { if (cy + 1 < H && A[cy + 1][cx] == '#' && cx + 1 < W && A[cy][cx + 1] == '#') { out.println("Impossible"); return; } else if (cy > 0 && A[cy - 1][cx] == '#' || cx > 0 && A[cy][cx - 1] == '#') { out.println("Impossible"); return; } else if (cy + 1 < H && A[cy + 1][cx] == '#') { A[cy][cx] = '$'; ++cy; } else if (cx + 1 < W && A[cy][cx + 1] == '#') { A[cy][cx] = '$'; ++cx; } else { out.println("Impossible"); return; } } A[cy][cx] = '$'; if (debug) { for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { System.err.print(A[i][j]); } System.err.println(); } } for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (A[i][j] == '#') { out.println("Impossible"); return; } } } out.println("Possible"); } /* * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9 * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18 */ public static void main(String[] args) { long S = System.currentTimeMillis(); Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); new Main().solve(sc, out); out.flush(); long G = System.currentTimeMillis(); if (elapsed) { System.err.println((G - S) + "ms"); } } }
Submission Info
Submission Time | |
---|---|
Task | A - Shik and Stone |
User | unirita135 |
Language | Java8 (OpenJDK 1.8.0) |
Score | 200 |
Code Size | 2512 Byte |
Status | AC |
Exec Time | 100 ms |
Memory | 23764 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, example0.txt, example1.txt, example2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 91 ms | 19924 KB |
001.txt | AC | 91 ms | 19796 KB |
002.txt | AC | 93 ms | 21460 KB |
003.txt | AC | 93 ms | 21332 KB |
004.txt | AC | 91 ms | 19796 KB |
005.txt | AC | 90 ms | 21844 KB |
006.txt | AC | 93 ms | 16976 KB |
007.txt | AC | 92 ms | 20688 KB |
008.txt | AC | 92 ms | 21716 KB |
009.txt | AC | 96 ms | 21844 KB |
010.txt | AC | 91 ms | 18764 KB |
011.txt | AC | 91 ms | 18768 KB |
012.txt | AC | 100 ms | 21332 KB |
013.txt | AC | 91 ms | 18644 KB |
014.txt | AC | 92 ms | 23764 KB |
015.txt | AC | 92 ms | 20564 KB |
016.txt | AC | 92 ms | 21588 KB |
017.txt | AC | 92 ms | 20052 KB |
018.txt | AC | 96 ms | 19924 KB |
example0.txt | AC | 92 ms | 21844 KB |
example1.txt | AC | 91 ms | 18004 KB |
example2.txt | AC | 91 ms | 21972 KB |