Submission #1609990


Source Code Expand

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    int n, m, tmp, ans = 0;
    cin >> n >> m;
    vector< map<int, int> > a(m);
    vector<int> count(m, 0);
    rep(n){
        cin >> tmp;
        a[tmp%m][tmp]++;
        count[tmp%m]++;
    }

    reppp(i, 1, (m-1)/2){
        int n_i = count[i], n_j = count[m-i];
        if(n_i > n_j){
            swap(a[i], a[m-i]);
            swap(n_i, n_j);
        }

        // 同じ数字のペア
        if(n_j - n_i >= 2)
            for(auto itr = a[m-i].begin(); itr != a[m-i].end(); ++itr){
                int dec_count = min(itr->second, n_j-n_i);
                if(dec_count % 2 == 1) dec_count--;
                if(dec_count > 0){
                    n_j -= dec_count;
                    ans += dec_count/2;
                }
            }
            //cout << ans << " ";
        
        // 合わせてmの倍数
        ans += min(n_i, n_j);
        //cout << ans << endl;
    }

    ans += count[0]/2;
    if(m % 2 == 0) ans += count[m/2]/2;
    
    cout << ans << endl;
}

Submission Info

Submission Time
Task D - Pair Cards
User Noimin
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1763 Byte
Status AC
Exec Time 61 ms
Memory 9984 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 1 ms 256 KB
01-02.txt AC 55 ms 3200 KB
01-03.txt AC 55 ms 3200 KB
01-04.txt AC 55 ms 3200 KB
01-05.txt AC 55 ms 3200 KB
01-06.txt AC 55 ms 3200 KB
01-07.txt AC 54 ms 3200 KB
01-08.txt AC 51 ms 3200 KB
01-09.txt AC 50 ms 3328 KB
01-10.txt AC 42 ms 5248 KB
01-11.txt AC 43 ms 8320 KB
01-12.txt AC 30 ms 256 KB
01-13.txt AC 31 ms 2432 KB
01-14.txt AC 61 ms 4992 KB
01-15.txt AC 60 ms 4992 KB
01-16.txt AC 59 ms 4992 KB
01-17.txt AC 57 ms 4992 KB
01-18.txt AC 51 ms 5120 KB
01-19.txt AC 49 ms 5504 KB
01-20.txt AC 41 ms 9984 KB
01-21.txt AC 38 ms 384 KB
01-22.txt AC 37 ms 384 KB
01-23.txt AC 36 ms 384 KB
01-24.txt AC 33 ms 512 KB
01-25.txt AC 32 ms 1920 KB
01-26.txt AC 33 ms 5504 KB
01-27.txt AC 22 ms 7680 KB
01-28.txt AC 5 ms 5504 KB
01-29.txt AC 3 ms 2304 KB
01-30.txt AC 4 ms 5376 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB