Submission #991979


Source Code Expand

Copy
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int A[100050];
vector<int> X[100050];

int calc(int a, int b) {
  if (X[a].size() > X[b].size()) {
    swap(a, b);
  }
  int res = X[a].size();
  int rem = X[b].size() - X[a].size();
  int pr = 0;
  for (int i = 0; i + 1 < X[b].size(); ++i) {
    if (X[b][i] == X[b][i + 1]) {
      ++pr;
      ++i;
    }
  }
  return res + min(rem, pr);
}

int main() {
  int N = in();
  int M = in();

  for (int i = 0; i < N; ++i) {
    A[i] = in();
    X[A[i] % M].push_back(A[i]);
  }

  int res = 0;
  for (int i = 0; i <= M - i; ++i) {
    int j = (M - i) % M;
    if (i == j) {
      res += X[i].size() / 2;
    } else {
      sort(X[i].begin(), X[i].end());
      sort(X[j].begin(), X[j].end());
      res += calc(i, j);
    }
  }

  printf("%d\n", res);

  return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User japlj
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1765 Byte
Status
Exec Time 26 ms
Memory 6144 KB

Compile Error

./Main.cpp: In function ‘int in()’:
./Main.cpp:34:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 int in() { int x; scanf("%d", &x); return x; }
                                  ^
./Main.cpp: In function ‘double fin()’:
./Main.cpp:35:42: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 double fin() { double x; scanf("%lf", &x); return x; }
                                          ^
./Main.cpp: In function ‘Int lin()’:
./Main.cpp:36:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 Int lin() { Int x; scanf("%lld", &x); return x; }
                                     ^

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt
all 0 / 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
Case Name Status Exec Time Memory
01-01.txt 5 ms 2560 KB
01-02.txt 16 ms 3452 KB
01-03.txt 16 ms 3580 KB
01-04.txt 20 ms 3584 KB
01-05.txt 18 ms 3456 KB
01-06.txt 20 ms 3712 KB
01-07.txt 20 ms 3456 KB
01-08.txt 20 ms 3584 KB
01-09.txt 20 ms 3584 KB
01-10.txt 25 ms 4224 KB
01-11.txt 26 ms 4992 KB
01-12.txt 17 ms 3452 KB
01-13.txt 17 ms 3452 KB
01-14.txt 16 ms 3472 KB
01-15.txt 20 ms 3584 KB
01-16.txt 20 ms 3712 KB
01-17.txt 19 ms 3456 KB
01-18.txt 21 ms 3840 KB
01-19.txt 23 ms 3712 KB
01-20.txt 25 ms 6144 KB
01-21.txt 16 ms 3520 KB
01-22.txt 19 ms 3456 KB
01-23.txt 19 ms 3584 KB
01-24.txt 19 ms 3584 KB
01-25.txt 20 ms 3712 KB
01-26.txt 21 ms 3712 KB
01-27.txt 15 ms 4352 KB
01-28.txt 6 ms 2688 KB
01-29.txt 5 ms 2560 KB
01-30.txt 5 ms 2560 KB
sample-01.txt 5 ms 2560 KB
sample-02.txt 5 ms 2560 KB