Submission #995450


Source Code Expand

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
typedef vector<vector<char> > vvc;
typedef vector<double> vd;
typedef vector<vector<double> > vvd;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;
typedef deque<bool> db;
typedef deque<deque<bool> > ddb;

int main() {
  int n, m;
  cin >> n >> m;
  vi x(n);
  vvi group(m);
  vi eachnum(100005, 0);
  rep (i, n) {
    cin >> x[i];
    group[x[i] % m].eb(x[i]);
    eachnum[x[i]] += 1;
  }
  rep (i, m) {
    sort(all(group[i]));
  }
  vi pairnum(m, 0);
  rep (i, 100005) {
    if (eachnum[i] >= 2) {
      pairnum[i % m] += eachnum[i] / 2;
    }
  }

  int ans = 0;
  ans += (int)group[0].size() / 2;
  if (m % 2 == 0) {
    ans += (int)group[m/2].size() / 2;
  }
  FOR (i, 1, (m-1)/2 + 1) {
    int j = m - i;
    int is, js;
    is = group[i].size();
    js = group[j].size();
    ans += min(is, js);
    int maxi;
    int diff;
    if (is == js) {
      continue;
    } else if (is > js) {
      maxi = i;
      diff = is - js;
    } else {
      maxi = j;
      diff = js - is;
    }
    ans += min(pairnum[maxi], diff/2);
  }
  printf("%d\n", ans);

  return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User tspcx
Language C++14 (Clang 3.8.0)
Score 700
Code Size 2103 Byte
Status AC
Exec Time 102 ms
Memory 6912 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 32
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
Case Name Status Exec Time Memory
01-01.txt AC 8 ms 1272 KB
01-02.txt AC 89 ms 1660 KB
01-03.txt AC 88 ms 1660 KB
01-04.txt AC 89 ms 1664 KB
01-05.txt AC 89 ms 1536 KB
01-06.txt AC 88 ms 1792 KB
01-07.txt AC 87 ms 1536 KB
01-08.txt AC 88 ms 1664 KB
01-09.txt AC 88 ms 1664 KB
01-10.txt AC 95 ms 3328 KB
01-11.txt AC 102 ms 5760 KB
01-12.txt AC 80 ms 1660 KB
01-13.txt AC 82 ms 2684 KB
01-14.txt AC 88 ms 1560 KB
01-15.txt AC 88 ms 1664 KB
01-16.txt AC 88 ms 1792 KB
01-17.txt AC 86 ms 1536 KB
01-18.txt AC 88 ms 2048 KB
01-19.txt AC 91 ms 2176 KB
01-20.txt AC 101 ms 6912 KB
01-21.txt AC 87 ms 1664 KB
01-22.txt AC 87 ms 1536 KB
01-23.txt AC 87 ms 1664 KB
01-24.txt AC 85 ms 1664 KB
01-25.txt AC 88 ms 2560 KB
01-26.txt AC 91 ms 4480 KB
01-27.txt AC 52 ms 5120 KB
01-28.txt AC 10 ms 3456 KB
01-29.txt AC 5 ms 1792 KB
01-30.txt AC 7 ms 3328 KB
sample-01.txt AC 3 ms 640 KB
sample-02.txt AC 3 ms 640 KB