Submission #993017
Source Code Expand
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.NoSuchElementException; public class Main { private static void solve() { int n = nei(); int m = nei(); ArrayList<Integer> xs = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { xs.add(nei()); } Collections.sort(xs, (a, b) -> a % m - b % m); int[] ns = new int[m]; int[] ss = new int[m]; boolean skp = false; for (int i = 0; i < n; i++) { int x = xs.get(i); int g = x % m; ns[g]++; if (!skp) { if (i < n - 1 && x == xs.get(i + 1)) { ss[g]++; skp = true; } } else skp = false; } int ans = 0; ans += ns[0] >> 1; if (m % 2 == 0) { int mid = m / 2; ans += ns[mid] >> 1; for (int i = 1; i < mid; i++) { int j = m - i; int maxp = min(ns[i], ns[j]); ans += maxp; ns[i] -= maxp; ns[j] -= maxp; while (ns[i] >= 2 && ss[i] > 0) { ns[i] -= 2; ss[i]--; ans++; } while (ns[j] >= 2 && ss[j] > 0) { ns[j] -= 2; ss[j]--; ans++; } } } else { int mid = (m + 1) >> 1; for (int i = 1; i < mid; i++) { int j = m - i; int maxp = min(ns[i], ns[j]); ans += maxp; ns[i] -= maxp; ns[j] -= maxp; while (ns[i] >= 2 && ss[i] > 0) { ns[i] -= 2; ss[i]--; ans++; } while (ns[j] >= 2 && ss[j] > 0) { ns[j] -= 2; ss[j]--; ans++; } } } out(ans); } static int abs(int x) { return x < 0 ? -x : x; } static long abs(long x) { return x < 0 ? -x : x; } static int min(int a, int b) { return a < b ? a : b; } static long min(long a, long b) { return a < b ? a : b; } static int max(int a, int b) { return a > b ? a : b; } static long max(long a, long b) { return a > b ? a : b; } static int clamp(int a, int min, int max) { return a < min ? min : a > max ? max : a; } static long clamp(long a, long min, long max) { return a < min ? min : a > max ? max : a; } static void out(String val) { IO.out(val); } static void out(Object val) { IO.out(String.valueOf(val)); } static void out(int val) { IO.out(String.valueOf(val)); } static void out(long val) { IO.out(String.valueOf(val)); } static void out(char val) { IO.out(String.valueOf(val)); } static void out(float val) { IO.out(String.valueOf(val)); } static void out(double val) { IO.out(String.valueOf(val)); } static void out(boolean val) { IO.out(String.valueOf(val)); } static String nes() { return IO.next(); } static int nei() { return IO.nextInt(); } static long nel() { return IO.nextLong(); } static int parseInt(String val) { return Integer.parseInt(val); } static int parseInt(char val) { return Integer.parseInt(String.valueOf(val)); } static long parseLong(String val) { return Long.parseLong(val); } public static void main(String[] args) { solve(); IO.flush(); } } final class IO { private static final InputStream in = System.in; private static final PrintWriter out = new PrintWriter(System.out, false); private static final byte[] buffer = new byte[1024]; private static int ptr = 0; private static int len = 0; private static boolean hasNextByte() { if (ptr < len) return true; ptr = 0; try { len = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } return len > 0; } private static int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } static boolean hasNext() { byte c; while (hasNextByte() && ((c = buffer[ptr]) < '!' || c > '~')) ptr++; return hasNextByte(); } static String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (b >= '!' && b <= '~') { sb.append((char) b); b = readByte(); } return sb.toString(); } static long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; int sign = 1; int b = readByte(); if (b == '-') { sign = -1; b = readByte(); } if (b < '0' || '9' < b) throw new NumberFormatException(); while (true) { if ('0' <= b && b <= '9') n = n * 10 + b - '0'; else if (b == -1 || b < '!' || b > '~') return n * sign; else throw new NumberFormatException(); b = readByte(); } } static int nextInt() { if (!hasNext()) throw new NoSuchElementException(); int n = 0; int sign = 1; int b = readByte(); if (b == '-') { sign = -1; b = readByte(); } if (b < '0' || '9' < b) throw new NumberFormatException(); while (true) { if ('0' <= b && b <= '9') n = n * 10 + b - '0'; else if (b == -1 || b < '!' || b > '~') return n * sign; else throw new NumberFormatException(); b = readByte(); } } static void out(String val) { out.println(val); } static void flush() { out.flush(); } }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | saharan |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 5242 Byte |
Status | WA |
Exec Time | 329 ms |
Memory | 18844 KB |
Judge Result
Set Name | sample | all | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 211 ms | 14416 KB |
01-02.txt | AC | 237 ms | 16452 KB |
01-03.txt | AC | 280 ms | 17352 KB |
01-04.txt | WA | 270 ms | 17484 KB |
01-05.txt | WA | 273 ms | 17736 KB |
01-06.txt | WA | 276 ms | 16972 KB |
01-07.txt | WA | 274 ms | 17304 KB |
01-08.txt | WA | 299 ms | 17404 KB |
01-09.txt | WA | 316 ms | 18192 KB |
01-10.txt | WA | 329 ms | 18472 KB |
01-11.txt | AC | 327 ms | 18844 KB |
01-12.txt | AC | 231 ms | 16588 KB |
01-13.txt | AC | 316 ms | 17488 KB |
01-14.txt | AC | 270 ms | 16844 KB |
01-15.txt | AC | 272 ms | 17092 KB |
01-16.txt | AC | 292 ms | 17564 KB |
01-17.txt | AC | 301 ms | 17444 KB |
01-18.txt | AC | 322 ms | 18348 KB |
01-19.txt | AC | 317 ms | 17736 KB |
01-20.txt | AC | 310 ms | 18316 KB |
01-21.txt | AC | 265 ms | 16840 KB |
01-22.txt | WA | 271 ms | 16968 KB |
01-23.txt | WA | 294 ms | 18200 KB |
01-24.txt | WA | 304 ms | 17852 KB |
01-25.txt | WA | 311 ms | 17904 KB |
01-26.txt | AC | 326 ms | 18832 KB |
01-27.txt | AC | 281 ms | 17276 KB |
01-28.txt | AC | 198 ms | 14676 KB |
01-29.txt | AC | 192 ms | 14024 KB |
01-30.txt | AC | 190 ms | 14920 KB |
sample-01.txt | AC | 252 ms | 13904 KB |
sample-02.txt | AC | 188 ms | 13772 KB |