CODE FESTIVAL 2016 Final

Submission #6332522

Source codeソースコード

#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

Task問題 D - Pair Cards
User nameユーザ名 Shibuyap
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2584 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
sample - 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 2 ms 640 KB
01-02.txt AC 37 ms 640 KB
01-03.txt AC 36 ms 640 KB
01-04.txt AC 36 ms 640 KB
01-05.txt AC 38 ms 640 KB
01-06.txt AC 37 ms 640 KB
01-07.txt AC 36 ms 640 KB
01-08.txt WA
01-09.txt WA
01-10.txt WA
01-11.txt WA
01-12.txt AC 37 ms 640 KB
01-13.txt WA
01-14.txt AC 36 ms 640 KB
01-15.txt AC 37 ms 640 KB
01-16.txt AC 36 ms 640 KB
01-17.txt AC 37 ms 640 KB
01-18.txt AC 36 ms 640 KB
01-19.txt AC 37 ms 640 KB
01-20.txt AC 36 ms 1024 KB
01-21.txt AC 36 ms 640 KB
01-22.txt AC 36 ms 640 KB
01-23.txt AC 36 ms 640 KB
01-24.txt WA
01-25.txt WA
01-26.txt WA
01-27.txt AC 19 ms 1024 KB
01-28.txt WA
01-29.txt AC 2 ms 768 KB
01-30.txt AC 2 ms 1024 KB
sample-01.txt AC 1 ms 640 KB
sample-02.txt AC 2 ms 640 KB