Submission #7475894


Source Code Expand

using System;
using System.Net.Http.Headers;

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 0
Code Size 3337 Byte
Status CE

Compile Error

./Main.cs(2,18): error CS0234: The type or namespace name `Http' does not exist in the namespace `System.Net'. Are you missing `System.Net.Http' assembly reference?