Submission #433981
Source Code Expand
import java.util.Scanner; public class Main { static int[][] b; static int[][] c; static boolean turnA; static void solve() { // A: naohiro // B: naoko // A -> B -> ... b = new int[2][3]; b[0][0] = nextInt(); b[0][1] = nextInt(); b[0][2] = nextInt(); b[1][0] = nextInt(); b[1][1] = nextInt(); b[1][2] = nextInt(); c = new int[3][2]; c[0][0] = nextInt(); c[0][1] = nextInt(); c[1][0] = nextInt(); c[1][1] = nextInt(); c[2][0] = nextInt(); c[2][1] = nextInt(); int[][] board = new int[3][3]; // 0:N, 1:A, 2:B for (int i = 0; i < 9; i++) { board = put(board, 9 - i, turnA = (i & 1) == 0); } out(score(board, true)); out(score(board, false)); } static int[][] put(int[][] board, int lv, boolean a) { int bx = 0; int by = 0; int bs = -1; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (board[i][j] == 0) { board[i][j] = a ? 1 : 2; int s = minmax(board, lv - 1, false, !a); if (s > bs) { bs = s; bx = i; by = j; } board[i][j] = 0; } } } board[bx][by] = a ? 1 : 2; return board; } static int minmax(int[][] board, int lv, boolean max, boolean a) { if (lv == 0) { return score(board, turnA); } int bs = max ? -1 : 1000000009; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (board[i][j] == 0) { board[i][j] = a ? 1 : 2; int s = minmax(board, lv - 1, !max, !a); if (max) { if (s >= bs) bs = s; } else { if (s <= bs) bs = s; } board[i][j] = 0; } } } return bs; } private static int score(int[][] board, boolean a) { int s = 0; if (a) { if (board[0][0] == board[1][0]) s += b[0][0]; if (board[0][1] == board[1][1]) s += b[0][1]; if (board[0][2] == board[1][2]) s += b[0][2]; if (board[1][0] == board[2][0]) s += b[1][0]; if (board[1][1] == board[2][1]) s += b[1][1]; if (board[1][2] == board[2][2]) s += b[1][2]; if (board[0][0] == board[0][1]) s += c[0][0]; if (board[1][0] == board[1][1]) s += c[1][0]; if (board[2][0] == board[2][1]) s += c[2][0]; if (board[0][1] == board[0][2]) s += c[0][1]; if (board[1][1] == board[1][2]) s += c[1][1]; if (board[2][1] == board[2][2]) s += c[2][1]; } else { if (board[0][0] != board[1][0]) s += b[0][0]; if (board[0][1] != board[1][1]) s += b[0][1]; if (board[0][2] != board[1][2]) s += b[0][2]; if (board[1][0] != board[2][0]) s += b[1][0]; if (board[1][1] != board[2][1]) s += b[1][1]; if (board[1][2] != board[2][2]) s += b[1][2]; if (board[0][0] != board[0][1]) s += c[0][0]; if (board[1][0] != board[1][1]) s += c[1][0]; if (board[2][0] != board[2][1]) s += c[2][0]; if (board[0][1] != board[0][2]) s += c[0][1]; if (board[1][1] != board[1][2]) s += c[1][1]; if (board[2][1] != board[2][2]) s += c[2][1]; } return s; } static Scanner in; static void out(String val) { System.out.println(val); } static void out(int val) { System.out.println(val); } static void out(char val) { System.out.println(val); } static void out(float val) { System.out.println(val); } static void out(double val) { System.out.println(val); } static void out(boolean val) { System.out.println(val); } static String next() { return in.next(); } static int nextInt() { return parseInt(in.next()); } static int parseInt(String val) { return Integer.parseInt(val); } static int parseInt(char val) { return Integer.parseInt(String.valueOf(val)); } public static void main(String[] args) { in = new Scanner(System.in); solve(); } }
Submission Info
Submission Time | |
---|---|
Task | C - 双子と○×ゲーム |
User | incmprsblfld |
Language | Java (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 3909 Byte |
Status | AC |
Exec Time | 497 ms |
Memory | 28156 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample-01.txt, sample-02.txt |
All | test-01.txt, test-02.txt, test-03.txt, test-04.txt, test-05.txt, test-06.txt, test-07.txt, test-08.txt, test-09.txt, test-10.txt, test-11.txt, test-12.txt, test-13.txt, test-14.txt, test-15.txt, test-16.txt, test-17.txt, test-18.txt, test-19.txt, test-20.txt, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample-01.txt | AC | 491 ms | 28104 KB |
sample-02.txt | AC | 486 ms | 28156 KB |
test-01.txt | AC | 484 ms | 28104 KB |
test-02.txt | AC | 485 ms | 28072 KB |
test-03.txt | AC | 486 ms | 28108 KB |
test-04.txt | AC | 484 ms | 28156 KB |
test-05.txt | AC | 487 ms | 28108 KB |
test-06.txt | AC | 483 ms | 28112 KB |
test-07.txt | AC | 489 ms | 28112 KB |
test-08.txt | AC | 490 ms | 28068 KB |
test-09.txt | AC | 493 ms | 28104 KB |
test-10.txt | AC | 495 ms | 28112 KB |
test-11.txt | AC | 489 ms | 28036 KB |
test-12.txt | AC | 491 ms | 28132 KB |
test-13.txt | AC | 491 ms | 28128 KB |
test-14.txt | AC | 493 ms | 28112 KB |
test-15.txt | AC | 495 ms | 28124 KB |
test-16.txt | AC | 497 ms | 28120 KB |
test-17.txt | AC | 492 ms | 28112 KB |
test-18.txt | AC | 495 ms | 28104 KB |
test-19.txt | AC | 494 ms | 28120 KB |
test-20.txt | AC | 497 ms | 28076 KB |