CODE FESTIVAL 2016 Final

Submission #7913900

Source codeソースコード

import sys
input = sys.stdin.readline
from collections import Counter

N, M = map(int, input().split())
X = list(map(int, input().split()))


def main():
    P = [[] for _ in range(M)]

    for x in X:
        P[x%M].append(x)

    ans = 0
    checked = [False]*M
    for m in range(M):
        if checked[m]:
            continue
        if m == 0 or m == M-m:
            ans += len(P[m])//2
        else:
            P1, P2 = P[m], P[M-m]
            L1, L2 = len(P[m]), len(P[M-m])
            if L2 > L1:
                P1, P2 = P[M-m], P[m]
                L1, L2 = len(P1), len(P2)
            
            C1 = Counter(P1)
            n = 0
            for num, c1 in C1.items():
                n += c1//2
            if L1 - n*2 <= L2:
                ans += (L1+L2)//2
            else:
                ans += L2 + n

            checked[m] = True
            checked[M-m] = True

    print(ans)


if __name__ == "__main__":
    main()

Submission

Task問題 D - Pair Cards
User nameユーザ名 wattaihei
Created time投稿日時
Language言語 Python3 (3.4.3)
Status状態 AC
Score得点 700
Source lengthソースコード長 991 Byte
File nameファイル名
Exec time実行時間 428 ms
Memory usageメモリ使用量 19868 KB

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
all 700 / 700 sample-01.txt,sample-02.txt,01-01.txt,01-02.txt,01-03.txt,01-04.txt,01-05.txt,01-06.txt,01-07.txt,01-08.txt,01-09.txt,01-10.txt,01-11.txt,01-12.txt,01-13.txt,01-14.txt,01-15.txt,01-16.txt,01-17.txt,01-18.txt,01-19.txt,01-20.txt,01-21.txt,01-22.txt,01-23.txt,01-24.txt,01-25.txt,01-26.txt,01-27.txt,01-28.txt,01-29.txt,01-30.txt,sample-01.txt,sample-02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 21 ms 3316 KB
01-02.txt AC 56 ms 14124 KB
01-03.txt AC 57 ms 14124 KB
01-04.txt AC 63 ms 14124 KB
01-05.txt AC 61 ms 14124 KB
01-06.txt AC 64 ms 14124 KB
01-07.txt AC 64 ms 14124 KB
01-08.txt AC 70 ms 14124 KB
01-09.txt AC 77 ms 14124 KB
01-10.txt AC 214 ms 14124 KB
01-11.txt AC 428 ms 18204 KB
01-12.txt AC 64 ms 14540 KB
01-13.txt AC 203 ms 13644 KB
01-14.txt AC 57 ms 14124 KB
01-15.txt AC 63 ms 14124 KB
01-16.txt AC 66 ms 14124 KB
01-17.txt AC 69 ms 14124 KB
01-18.txt AC 78 ms 14124 KB
01-19.txt AC 114 ms 14124 KB
01-20.txt AC 414 ms 19868 KB
01-21.txt AC 57 ms 14124 KB
01-22.txt AC 61 ms 14124 KB
01-23.txt AC 63 ms 14124 KB
01-24.txt AC 70 ms 14124 KB
01-25.txt AC 166 ms 14124 KB
01-26.txt AC 390 ms 16412 KB
01-27.txt AC 394 ms 15528 KB
01-28.txt AC 338 ms 11432 KB
01-29.txt AC 139 ms 6544 KB
01-30.txt AC 331 ms 11372 KB
sample-01.txt AC 21 ms 3316 KB
sample-02.txt AC 21 ms 3316 KB