Submission #992690


Source Code Expand

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        int m = ni();
        int[] x = nia(n);

        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            if (map.containsKey(x[i])) {
                map.put(x[i], map.get(x[i]) + 1);
            } else {
                map.put(x[i], 1);
            }
        }

        int[][] cnt = new int[2][m];
        for (int t : map.keySet()) {
            cnt[0][t % m] += map.get(t) - map.get(t) % 2;
            cnt[1][t % m] += map.get(t) % 2;
        }

        int ans = (cnt[0][0] + cnt[1][0]) / 2;
        for (int i = 1; i <= m / 2; i++) {
            if (i * 2 == m) {
                ans += cnt[1][i] / 2;
                ans += cnt[0][i] / 2;
            } else {
                int tmp = Math.min(cnt[1][i], cnt[1][m - i]);
                cnt[1][i] -= tmp;
                cnt[1][m - i] -= tmp;
                ans += tmp;

                int tmp2 = Math.min(cnt[1][i], cnt[0][m - i]);
                cnt[1][i] -= tmp2;
                cnt[0][m - i] -= tmp2;
                ans += tmp2;

                int tmp3 = Math.min(cnt[1][m - i], cnt[0][i]);
                cnt[1][m - i] -= tmp3;
                cnt[0][i] -= tmp3;
                ans += tmp3;

                ans += cnt[0][i] / 2;
                ans += cnt[0][m - i] / 2;
            }
        }

        out.println(ans);
    }

    public class Pair implements Comparable<Pair> {
    	int x, y;

    	public Pair(int x, int y) {
    		this.x = x;
    		this.y = y;
    	}

    	public int compareTo(Pair p) {
    		return y - p.y;
    	}
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Submission Info

Submission Time
Task D - Pair Cards
User CrazyBBB
Language Java8 (OpenJDK 1.8.0)
Score 700
Code Size 3307 Byte
Status AC
Exec Time 383 ms
Memory 31564 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 32
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 98 ms 8136 KB
01-02.txt AC 281 ms 30228 KB
01-03.txt AC 278 ms 30176 KB
01-04.txt AC 300 ms 31524 KB
01-05.txt AC 286 ms 30764 KB
01-06.txt AC 283 ms 30276 KB
01-07.txt AC 283 ms 30052 KB
01-08.txt AC 285 ms 30492 KB
01-09.txt AC 289 ms 30240 KB
01-10.txt AC 288 ms 30432 KB
01-11.txt AC 283 ms 31564 KB
01-12.txt AC 242 ms 27492 KB
01-13.txt AC 245 ms 28848 KB
01-14.txt AC 289 ms 30620 KB
01-15.txt AC 299 ms 31020 KB
01-16.txt AC 283 ms 30612 KB
01-17.txt AC 292 ms 31044 KB
01-18.txt AC 295 ms 30220 KB
01-19.txt AC 300 ms 30540 KB
01-20.txt AC 383 ms 31044 KB
01-21.txt AC 267 ms 27564 KB
01-22.txt AC 263 ms 27596 KB
01-23.txt AC 255 ms 27616 KB
01-24.txt AC 260 ms 27832 KB
01-25.txt AC 252 ms 27740 KB
01-26.txt AC 263 ms 28088 KB
01-27.txt AC 236 ms 23572 KB
01-28.txt AC 160 ms 11216 KB
01-29.txt AC 121 ms 9168 KB
01-30.txt AC 122 ms 9040 KB
sample-01.txt AC 96 ms 8140 KB
sample-02.txt AC 95 ms 8268 KB