Submission #1176001
Source Code Expand
import java.util.*; public class Main { static int[][] b = new int[2][3]; static int[][] c = new int[3][2]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 先手と後手の得点の和 int sum = 0; for(int i = 0; i < 2; i++) { for(int j = 0; j < 3; j++) { b[i][j] = sc.nextInt(); sum += b[i][j]; } } for(int i = 0; i < 3; i++) { for(int j = 0; j < 2; j++) { c[i][j] = sc.nextInt(); sum += c[i][j]; } } char[][] board = new char[3][3]; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { board[i][j] = '.'; } } int score = dfs(1, board); System.out.println((sum + score) / 2); System.out.println((sum - score) / 2); } // n手目の盤面の評価値(先手の得点-後手の得点) public static int dfs(int n, char[][] board) { if(n == 10) { int sente = 0; int koute = 0; for(int i = 0; i < 2; i++) { for(int j = 0; j < 3; j++) { if(board[i][j] == board[i + 1][j]) { sente += b[i][j]; } else { koute += b[i][j]; } } } for(int i = 0; i < 3; i++) { for(int j = 0; j < 2; j++) { if(board[i][j] == board[i][j + 1]) { sente += c[i][j]; } else { koute += c[i][j]; } } } return sente - koute; } else { if(n % 2 == 0) { int score = Integer.MAX_VALUE; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { if(board[i][j] == '.') { board[i][j] = 'x'; score = Math.min(score, dfs(n + 1, board)); board[i][j] = '.'; } } } return score; } else { int score = -10000; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { if(board[i][j] == '.') { board[i][j] = 'o'; score = Math.max(score, dfs(n + 1, board)); board[i][j] = '.'; } } } return score; } } } }
Submission Info
Submission Time | |
---|---|
Task | C - 双子と○×ゲーム |
User | takeya |
Language | Java8 (OpenJDK 1.8.0) |
Score | 100 |
Code Size | 2271 Byte |
Status | AC |
Exec Time | 210 ms |
Memory | 27292 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 | sample-01.txt, sample-02.txt, 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 | 210 ms | 25244 KB |
sample-02.txt | AC | 191 ms | 25108 KB |
test-01.txt | AC | 190 ms | 27292 KB |
test-02.txt | AC | 189 ms | 25236 KB |
test-03.txt | AC | 191 ms | 24476 KB |
test-04.txt | AC | 189 ms | 27292 KB |
test-05.txt | AC | 190 ms | 26124 KB |
test-06.txt | AC | 191 ms | 23196 KB |
test-07.txt | AC | 189 ms | 25244 KB |
test-08.txt | AC | 192 ms | 27028 KB |
test-09.txt | AC | 190 ms | 26012 KB |
test-10.txt | AC | 188 ms | 24200 KB |
test-11.txt | AC | 190 ms | 27292 KB |
test-12.txt | AC | 189 ms | 23060 KB |
test-13.txt | AC | 190 ms | 27292 KB |
test-14.txt | AC | 188 ms | 24084 KB |
test-15.txt | AC | 189 ms | 25116 KB |
test-16.txt | AC | 190 ms | 27292 KB |
test-17.txt | AC | 190 ms | 24080 KB |
test-18.txt | AC | 191 ms | 27164 KB |
test-19.txt | AC | 191 ms | 27036 KB |
test-20.txt | AC | 192 ms | 26524 KB |