Submission #11351728


Source Code Expand

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

public class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] count = new int[m];
        int[] pair = new int[m];
        boolean[] has = new boolean[100001];
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            if (has[x]) {
                pair[x % m]++;
            }
            has[x] = !has[x];
            count[x % m]++;
        }
        long ans = 0;
        for (int i = 0; i <= m / 2; i++) {
            if (i * 2 == m || i == 0) {
                ans += count[i] / 2;
            } else {
                int j = count[i] < count[m - i] ? i : m - i;
                int k = count[i] < count[m - i] ? m - i : i;
                ans += count[j] + Math.min((count[k] - count[j]) / 2, pair[k]);
            }
        }
        out.println(ans);
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

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

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

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

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

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private PrintWriter out = new PrintWriter(System.out);
    boolean autoFlush = false;

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(int[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int i : a) {
            joiner.add(Integer.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void println(long[] a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (long i : a) {
            joiner.add(Long.toString(i));
        }
        out.println(joiner);
        if (autoFlush) {
            out.flush();
        }
    }

    void flush() {
        out.flush();
    }
}

Submission Info

Submission Time
Task D - Pair Cards
User Yu_212
Language Java8 (OpenJDK 1.8.0)
Score 700
Code Size 3949 Byte
Status AC
Exec Time 183 ms
Memory 35684 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 73 ms 17876 KB
01-02.txt AC 169 ms 30492 KB
01-03.txt AC 172 ms 33532 KB
01-04.txt AC 167 ms 33872 KB
01-05.txt AC 180 ms 33552 KB
01-06.txt AC 159 ms 33812 KB
01-07.txt AC 166 ms 33680 KB
01-08.txt AC 162 ms 32996 KB
01-09.txt AC 169 ms 32864 KB
01-10.txt AC 157 ms 32228 KB
01-11.txt AC 170 ms 33392 KB
01-12.txt AC 163 ms 33764 KB
01-13.txt AC 168 ms 31616 KB
01-14.txt AC 168 ms 35684 KB
01-15.txt AC 181 ms 30636 KB
01-16.txt AC 171 ms 30956 KB
01-17.txt AC 160 ms 31844 KB
01-18.txt AC 158 ms 30488 KB
01-19.txt AC 183 ms 33704 KB
01-20.txt AC 171 ms 33208 KB
01-21.txt AC 173 ms 33516 KB
01-22.txt AC 158 ms 33220 KB
01-23.txt AC 174 ms 32996 KB
01-24.txt AC 161 ms 33684 KB
01-25.txt AC 169 ms 31868 KB
01-26.txt AC 173 ms 32304 KB
01-27.txt AC 142 ms 26768 KB
01-28.txt AC 94 ms 21716 KB
01-29.txt AC 81 ms 19540 KB
01-30.txt AC 81 ms 17748 KB
sample-01.txt AC 74 ms 18516 KB
sample-02.txt AC 72 ms 18388 KB