Submission #7475896


Source Code Expand

using System;

public class Program
{
    private int N, M;
    private int[] X;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        M = sc.NextInt();
        X = sc.IntArray();
        var count = new int[100001];
        var countModM = new int[M];
        foreach (int i in X)
        {
            count[i]++;
            countModM[i % M]++;
        }


        // mod Mでいくつ同じ数字のペアが作れるか
        var countPair = new int[M];

        for (int i = 0; i <= 100000; i++)
        {
            countPair[i % M] += count[i] / 2;
        }

        int ans = 0;

        ans += countModM[0] / 2;
        if (M % 2 == 0)
        {
            ans += countModM[M / 2] / 2;
        }

        for (int i = 1; i * 2 < M; i++)
        {
            int min = Math.Min(countModM[i], countModM[M - i]);
            ans += min;
            countModM[i] -= min;
            countModM[M - i] -= min;
            ans += Math.Min(countPair[i], countModM[i] / 2);
            ans += Math.Min(countPair[M - i], countModM[M - i] / 2);
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Submission Info

Submission Time
Task D - Pair Cards
User mban
Language C# (Mono 4.6.2.0)
Score 700
Code Size 3305 Byte
Status AC
Exec Time 54 ms
Memory 19296 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 21 ms 9184 KB
01-02.txt AC 54 ms 19296 KB
01-03.txt AC 53 ms 15200 KB
01-04.txt AC 53 ms 15200 KB
01-05.txt AC 53 ms 17248 KB
01-06.txt AC 54 ms 19296 KB
01-07.txt AC 53 ms 15200 KB
01-08.txt AC 53 ms 17248 KB
01-09.txt AC 53 ms 15200 KB
01-10.txt AC 53 ms 17504 KB
01-11.txt AC 54 ms 15968 KB
01-12.txt AC 52 ms 15200 KB
01-13.txt AC 52 ms 15584 KB
01-14.txt AC 53 ms 17248 KB
01-15.txt AC 53 ms 17248 KB
01-16.txt AC 53 ms 17248 KB
01-17.txt AC 53 ms 17248 KB
01-18.txt AC 53 ms 17248 KB
01-19.txt AC 53 ms 15328 KB
01-20.txt AC 54 ms 18016 KB
01-21.txt AC 53 ms 15200 KB
01-22.txt AC 53 ms 17248 KB
01-23.txt AC 53 ms 17248 KB
01-24.txt AC 53 ms 17248 KB
01-25.txt AC 53 ms 17504 KB
01-26.txt AC 53 ms 15968 KB
01-27.txt AC 38 ms 12000 KB
01-28.txt AC 23 ms 12256 KB
01-29.txt AC 22 ms 11616 KB
01-30.txt AC 22 ms 10080 KB
sample-01.txt AC 22 ms 11232 KB
sample-02.txt AC 22 ms 9184 KB