Submission #433420
Source Code Expand
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Comparator; import java.util.HashSet; import java.util.List; class Solve{ ContestScanner in; Solve() throws FileNotFoundException{ in = new ContestScanner(); } int[][] b; int[][] c; void solve() throws IOException{ b = new int[2][3]; c = new int[3][2]; for(int i=0; i<2; i++){ for(int j=0; j<3; j++){ b[i][j] = in.nextInt(); } } for(int i=0; i<3; i++){ for(int j=0; j<2; j++){ c[i][j] = in.nextInt(); } } Point p = chokudai(new int[3][3], 0); System.out.println(p.ch); System.out.println(p.no); } Point chokudai(int[][] board, int used){ int max = -1; Point mp = null; for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ if(board[i][j] != 0) continue; board[i][j] = 1; Point p = naoko(board, used+1); if(max < p.ch){ max = p.ch; mp = p; } board[i][j] = 0; } } return mp; } Point naoko(int[][] board, int used){ if(used==9){ Point c = culc(board); return c; } int max = -1; Point mp = null; for(int i=0; i<3; i++){ for(int j=0; j<3; j++){ if(board[i][j] != 0) continue; board[i][j] = -1; Point p = chokudai(board, used+1); if(max < p.no){ max = p.no; mp = p; } board[i][j] = 0; } } return mp; } Point culc(int[][] board){ int ch = 0; int no = 0; for(int i=0; i<2; i++){ for(int j=0; j<3; j++){ if(board[i][j] == board[i+1][j]) ch+=b[i][j]; else no+=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]) ch+=c[i][j]; else no+=c[i][j]; } } return new Point(ch, no); } } class Point{ int ch, no; Point(int ch, int no){ this.ch = ch; this.no = no; } public String toString(){ return ch+" "+no; } } public class Main { static HashSet<String> set = new HashSet<String>(); public static void main(String[] args) throws NumberFormatException, IOException { Solve solve = new Solve(); solve.solve(); } } class Timer{ long time; public void set(){ time = System.currentTimeMillis(); } public long stop(){ return System.currentTimeMillis()-time; } } class Node{ int id; ArrayList<Node> edge = new ArrayList<Node>(); public Node(int id) { this.id = id; } public void createEdge(Node node) { edge.add(node); } } class MyComp implements Comparator<int[]> { final int idx; public MyComp(int idx){ this.idx = idx; } public int compare(int[] a, int[] b) { return a[idx] - b[idx]; } } class Reverse implements Comparator<Integer> { public int compare(Integer arg0, Integer arg1) { return arg1 - arg0; } } class ContestWriter { private PrintWriter out; public ContestWriter(String filename) throws IOException { out = new PrintWriter(new BufferedWriter(new FileWriter(filename))); } public ContestWriter() throws IOException { out = new PrintWriter(System.out); } public void println(String str) { out.println(str); } public void println(Object obj) { out.println(obj); } public void print(String str) { out.print(str); } public void print(Object obj) { out.print(obj); } public void close() { out.close(); } } class ContestScanner { private BufferedReader reader; private String[] line; private int idx; public ContestScanner() throws FileNotFoundException { reader = new BufferedReader(new InputStreamReader(System.in)); } public ContestScanner(String filename) throws FileNotFoundException { reader = new BufferedReader(new InputStreamReader(new FileInputStream( filename))); } public String nextToken() throws IOException { if (line == null || line.length <= idx) { line = reader.readLine().trim().split(" "); idx = 0; } return line[idx++]; } public String readLine() throws IOException{ return reader.readLine(); } public long nextLong() throws IOException, NumberFormatException { return Long.parseLong(nextToken()); } public int nextInt() throws NumberFormatException, IOException { return (int) nextLong(); } public double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(nextToken()); } }
Submission Info
Submission Time | |
---|---|
Task | C - 双子と○×ゲーム |
User | threepipes_s |
Language | Java (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 4643 Byte |
Status | AC |
Exec Time | 493 ms |
Memory | 35344 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 | 463 ms | 35152 KB |
sample-02.txt | AC | 466 ms | 35040 KB |
test-01.txt | AC | 477 ms | 34912 KB |
test-02.txt | AC | 473 ms | 35004 KB |
test-03.txt | AC | 470 ms | 34924 KB |
test-04.txt | AC | 476 ms | 34920 KB |
test-05.txt | AC | 472 ms | 35312 KB |
test-06.txt | AC | 470 ms | 34772 KB |
test-07.txt | AC | 464 ms | 34952 KB |
test-08.txt | AC | 468 ms | 35344 KB |
test-09.txt | AC | 471 ms | 35092 KB |
test-10.txt | AC | 487 ms | 35196 KB |
test-11.txt | AC | 479 ms | 35020 KB |
test-12.txt | AC | 493 ms | 35280 KB |
test-13.txt | AC | 477 ms | 35196 KB |
test-14.txt | AC | 459 ms | 35312 KB |
test-15.txt | AC | 466 ms | 34804 KB |
test-16.txt | AC | 476 ms | 35056 KB |
test-17.txt | AC | 469 ms | 35040 KB |
test-18.txt | AC | 474 ms | 35084 KB |
test-19.txt | AC | 466 ms | 35076 KB |
test-20.txt | AC | 467 ms | 35048 KB |