Submission #1986433


Source Code Expand

import java.util.HashSet;
import java.util.Set;

public class Main {

	private static void solve() {
		int n = ni();
		int m = ni();
		
		int[] count = new int[m];
		int[] samePair = new int[m];
		Set<Integer> set = new HashSet<>();
		for (int i = 0; i < n; i ++) {
			int x = ni();
			count[x % m] ++;
			if (set.contains(x)) {
				set.remove(x);
				samePair[x % m] ++;
			} else {
				set.add(x);
			}
		}
		
		int ret = count[0] / 2;
		count[0] %= 2;
		if (m % 2 == 0) {
			ret += count[m / 2] / 2;
			count[m / 2] %= 2;
		}
		for (int i = 1; i < (m + 1) / 2; i ++) {
			int v = Math.min(count[i], count[m - i]);
			ret += v;
			count[i] -= v;
			count[m - i] -= v;
		}
		for (int i = 0; i < m; i ++) {
			int v = Math.min(samePair[i], count[i] / 2);
			ret +=v;
		}
		System.out.println(ret);
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			@Override
			public void run() {
				long start = System.currentTimeMillis();
				String debug = args.length > 0 ? args[0] : null;
				if (debug != null) {
					try {
						is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
					} catch (Exception e) {
						throw new RuntimeException(e);
					}
				}
				reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
				solve();
				out.flush();
				tr((System.currentTimeMillis() - start) + "ms");
			}
		}, "", 64000000).start();
	}

	private static java.io.InputStream is = System.in;
	private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
	private static java.util.StringTokenizer tokenizer = null;
	private static java.io.BufferedReader reader;

	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new java.util.StringTokenizer(reader.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	private static double nd() {
		return Double.parseDouble(next());
	}

	private static long nl() {
		return Long.parseLong(next());
	}

	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private static char[] ns() {
		return next().toCharArray();
	}

	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}

	private static int[][] ntable(int n, int m) {
		int[][] table = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[i][j] = ni();
			}
		}
		return table;
	}

	private static int[][] nlist(int n, int m) {
		int[][] table = new int[m][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				table[j][i] = ni();
			}
		}
		return table;
	}

	private static int ni() {
		return Integer.parseInt(next());
	}

	private static void tr(Object... o) {
		if (is != System.in)
			System.out.println(java.util.Arrays.deepToString(o));
	}
}

Submission Info

Submission Time
Task D - Pair Cards
User hiromi_ayase
Language Java8 (OpenJDK 1.8.0)
Score 700
Code Size 3089 Byte
Status AC
Exec Time 222 ms
Memory 47044 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 34
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, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt AC 70 ms 21204 KB
01-02.txt AC 197 ms 40760 KB
01-03.txt AC 190 ms 42508 KB
01-04.txt AC 190 ms 40212 KB
01-05.txt AC 201 ms 40332 KB
01-06.txt AC 201 ms 42136 KB
01-07.txt AC 215 ms 44280 KB
01-08.txt AC 213 ms 42352 KB
01-09.txt AC 201 ms 44044 KB
01-10.txt AC 202 ms 38168 KB
01-11.txt AC 213 ms 41796 KB
01-12.txt AC 180 ms 44000 KB
01-13.txt AC 203 ms 41928 KB
01-14.txt AC 213 ms 43844 KB
01-15.txt AC 201 ms 44056 KB
01-16.txt AC 200 ms 43232 KB
01-17.txt AC 216 ms 47044 KB
01-18.txt AC 195 ms 44044 KB
01-19.txt AC 222 ms 43376 KB
01-20.txt AC 209 ms 46092 KB
01-21.txt AC 209 ms 41924 KB
01-22.txt AC 205 ms 40920 KB
01-23.txt AC 195 ms 36832 KB
01-24.txt AC 209 ms 39344 KB
01-25.txt AC 195 ms 41840 KB
01-26.txt AC 207 ms 40908 KB
01-27.txt AC 171 ms 29748 KB
01-28.txt AC 108 ms 21624 KB
01-29.txt AC 80 ms 21716 KB
01-30.txt AC 80 ms 23952 KB
sample-01.txt AC 69 ms 19540 KB
sample-02.txt AC 70 ms 19924 KB