Submission #7458819


Source Code Expand

Copy
#!/usr/bin/env python3
from collections import defaultdict
N,M=map(int,input().split())
X=list(map(int,input().split()))
tab=[0]*M
cnts=[defaultdict(lambda: 0) for _ in range(M)]
for x in X:
    tab[x%M]+=1
    cnts[x%M][x]+=1
    
ans=0
for i in range(M//2+1):
    if i==0 or (M%2==0 and i==M//2):
        npair = tab[i]//2
        tab[i]-= 2*npair
        ans += npair
    else:
        npair = min(tab[i],tab[M-i])
        tab[i]-= npair
        tab[M-i]-= npair
        ans += npair

for remn, d in zip(tab, cnts):
    tmp=0
    for _,n in d.items():
        tmp += (n//2)
    ans += min(tmp, remn//2)

print(ans)

Submission Info

Submission Time
Task D - Pair Cards
User torimy
Language PyPy3 (2.4.0)
Score 700
Code Size 647 Byte
Status
Exec Time 376 ms
Memory 102124 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 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
Case Name Status Exec Time Memory
01-01.txt 177 ms 38256 KB
01-02.txt 237 ms 55792 KB
01-03.txt 234 ms 59376 KB
01-04.txt 239 ms 54512 KB
01-05.txt 231 ms 55152 KB
01-06.txt 240 ms 62316 KB
01-07.txt 232 ms 56556 KB
01-08.txt 246 ms 59116 KB
01-09.txt 259 ms 60268 KB
01-10.txt 317 ms 72940 KB
01-11.txt 364 ms 94060 KB
01-12.txt 214 ms 52804 KB
01-13.txt 257 ms 62404 KB
01-14.txt 234 ms 59884 KB
01-15.txt 230 ms 56812 KB
01-16.txt 236 ms 61164 KB
01-17.txt 237 ms 58092 KB
01-18.txt 268 ms 63340 KB
01-19.txt 285 ms 67692 KB
01-20.txt 376 ms 102124 KB
01-21.txt 229 ms 52460 KB
01-22.txt 223 ms 52464 KB
01-23.txt 222 ms 52336 KB
01-24.txt 241 ms 52720 KB
01-25.txt 267 ms 60528 KB
01-26.txt 290 ms 78060 KB
01-27.txt 293 ms 84116 KB
01-28.txt 253 ms 68956 KB
01-29.txt 217 ms 51676 KB
01-30.txt 247 ms 66908 KB
sample-01.txt 172 ms 38256 KB
sample-02.txt 167 ms 38256 KB