Submission #5413165


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int n = ir.nextInt();
		int m = ir.nextInt();
		int[] l = new int[m];
		int[] ct = new int[100010];
		int[] s = new int[m];
		for (int i = 0; i < n; i++) {
			int x = ir.nextInt();
			l[x % m]++;
			ct[x]++;
		}
		for (int i = 0; i <= 100000; i++)
			s[i % m] += ct[i] / 2;
		long res = l[0] / 2 + (m % 2 == 0 ? l[m / 2] / 2 : 0);
		for (int i = 1; i <= (m - 1) / 2; i++) {
			if (l[i] > l[m - i]) {
				res += l[m - i];
				res += Math.min((l[i] - l[m - i]) / 2, s[i]);
			} else {
				res += l[i];
				res += Math.min((l[m - i] - l[i]) / 2, s[m - i]);
			}
		}
		out.println(res);
	}

	public static void main(String[] args) {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}

	static void tr(Object... o) {
		out.println(Arrays.deepToString(o));
	}
}

Submission Info

Submission Time
Task D - Pair Cards
User holeguma
Language Java8 (OpenJDK 1.8.0)
Score 700
Code Size 3800 Byte
Status AC
Exec Time 114 ms
Memory 23892 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 76 ms 19412 KB
01-02.txt AC 101 ms 20948 KB
01-03.txt AC 102 ms 21972 KB
01-04.txt AC 101 ms 20180 KB
01-05.txt AC 100 ms 18260 KB
01-06.txt AC 101 ms 19796 KB
01-07.txt AC 100 ms 20052 KB
01-08.txt AC 104 ms 16724 KB
01-09.txt AC 103 ms 20692 KB
01-10.txt AC 114 ms 21716 KB
01-11.txt AC 105 ms 23892 KB
01-12.txt AC 101 ms 21844 KB
01-13.txt AC 103 ms 20692 KB
01-14.txt AC 100 ms 20436 KB
01-15.txt AC 102 ms 20564 KB
01-16.txt AC 108 ms 21460 KB
01-17.txt AC 101 ms 18388 KB
01-18.txt AC 101 ms 21972 KB
01-19.txt AC 102 ms 20692 KB
01-20.txt AC 107 ms 22612 KB
01-21.txt AC 102 ms 19284 KB
01-22.txt AC 102 ms 20820 KB
01-23.txt AC 102 ms 21588 KB
01-24.txt AC 101 ms 21972 KB
01-25.txt AC 102 ms 20052 KB
01-26.txt AC 94 ms 20820 KB
01-27.txt AC 100 ms 23892 KB
01-28.txt AC 92 ms 19412 KB
01-29.txt AC 76 ms 19028 KB
01-30.txt AC 86 ms 19028 KB
sample-01.txt AC 74 ms 19028 KB
sample-02.txt AC 72 ms 19668 KB