Submission #1818982


Source Code Expand

import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍(右, 下, 左, 上)
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    H, W = map(int, input().split())
    d = defaultdict(int)
    for y in range(H):
        for c in input():
            d[c] += 1

    counter = [0] * 5
    counter[4] = (H // 2) * (W // 2)

    if H % 2 == 0 and W % 2 == 0:
        pass
    elif H % 2 != 0 and W % 2 == 0:
        counter[2] = W // 2
    elif H % 2 == 0 and W % 2 != 0:
        counter[2] = H // 2
    elif H % 2 != 0 and W % 2 != 0:
        counter[2] = H // 2 + W // 2
        counter[1] = 1

    for x in [4, 2, 1]:
        for k, v in d.items():
            if v >= x and counter[x] > 0:
                n = v // x
                counter[x] -= n
                d[k] -= x * n

    if sum(counter) == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task C - Palindromic Matrix
User MitI_7
Language Python (3.4.3)
Score 400
Code Size 1397 Byte
Status AC
Exec Time 37 ms
Memory 4212 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 32
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt
Case Name Status Exec Time Memory
0_00.txt AC 37 ms 4212 KB
0_01.txt AC 27 ms 3956 KB
0_02.txt AC 27 ms 3952 KB
0_03.txt AC 27 ms 3956 KB
0_04.txt AC 27 ms 3952 KB
1_00.txt AC 27 ms 3960 KB
1_01.txt AC 27 ms 3952 KB
1_02.txt AC 27 ms 3952 KB
1_03.txt AC 27 ms 3952 KB
1_04.txt AC 27 ms 3956 KB
1_05.txt AC 27 ms 3952 KB
1_06.txt AC 27 ms 3956 KB
1_07.txt AC 27 ms 3956 KB
1_08.txt AC 27 ms 3960 KB
1_09.txt AC 28 ms 3952 KB
1_10.txt AC 28 ms 3956 KB
1_11.txt AC 28 ms 3960 KB
1_12.txt AC 28 ms 3960 KB
1_13.txt AC 28 ms 3952 KB
1_14.txt AC 28 ms 3960 KB
1_15.txt AC 28 ms 3960 KB
1_16.txt AC 28 ms 3956 KB
1_17.txt AC 28 ms 3960 KB
1_18.txt AC 28 ms 3952 KB
1_19.txt AC 28 ms 3956 KB
1_20.txt AC 28 ms 3952 KB
1_21.txt AC 28 ms 3952 KB
1_22.txt AC 27 ms 3960 KB
1_23.txt AC 27 ms 3952 KB
1_24.txt AC 27 ms 3956 KB
1_25.txt AC 27 ms 3960 KB
1_26.txt AC 27 ms 3960 KB