Submission #1531700


Source Code Expand

from collections import defaultdict
from itertools import product
from math import pi
import copy

b, c = None, None

def calc(field):
    t, n = 0, 0
    for y in range(3):
        for x in range(3):
            if y + 1 < 3:
                if field[y][x] == field[y + 1][x]:
                    t += b[y][x]
                else:
                    n += b[y][x]
            if x + 1 < 3:
                if field[y][x] == field[y][x + 1]:
                    t += c[y][x]
                else:
                    n += c[y][x]
    return t, n

memo = {}


def lt(l):
    return tuple(l[0]), tuple(l[1]), tuple(l[2])


def dfs(i, field):
    if i >= 9:
        return calc(field)

    if lt(field) in memo:
        return memo[lt(field)]

    mark = i % 2

    t_score, n_score = 0, 0
    for y in range(3):
        for x in range(3):
            if field[y][x] is None:
                f = copy.deepcopy(field)
                f[y][x] = mark
                t, n = dfs(i + 1, f)

                if i % 2 == 0 and t > t_score:
                    t_score, n_score = t, n
                elif i % 2 == 1 and n > n_score:
                    t_score, n_score = t, n

    memo[lt(field)] = t_score, n_score
    return t_score, n_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)]
    print(*dfs(0, field), sep="\n")


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task C - 双子と○×ゲーム
User MitI_7
Language Python (3.4.3)
Score 0
Code Size 1719 Byte
Status WA
Exec Time 360 ms
Memory 6232 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 2
AC × 16
WA × 8
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 356 ms 6232 KB
sample-02.txt AC 342 ms 6112 KB
test-01.txt AC 349 ms 6132 KB
test-02.txt AC 345 ms 6132 KB
test-03.txt AC 348 ms 6112 KB
test-04.txt WA 339 ms 6108 KB
test-05.txt WA 342 ms 6072 KB
test-06.txt WA 344 ms 6108 KB
test-07.txt AC 353 ms 6116 KB
test-08.txt AC 342 ms 6144 KB
test-09.txt AC 355 ms 6172 KB
test-10.txt AC 344 ms 6112 KB
test-11.txt AC 342 ms 6104 KB
test-12.txt WA 339 ms 6176 KB
test-13.txt WA 353 ms 6124 KB
test-14.txt AC 339 ms 6072 KB
test-15.txt WA 344 ms 6108 KB
test-16.txt AC 341 ms 6104 KB
test-17.txt WA 346 ms 6108 KB
test-18.txt AC 360 ms 6136 KB
test-19.txt WA 352 ms 6104 KB
test-20.txt AC 346 ms 6128 KB