Submission #7458787


Source Code Expand

Copy
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]-=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 0
Code Size 614 Byte
Status
Exec Time 364 ms
Memory 102252 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt
all 0 / 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 164 ms 38256 KB
01-02.txt 227 ms 55792 KB
01-03.txt 230 ms 59376 KB
01-04.txt 229 ms 54384 KB
01-05.txt 232 ms 55152 KB
01-06.txt 237 ms 62316 KB
01-07.txt 231 ms 56556 KB
01-08.txt 246 ms 59244 KB
01-09.txt 274 ms 61164 KB
01-10.txt 343 ms 73068 KB
01-11.txt 364 ms 94188 KB
01-12.txt 215 ms 52804 KB
01-13.txt 251 ms 62532 KB
01-14.txt 225 ms 59884 KB
01-15.txt 228 ms 56812 KB
01-16.txt 236 ms 61036 KB
01-17.txt 233 ms 57836 KB
01-18.txt 264 ms 63340 KB
01-19.txt 276 ms 67692 KB
01-20.txt 355 ms 102252 KB
01-21.txt 221 ms 52460 KB
01-22.txt 223 ms 52464 KB
01-23.txt 223 ms 52464 KB
01-24.txt 241 ms 52720 KB
01-25.txt 262 ms 60528 KB
01-26.txt 290 ms 78060 KB
01-27.txt 304 ms 84116 KB
01-28.txt 255 ms 68956 KB
01-29.txt 219 ms 51676 KB
01-30.txt 243 ms 67036 KB
sample-01.txt 166 ms 38256 KB
sample-02.txt 165 ms 38256 KB