CODE FESTIVAL 2016 Final

Submission #5430972

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    map<int,int> mp;
    VI x(n);
    map<int,int> tmp;
    map<int,int> pairCnt;
    rep(i,n){
      cin >> x[i];
      if(tmp[x[i]] > 0){
        tmp[x[i]]--;
        pairCnt[x[i]%m]++;
      }else {
        tmp[x[i]]++;
      }
      mp[x[i] % m]++;
    }


    ll ans = 0;
    rep(i,m){
      int x;
      if(i != (m-i)%m) x = min(mp[i] , mp[(m-i)%m]);
      else x = mp[i]/2;
      mp[i] -= x;
      mp[(m-i)%m] -= x;
      ans += x;
    }

    //cout << "ans" << ' ' << ans << "\n";
    rep(i,m){
      //cout << i << ':' << pairCnt[i] << "\n";
      if(pairCnt[i] > 0 && mp[i] > 0){
        ans += min(mp[i]/2,pairCnt[i]);
      }
    }

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

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
all 700 / 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 1 ms 256 KB
01-02.txt AC 45 ms 3584 KB
01-03.txt AC 46 ms 3584 KB
01-04.txt AC 48 ms 3584 KB
01-05.txt AC 46 ms 3584 KB
01-06.txt AC 48 ms 3584 KB
01-07.txt AC 48 ms 3584 KB
01-08.txt AC 56 ms 3712 KB
01-09.txt AC 63 ms 3840 KB
01-10.txt AC 103 ms 7424 KB
01-11.txt AC 140 ms 13056 KB
01-12.txt AC 10 ms 640 KB
01-13.txt AC 37 ms 4736 KB
01-14.txt AC 52 ms 5504 KB
01-15.txt AC 53 ms 5376 KB
01-16.txt AC 55 ms 5376 KB
01-17.txt AC 59 ms 5376 KB
01-18.txt AC 66 ms 5632 KB
01-19.txt AC 77 ms 6528 KB
01-20.txt AC 133 ms 14720 KB
01-21.txt AC 26 ms 896 KB
01-22.txt AC 27 ms 896 KB
01-23.txt AC 29 ms 896 KB
01-24.txt AC 39 ms 896 KB
01-25.txt AC 60 ms 3712 KB
01-26.txt AC 97 ms 10240 KB
01-27.txt AC 104 ms 12160 KB
01-28.txt AC 55 ms 9856 KB
01-29.txt AC 21 ms 3968 KB
01-30.txt AC 62 ms 9600 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB