CODE FESTIVAL 2016 Final

Submission #6428047

Source codeソースコード

#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcount((unsigned int)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    vvl m(M);
    rep(i, N){
        ll x; cin >> x;
        m[x%M].pb(x);
    }
    
    ll ans = m[0].size()/2;
    FOR(i, 1, M/2+1){
        auto p1 = m[i];
        auto p2 = m[M-i];
        if(p1.size() > p2.size()) swap(p1, p2);
        if(i == M/2 && M%2 == 0){
            ans += p2.size()/2;
        }
        else
        {
            ans += p1.size();
            sort(p2.begin(), p2.end());
            ll cnt = 0;
            ll l = 0;
            while(l < p2.size()){
                ll r = l;
                while(r < p2.size() && p2[r] == p2[l]) r++;
                ll c = r-l;
                cnt += c/2;
                l = r;
            }
            ans += min((ll)(p2.size()-p1.size())/2, cnt);
        }
    }
    
    cout << ans << endstr;
    return 0;
}

Submission

Task問題 D - Pair Cards
User nameユーザ名 k_k_hiroki
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 700
Source lengthソースコード長 3204 Byte
File nameファイル名
Exec time実行時間 22 ms
Memory usageメモリ使用量 5760 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 11 ms 1400 KB
01-03.txt AC 11 ms 2012 KB
01-04.txt AC 13 ms 1584 KB
01-05.txt AC 12 ms 1600 KB
01-06.txt AC 13 ms 1536 KB
01-07.txt AC 13 ms 1152 KB
01-08.txt AC 13 ms 1536 KB
01-09.txt AC 14 ms 1536 KB
01-10.txt AC 20 ms 2944 KB
01-11.txt AC 22 ms 4736 KB
01-12.txt AC 12 ms 1908 KB
01-13.txt AC 13 ms 2932 KB
01-14.txt AC 11 ms 2012 KB
01-15.txt AC 13 ms 1648 KB
01-16.txt AC 13 ms 1664 KB
01-17.txt AC 13 ms 1280 KB
01-18.txt AC 15 ms 2048 KB
01-19.txt AC 17 ms 1792 KB
01-20.txt AC 22 ms 5760 KB
01-21.txt AC 11 ms 1992 KB
01-22.txt AC 12 ms 1536 KB
01-23.txt AC 12 ms 1408 KB
01-24.txt AC 13 ms 1536 KB
01-25.txt AC 15 ms 2304 KB
01-26.txt AC 17 ms 3968 KB
01-27.txt AC 12 ms 4224 KB
01-28.txt AC 3 ms 2688 KB
01-29.txt AC 2 ms 1152 KB
01-30.txt AC 3 ms 2560 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB