Submission #11444212


Source Code Expand

import java.util.*;
import java.io.*;

public class Main {
	static final int mod = (int) 1e9 + 7;
	static final int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int[] DX8 = { -1, -1, -1, 0, 0, 1, 1, 1 }, DY8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;
	static final String nextLine = "\n";

	static int b[][], c[][];
	
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		b = new int[2][3];
		c = new int[3][2];
		int tot = 0;
		for(int i=0;i<2;i++) {
			for(int j=0;j<3;j++) {
				b[i][j] = fs.nextInt();
				tot += b[i][j];
			}
		}
		for(int i=0;i<3;i++) {
			for(int j=0;j<2;j++) {
				c[i][j] = fs.nextInt();
				tot += c[i][j];
			}
		}
		int field[][] = new int[3][3];
		int res = dfs(field, 0);
		int ans1 = (tot + res)/2;
		int ans2 = tot - ans1;
		System.out.println(ans1);
		System.out.println(ans2);
	}

	static int dfs(int field[][], int t) {
		if(t == 9) {
			return culc(field);
		}
		int ret = 0;
		if(t%2==0) {
			ret = -INF;
			for(int i=0;i<3;i++) {
				for(int j=0;j<3;j++) {
					if(field[i][j] != 0)continue;
					field[i][j] = 1;
					ret = Math.max(ret, dfs(field, t+1));
					field[i][j] = 0;
				}
			}
			return ret;
		}
		else {
			ret = INF;
			for(int i=0;i<3;i++) {
				for(int j=0;j<3;j++) {
					if(field[i][j] != 0)continue;
					field[i][j] = 2;
					ret = Math.min(ret, dfs(field, t+1));
					field[i][j] = 0;
				}
			}
			return ret;
		}
	}
	
	static int culc(int f[][]) {
		int ret = 0;
		for(int i=0;i<2;i++) {
			for(int j=0;j<3;j++) {
				if(f[i][j] == f[i+1][j]) ret += b[i][j];
				else ret -= b[i][j];
			}
		}
		for(int i=0;i<3;i++) {
			for(int j=0;j<2;j++) {
				if(f[i][j] == f[i][j+1]) ret += c[i][j];
				else ret -= c[i][j];
			}
		}
		return ret;
	}
	
	
	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Submission Info

Submission Time
Task C - 双子と○×ゲーム
User narushima
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 3862 Byte
Status AC
Exec Time 175 ms
Memory 26996 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 24
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 172 ms 25848 KB
sample-02.txt AC 173 ms 24436 KB
test-01.txt AC 172 ms 24704 KB
test-02.txt AC 173 ms 24992 KB
test-03.txt AC 174 ms 24312 KB
test-04.txt AC 173 ms 24436 KB
test-05.txt AC 173 ms 24960 KB
test-06.txt AC 173 ms 23424 KB
test-07.txt AC 173 ms 26880 KB
test-08.txt AC 172 ms 23936 KB
test-09.txt AC 171 ms 25588 KB
test-10.txt AC 172 ms 25332 KB
test-11.txt AC 171 ms 26996 KB
test-12.txt AC 175 ms 26880 KB
test-13.txt AC 173 ms 23928 KB
test-14.txt AC 171 ms 24440 KB
test-15.txt AC 172 ms 24056 KB
test-16.txt AC 173 ms 23936 KB
test-17.txt AC 173 ms 24568 KB
test-18.txt AC 173 ms 24192 KB
test-19.txt AC 174 ms 24696 KB
test-20.txt AC 171 ms 26872 KB