Submission #5809772
Source Code Expand
import java.io.*; import java.util.*; import java.util.Map.Entry; import java.util.stream.Collectors; @SuppressWarnings("unused") public class Main { String fileName = "input.txt"; final boolean isDebug = false; //final boolean isDebug = true; FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(System.out); final int MOD = (int)1e9+7; final long INF = Long.MAX_VALUE / 2; //final int INF = Integer.MAX_VALUE / 2; int H, W; boolean[][] visited, winF; char[][] board; int[] dx = {1, 1, 0}; int[] dy = {0, 1, 1}; void solve() throws Exception{ H = in.nextInt(); W = in.nextInt(); visited = new boolean[H][W]; winF = new boolean[H][W]; board = new char[H][W]; for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) board[i][j] = in.nextChar(); System.out.println(bfs(0, 0) ? "First" : "Second"); } boolean bfs(int y, int x){ if(visited[y][x]) return winF[y][x]; boolean res = false; for(int i = 0; i < dy.length; i++){ int nextY = y + dy[i], nextX = x + dx[i]; if(nextY < 0 || nextY >= H || nextX < 0 || nextX >= W) continue; if(board[nextY][nextX] == '#') continue; if(!bfs(nextY, nextX)){ res = true; break; } } visited[y][x] = true; winF[y][x] = res; return winF[y][x]; } /* end solve */ /* main */ public static void main(String[] args) throws Exception { new Main().m(); } void m() throws Exception { if(isDebug) in = new FastScanner(new FileInputStream(fileName)); solve(); out.flush(); } /* end main */ } /* end Main */ class FastScanner { Reader input; FastScanner() {this(System.in);} FastScanner(InputStream stream) {this.input = new BufferedReader(new InputStreamReader(stream));} int nextInt() {return (int) nextLong();} long nextLong() { try { int sign = 1; int b = input.read(); while ((b < '0' || '9' < b) && b != '-' && b != '+') { b = input.read(); } if (b == '-') { sign = -1; b = input.read(); } else if (b == '+') { b = input.read(); } long ret = b - '0'; while (true) { b = input.read(); if (b < '0' || '9' < b) return ret * sign; ret *= 10; ret += b - '0'; } } catch (IOException e) { e.printStackTrace(); return -1; } } double nextDouble() { try { double sign = 1; int b = input.read(); while ((b < '0' || '9' < b) && b != '-' && b != '+') { b = input.read(); } if (b == '-') { sign = -1; b = input.read(); } else if (b == '+') { b = input.read(); } double ret = b - '0'; while (true) { b = input.read(); if (b < '0' || '9' < b) break; ret *= 10; ret += b - '0'; } if (b != '.') return sign * ret; double div = 1; b = input.read(); while ('0' <= b && b <= '9') { ret *= 10; ret += b - '0'; div *= 10; b = input.read(); } return sign * ret / div; } catch (IOException e) { e.printStackTrace(); return Double.NaN; } } char nextChar() { try { int b = input.read(); while (Character.isWhitespace(b)) { b = input.read(); } return (char) b; } catch (IOException e) { e.printStackTrace(); return 0; } } String nextStr() { try { StringBuilder sb = new StringBuilder(); int b = input.read(); while (Character.isWhitespace(b)) { b = input.read(); } while (b != -1 && !Character.isWhitespace(b)) { sb.append((char) b); b = input.read(); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); return ""; } } }
Submission Info
Submission Time | |
---|---|
Task | B - マス目と駒 |
User | Oland |
Language | Java8 (OpenJDK 1.8.0) |
Score | 100 |
Code Size | 3694 Byte |
Status | AC |
Exec Time | 92 ms |
Memory | 23636 KB |
Judge Result
Set Name | Sample | Dataset1 | Dataset2 | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 30 / 30 | 70 / 70 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt, sample-03.txt |
Dataset1 | sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt |
Dataset2 | sample-01.txt, sample-02.txt, sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, sample-01.txt, sample-02.txt, sample-03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 70 ms | 20052 KB |
01-02.txt | AC | 68 ms | 19284 KB |
01-03.txt | AC | 69 ms | 19412 KB |
01-04.txt | AC | 70 ms | 19156 KB |
01-05.txt | AC | 69 ms | 17748 KB |
01-06.txt | AC | 69 ms | 18004 KB |
01-07.txt | AC | 69 ms | 21076 KB |
01-08.txt | AC | 71 ms | 20564 KB |
01-09.txt | AC | 69 ms | 20692 KB |
01-10.txt | AC | 70 ms | 18772 KB |
01-11.txt | AC | 69 ms | 21204 KB |
01-12.txt | AC | 70 ms | 18516 KB |
01-13.txt | AC | 67 ms | 19284 KB |
01-14.txt | AC | 71 ms | 21072 KB |
01-15.txt | AC | 71 ms | 19156 KB |
02-01.txt | AC | 92 ms | 19796 KB |
02-02.txt | AC | 68 ms | 21460 KB |
02-03.txt | AC | 73 ms | 21204 KB |
02-04.txt | AC | 68 ms | 18516 KB |
02-05.txt | AC | 70 ms | 18260 KB |
02-06.txt | AC | 85 ms | 18004 KB |
02-07.txt | AC | 85 ms | 20948 KB |
02-08.txt | AC | 85 ms | 21460 KB |
02-09.txt | AC | 88 ms | 23636 KB |
02-10.txt | AC | 84 ms | 17876 KB |
02-11.txt | AC | 77 ms | 19412 KB |
02-12.txt | AC | 82 ms | 21204 KB |
02-13.txt | AC | 75 ms | 18516 KB |
02-14.txt | AC | 78 ms | 18132 KB |
02-15.txt | AC | 85 ms | 21076 KB |
sample-01.txt | AC | 69 ms | 19284 KB |
sample-02.txt | AC | 71 ms | 18260 KB |
sample-03.txt | AC | 81 ms | 19924 KB |