CODE FESTIVAL 2016 Final

Submission #993453

Source codeソースコード

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")

template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;

#define N 100010
int n, m;
int ans;
map<pii,int> res;
map<int,int> raw, raw_cpy,
             mod, mod_cpy,
             par;

int main() {
    sf("%d%d", &n, &m);
    rep(i, 1, n) {
        int k;
        sf("%d", &k);
        raw[k]++;
        raw_cpy[k]++;
    }

    /// 凑相同的对子
    irep(it, raw_cpy) {
        if (it -> y >= 2) {
            int add = (it -> y) / 2;
            int rem = (it -> y) % 2;
            int mm = (it -> x) % m;
            par[mm] += add;
//            par_cpy[mm] += add;
            raw[it -> x] = rem;
//            pf("raw[%d] = %d\n", it->x, rem);
            ans += add;
        }
    }

    ///剩下的单个的数,对m取模,再相互配对
    irep(it, raw) {
        int ind = (it -> x) % m;
        int amt = (it -> y);
        if (amt > 0) {
            mod[ind] += amt;
            mod_cpy[ind] += amt;
        }
    }

    irep(it, mod_cpy) {
        int p = it -> x;
        int q = m - p;
//        pf("mod[%d] = %d\n", p, it->y);

        if (p == 0) {
            ans += mod[0] / 2;
            mod[0] %= 2;
            continue;
        }
        if (p == q) {
            ans += mod[p] / 2;
            mod[p] %= 2;
            break;
        }
        if (p > q) break;

        int add = min(mod[p], mod[q]);
        mod[p] -= add;
        mod[q] -= add;
        ans += add;
    }

    ///最后剩下的单个的数,考虑拆对子
    irep(it, mod) {
        int p = it -> x;
        int q = m - p;
        if (par.find(q) != par.end()) {
            int parq = par[q];
            int add = min(parq * 2, it -> y);
            ans += add / 2;
        }
    }

    pf("%d\n", ans);
    return 0;
}

Submission

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

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:58:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d%d", &n, &m);
^
./Main.cpp:61:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", &k);
^

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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 2 ms 256 KB
01-02.txt AC 70 ms 6144 KB
01-03.txt AC 71 ms 6144 KB
01-04.txt AC 71 ms 6144 KB
01-05.txt AC 72 ms 6144 KB
01-06.txt AC 72 ms 6272 KB
01-07.txt AC 72 ms 6144 KB
01-08.txt AC 77 ms 6272 KB
01-09.txt AC 79 ms 6400 KB
01-10.txt AC 98 ms 10240 KB
01-11.txt AC 112 ms 12032 KB
01-12.txt AC 12 ms 256 KB
01-13.txt AC 12 ms 256 KB
01-14.txt AC 82 ms 9600 KB
01-15.txt AC 83 ms 9600 KB
01-16.txt AC 86 ms 9600 KB
01-17.txt AC 92 ms 9728 KB
01-18.txt AC 94 ms 9856 KB
01-19.txt AC 99 ms 10752 KB
01-20.txt AC 173 ms 19072 KB
01-21.txt AC 31 ms 640 KB
01-22.txt AC 31 ms 640 KB
01-23.txt AC 31 ms 640 KB
01-24.txt AC 32 ms 768 KB
01-25.txt AC 33 ms 1024 KB
01-26.txt AC 32 ms 1152 KB
01-27.txt AC 97 ms 12032 KB
01-28.txt AC 6 ms 896 KB
01-29.txt AC 3 ms 384 KB
01-30.txt AC 2 ms 256 KB
sample-01.txt AC 2 ms 256 KB
sample-02.txt AC 2 ms 256 KB