Submission #5570029


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))


int main()
{
    lint N;
    cin >> N;
    lint M;
    cin >> M;
    vector<lint> X(N);
    cin >> X;

    vector<int> cou(M), pa(M);
    vector<set<int>> odd(M);
    for (auto x : X)
    {
        int m = x % M;
        cou[m]++;
        if (odd[m].count(x))
        {
            pa[m]++;
            odd[m].erase(x);
        }
        else odd[m].insert(x);
    }

    lint ret = cou[0] / 2;
    FOR(i, 1, M / 2 + 1)
    {
        if (i * 2 == M)
        {
            ret += cou[i] / 2;
        }
        else
        {
            int j = M - i;
            if (cou[i] < cou[j]) ret += cou[i] + min((cou[j] - cou[i]) / 2, pa[j]);
            else ret += cou[j] + min((cou[i] - cou[j]) / 2, pa[i]);
        }
    }
    cout << ret << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User hitonanode
Language C++14 (GCC 5.4.1)
Score 700
Code Size 3794 Byte
Status AC
Exec Time 46 ms
Memory 11264 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 34
Set Name Test Cases
sample sample-01.txt, sample-02.txt
all 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
Case Name Status Exec Time Memory
01-01.txt AC 1 ms 256 KB
01-02.txt AC 43 ms 3072 KB
01-03.txt AC 42 ms 3072 KB
01-04.txt AC 41 ms 3072 KB
01-05.txt AC 41 ms 3072 KB
01-06.txt AC 39 ms 3072 KB
01-07.txt AC 38 ms 3072 KB
01-08.txt AC 31 ms 3072 KB
01-09.txt AC 28 ms 3200 KB
01-10.txt AC 20 ms 5248 KB
01-11.txt AC 19 ms 8576 KB
01-12.txt AC 12 ms 1024 KB
01-13.txt AC 13 ms 3456 KB
01-14.txt AC 46 ms 5760 KB
01-15.txt AC 45 ms 5760 KB
01-16.txt AC 42 ms 5760 KB
01-17.txt AC 37 ms 5760 KB
01-18.txt AC 31 ms 5888 KB
01-19.txt AC 31 ms 6400 KB
01-20.txt AC 21 ms 11264 KB
01-21.txt AC 27 ms 1152 KB
01-22.txt AC 25 ms 1152 KB
01-23.txt AC 21 ms 1152 KB
01-24.txt AC 16 ms 1152 KB
01-25.txt AC 15 ms 2816 KB
01-26.txt AC 16 ms 6656 KB
01-27.txt AC 12 ms 8448 KB
01-28.txt AC 4 ms 5888 KB
01-29.txt AC 2 ms 2432 KB
01-30.txt AC 3 ms 5760 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB