Submission #1531746
Source Code Expand
from collections import defaultdict from itertools import product from math import pi import copy b, c = None, None def calc_score(field): score = 0 for y in range(3): for x in range(3): if y + 1 < 3 and field[y][x] == field[y + 1][x]: score += b[y][x] if x + 1 < 3 and field[y][x] == field[y][x + 1]: score += c[y][x] return score memo = {} def lt(l): return tuple(l[0]), tuple(l[1]), tuple(l[2]) def dfs(i, field): if i >= 9: return calc_score(field) if lt(field) in memo: return memo[lt(field)] mark = i % 2 best_score = 0 if mark == 0 else 10 ** 10 for y in range(3): for x in range(3): if field[y][x] is None: field[y][x] = mark score = dfs(i + 1, field) field[y][x] = None if mark == 0 and score > best_score: best_score = score if mark == 1 and score < best_score: best_score = score memo[lt(field)] = best_score return best_score def main(): global b, c b1 = list(map(int, input().split())) b2 = list(map(int, input().split())) b = [b1, b2] c1 = list(map(int, input().split())) c2 = list(map(int, input().split())) c3 = list(map(int, input().split())) c = [c1 + [0], c2 + [0], c3 + [0]] field = [[None] * 3 for _ in range(3)] score = dfs(0, field) total = sum([sum(x) for x in b + c]) print(*[score, total - score], sep="\n") if __name__ == '__main__': main()
Submission Info
Submission Time | |
---|---|
Task | C - 双子と○×ゲーム |
User | MitI_7 |
Language | Python (3.4.3) |
Score | 100 |
Code Size | 1669 Byte |
Status | AC |
Exec Time | 77 ms |
Memory | 5824 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 | 75 ms | 5696 KB |
sample-02.txt | AC | 75 ms | 5756 KB |
test-01.txt | AC | 76 ms | 5744 KB |
test-02.txt | AC | 75 ms | 5756 KB |
test-03.txt | AC | 76 ms | 5696 KB |
test-04.txt | AC | 75 ms | 5756 KB |
test-05.txt | AC | 75 ms | 5684 KB |
test-06.txt | AC | 76 ms | 5696 KB |
test-07.txt | AC | 75 ms | 5756 KB |
test-08.txt | AC | 75 ms | 5684 KB |
test-09.txt | AC | 77 ms | 5744 KB |
test-10.txt | AC | 75 ms | 5756 KB |
test-11.txt | AC | 76 ms | 5696 KB |
test-12.txt | AC | 75 ms | 5756 KB |
test-13.txt | AC | 74 ms | 5696 KB |
test-14.txt | AC | 77 ms | 5684 KB |
test-15.txt | AC | 74 ms | 5756 KB |
test-16.txt | AC | 75 ms | 5824 KB |
test-17.txt | AC | 74 ms | 5756 KB |
test-18.txt | AC | 74 ms | 5756 KB |
test-19.txt | AC | 75 ms | 5756 KB |
test-20.txt | AC | 74 ms | 5756 KB |