CODE FESTIVAL 2016 Final

Submission #994078

Source codeソースコード

/*** Template Begin ***/

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

auto init_ = [] {
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed;
    return 0;
}();

template <typename T>
inline T in() {
    T x;
    std::cin >> x;
    return x;
}

template <typename T>
inline void in(T &x) {
    std::cin >> x;
}

template <typename T, typename... Ts>
inline void in(T &t, Ts &... ts) {
    std::cin >> t;
    in(ts...);
}

template <typename T, typename U = std::vector<T>>
inline U vin(int n) {
    U v(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> v[i];
    }
    return v;
}

template <typename T, typename U = std::vector<T>, typename V = std::vector<U>>
inline V vin(int h, int w) {
    V vv(h, U(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            std::cin >> vv[i][j];
        }
    }
    return vv;
}

template <typename T>
inline void out(const T &x) {
    std::cout << x << std::endl;
}

template <char delimiter = ' ', typename T, typename... Ts>
inline void out(const T &t, const Ts &... ts) {
    std::cout << t << delimiter;
    out(ts...);
}

template <char delimiter = ' ', typename T>
inline void vout(const T &v, int n) {
    for (int i = 0; i < n; ++i) {
        if (i) std::cout << delimiter;
        std::cout << v[i];
    }
    std::cout << std::endl;
}

template <char delimiter = ' ', typename T>
inline void vout(const T &v, int h, int w) {
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (j) std::cout << delimiter;
            std::cout << v[i][j];
        }
        std::cout << std::endl;
    }
}

template <typename T, size_t D>
struct multi_vector_type {
    using type = std::vector<typename multi_vector_type<T, D - 1>::type>;
};

template <typename T>
struct multi_vector_type<T, 1> {
    using type = std::vector<T>;
};

template <typename T>
struct multi_vector_type<T, 0> {
    using type = T;
};

template <typename T, size_t D>
using multi_vector = typename multi_vector_type<T, D>::type;

template <typename T, size_t D, class = typename std::enable_if<D == 0>::type>
T make_vector(const T &val = T()) {
    return val;
}

template <typename T, size_t D = 1, typename... Ts,
          class = typename std::enable_if<D != 0>::type>
multi_vector<T, D> make_vector(size_t n, Ts &&... args) {
    return multi_vector<T, D>(n, make_vector<T, D - 1>(args...));
}

using namespace std;

#define USING_BOOST
#ifdef USING_BOOST

#include <boost/range.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/irange.hpp>

inline auto rep(int begin, int end) {
    if (begin > end) {
        return boost::irange(0, 0);
    } else {
        return boost::irange(begin, end);
    }
}

inline auto rep(int begin, int end, int step) {
    if ((step > 0 && begin > end) || (step < 0 && begin < end)) {
        return boost::irange(0, 0, step);
    } else {
        return boost::irange(begin, end, step);
    }
}

#endif

#define USING_NAMESPACE
#ifdef USING_NAMESPACE
using namespace std;

#ifdef USING_BOOST
using namespace boost;
using namespace boost::adaptors;
#endif
#endif

/*** Template End ***/

int main() {
    int n, m;
    in(n, m);

    auto x = vin<int>(n);
    sort(x.begin(), x.end());

    auto y = x;
    auto c = vector<int>(m);
    auto d = vector<int>(m);

    map<int, int> ma;
    for (int &i : y) {
        ma[i]++;
        i %= m;
        c[i]++;
    }

    for (auto &a : ma) {
        d[a.first % m] += a.second / 2;
    }

    int ans = 0;
    for (int i : rep(0, m)) {
        if (i > m - i) continue;
        if (i == 0) {
            ans += c[0] / 2;
        } else if (i == m - i) {
            ans += c[i] / 2;
        } else {
            if (c[i] == c[m - i]) {
                ans += c[i];
            } else if (c[i] < c[m - i]) {
                int dif = c[m - i] - c[i];
                ans += min(dif / 2, d[m - i]);
                ans += min(c[i], c[m - i]);
            } else if (c[i] > c[m - i]) {
                int dif = c[i] - c[m - i];
                ans += min(dif / 2, d[i]);
                ans += min(c[i], c[m - i]);
            }
        }
    }

    out(ans);
}

Submission

Task問題 D - Pair Cards
User nameユーザ名 runom
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 700
Source lengthソースコード長 4824 Byte
File nameファイル名
Exec time実行時間 45 ms
Memory usageメモリ使用量 6528 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 3 ms 256 KB
01-02.txt AC 36 ms 3968 KB
01-03.txt AC 36 ms 3968 KB
01-04.txt AC 36 ms 3968 KB
01-05.txt AC 36 ms 3968 KB
01-06.txt AC 36 ms 3968 KB
01-07.txt AC 36 ms 3968 KB
01-08.txt AC 36 ms 3968 KB
01-09.txt AC 35 ms 3968 KB
01-10.txt AC 36 ms 4352 KB
01-11.txt AC 38 ms 4736 KB
01-12.txt AC 13 ms 1024 KB
01-13.txt AC 14 ms 1408 KB
01-14.txt AC 45 ms 5760 KB
01-15.txt AC 43 ms 5760 KB
01-16.txt AC 43 ms 5760 KB
01-17.txt AC 44 ms 5760 KB
01-18.txt AC 41 ms 5760 KB
01-19.txt AC 45 ms 5888 KB
01-20.txt AC 44 ms 6528 KB
01-21.txt AC 20 ms 1280 KB
01-22.txt AC 20 ms 1280 KB
01-23.txt AC 20 ms 1280 KB
01-24.txt AC 20 ms 1280 KB
01-25.txt AC 20 ms 1408 KB
01-26.txt AC 21 ms 2048 KB
01-27.txt AC 22 ms 3840 KB
01-28.txt AC 5 ms 1280 KB
01-29.txt AC 3 ms 640 KB
01-30.txt AC 4 ms 1024 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB