Submission #6332522


Source Code Expand

Copy
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

int main() {
    int n,m;
    cin >> n >> m;
    int count[100001] = {};
    rep(i,n){
        int x; cin>>x;
        count[x]++;
    }

    int kisuu[m] = {};
    rep(i,100001){
        if(count[i]%2==1){
            kisuu[i%m]++;
        }
    }

    int ans = 0;

    rep(i,m){
        if(i==0){
            int now = 0;
            int sum = 0;
            while(now*m<100001){
                sum += count[now*m];
                now++;
            }
            ans += sum/2;
        }else if(i*2==m){
            int now = 0;
            int sum = 0;
            while(now*m + i<100001){
                sum += count[now*m+i];
                now++;
            }
            ans += sum/2;
        }else{
            if(m<i*2)break;
            int sum1 = 0;
            int kisuu1 = kisuu[i];
            int now1 = 0; 
            while(now1*m + i<100001){
                sum1 += count[now1*m+i];
                now1++;
            }
            int sum2 = 0;
            int kisuu2 = kisuu[m-i];
            int now2 = 0;
            while(now2*m + (m-i)<100001){
                sum2 += count[now2*m+(m-i)];
                now2++;
            }

            int minikisuu = min(kisuu1,kisuu2);
            ans += minikisuu;
            kisuu1 -= minikisuu;
            kisuu2 -= minikisuu;
            sum1 -= minikisuu;
            sum2 -= minikisuu;
            if(kisuu1>0){
                int mini = min(sum2,kisuu1);
                ans += mini;
                kisuu1 -= mini;
                sum1 -= mini;
                sum2 -= mini;
                sum1 -= kisuu1;
                ans += sum1/2;
                ans += sum2/2;
            }else if(kisuu2>0){
                int mini = min(sum1,kisuu2);
                ans += mini;
                kisuu2 -= mini;
                sum2 -= mini;
                sum1 -= mini;
                sum2 -= kisuu2;
                ans += sum2/2;
                ans += sum1/2;
            }
        }
    }

    cout << ans << endl;
    return 0;
}
 
 

Submission Info

Submission Time
Task D - Pair Cards
User Shibuyap
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2584 Byte
Status
Exec Time 38 ms
Memory 1024 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt
all 0 / 700 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 2 ms 640 KB
01-02.txt 37 ms 640 KB
01-03.txt 36 ms 640 KB
01-04.txt 36 ms 640 KB
01-05.txt 38 ms 640 KB
01-06.txt 37 ms 640 KB
01-07.txt 36 ms 640 KB
01-08.txt 37 ms 640 KB
01-09.txt 37 ms 640 KB
01-10.txt 37 ms 768 KB
01-11.txt 37 ms 1024 KB
01-12.txt 37 ms 640 KB
01-13.txt 37 ms 768 KB
01-14.txt 36 ms 640 KB
01-15.txt 37 ms 640 KB
01-16.txt 36 ms 640 KB
01-17.txt 37 ms 640 KB
01-18.txt 36 ms 640 KB
01-19.txt 37 ms 640 KB
01-20.txt 36 ms 1024 KB
01-21.txt 36 ms 640 KB
01-22.txt 36 ms 640 KB
01-23.txt 36 ms 640 KB
01-24.txt 35 ms 640 KB
01-25.txt 36 ms 768 KB
01-26.txt 37 ms 1024 KB
01-27.txt 19 ms 1024 KB
01-28.txt 3 ms 1024 KB
01-29.txt 2 ms 768 KB
01-30.txt 2 ms 1024 KB
sample-01.txt 1 ms 640 KB
sample-02.txt 2 ms 640 KB