Submission #992214
Source Code Expand
import java.util.ArrayList; import java.util.HashSet; import java.util.Scanner; public class Main { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int N = sc.nextInt(); int M = sc.nextInt(); ArrayList<ArrayList<Integer>> list = new ArrayList<>(); for (int i = 0; i < M; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < N; i++) { int X = Integer.parseInt(sc.next()); list.get(X % M).add(X); } int ans = list.get(0).size() / 2; if (M % 2 == 0) ans += list.get(M / 2).size() / 2; for (int i = 1; i < (M + 1) / 2; i++) { ArrayList<Integer> l1 = list.get(i); ArrayList<Integer> l2 = list.get(M - i); ans += Math.min(l1.size(), l2.size()); ArrayList<Integer> l = l1.size() < l2.size() ? l2 : l1; HashSet<Integer> exist = new HashSet<>(); int dup = 0; for (int v : l) { if (exist.contains(v)) { ++dup; exist.remove(v); } else { exist.add(v); } } ans += Math.min(dup, Math.abs(l1.size() - l2.size()) / 2); } System.out.println(ans); } }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | tomerun |
Language | Java8 (OpenJDK 1.8.0) |
Score | 700 |
Code Size | 1198 Byte |
Status | AC |
Exec Time | 502 ms |
Memory | 48212 KB |
Judge Result
Set Name | sample | all | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt |
all | 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 150 ms | 10192 KB |
01-02.txt | AC | 432 ms | 33632 KB |
01-03.txt | AC | 419 ms | 33160 KB |
01-04.txt | AC | 461 ms | 33428 KB |
01-05.txt | AC | 433 ms | 32988 KB |
01-06.txt | AC | 472 ms | 33568 KB |
01-07.txt | AC | 468 ms | 33892 KB |
01-08.txt | AC | 468 ms | 33688 KB |
01-09.txt | AC | 453 ms | 33860 KB |
01-10.txt | AC | 471 ms | 37264 KB |
01-11.txt | AC | 494 ms | 45956 KB |
01-12.txt | AC | 459 ms | 33544 KB |
01-13.txt | AC | 478 ms | 35336 KB |
01-14.txt | AC | 435 ms | 32920 KB |
01-15.txt | AC | 463 ms | 33524 KB |
01-16.txt | AC | 494 ms | 33604 KB |
01-17.txt | AC | 455 ms | 33784 KB |
01-18.txt | AC | 431 ms | 34032 KB |
01-19.txt | AC | 489 ms | 34596 KB |
01-20.txt | AC | 502 ms | 48212 KB |
01-21.txt | AC | 439 ms | 32940 KB |
01-22.txt | AC | 431 ms | 33680 KB |
01-23.txt | AC | 437 ms | 33600 KB |
01-24.txt | AC | 460 ms | 33672 KB |
01-25.txt | AC | 472 ms | 35432 KB |
01-26.txt | AC | 493 ms | 39524 KB |
01-27.txt | AC | 420 ms | 39480 KB |
01-28.txt | AC | 209 ms | 22768 KB |
01-29.txt | AC | 175 ms | 14032 KB |
01-30.txt | AC | 169 ms | 19020 KB |
sample-01.txt | AC | 125 ms | 9556 KB |
sample-02.txt | AC | 125 ms | 9684 KB |