Submission #1889853


Source Code Expand

#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
const int INF = (1 << 30);

//毎回変える定数
#define N_MAX 200


//問題文のとおりの変数
int N, M;
//vector<int> X;

//オリジナル変数
vector<vector<int>> kind;//種類分け(第1-indexがmod M)
int ans = 0;

//サブ関数
//入力
void input() {
	cin >> N >> M;
	REP(i, M)kind.push_back(vector<int>());

	REP(i, N) {
		int tmp;
		cin >> tmp;
		kind[tmp%M].push_back(tmp);
	}
}

//計算
int matching(vector<int> little, vector<int> big) {
	if (little.size() > big.size()) {
		vector<int> tmp = little;
		little = big;
		big = tmp;
	}
	int pair = little.size();
	int bigPair = 0;
	int maxBigPair = (big.size() - little.size()) / 2;

	sort(big.begin(), big.end());
	REP(i, (int)big.size() - 1) {
		if (big[i] == big[i+1]) {
			bigPair++;
			i++;
		}
	}

	return pair + min(maxBigPair, bigPair);
}

void calc() {
	int small = 1;
	int large;
	while (small < (large = M - small)) {
		if (kind[small].size() < kind[large].size()) {
			ans += matching(kind[small], kind[large]);
		}
		else {
			ans += matching(kind[large], kind[small]);
		}
		small++;
	}

	//例外処理
	ans += (int)kind[0].size() / 2;
	if (M % 2 == 0)ans += (int)kind[M / 2].size() / 2;
}

//出力
void output() {
	cout << ans << endl;
}

//デバッグ
void debug() {
	cin >> N;
}

//メイン関数
int main() {

	input();
	calc();
	output();
	//debug();

	return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User toma25
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2025 Byte
Status AC
Exec Time 44 ms
Memory 5744 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 29 ms 892 KB
01-03.txt AC 29 ms 892 KB
01-04.txt AC 32 ms 1016 KB
01-05.txt AC 32 ms 1024 KB
01-06.txt AC 32 ms 896 KB
01-07.txt AC 32 ms 768 KB
01-08.txt AC 32 ms 896 KB
01-09.txt AC 32 ms 896 KB
01-10.txt AC 40 ms 2420 KB
01-11.txt AC 44 ms 4592 KB
01-12.txt AC 31 ms 1148 KB
01-13.txt AC 32 ms 2164 KB
01-14.txt AC 29 ms 788 KB
01-15.txt AC 32 ms 996 KB
01-16.txt AC 32 ms 1024 KB
01-17.txt AC 32 ms 768 KB
01-18.txt AC 33 ms 1152 KB
01-19.txt AC 35 ms 1276 KB
01-20.txt AC 43 ms 5744 KB
01-21.txt AC 29 ms 832 KB
01-22.txt AC 31 ms 768 KB
01-23.txt AC 33 ms 896 KB
01-24.txt AC 32 ms 896 KB
01-25.txt AC 34 ms 1656 KB
01-26.txt AC 37 ms 3444 KB
01-27.txt AC 23 ms 4596 KB
01-28.txt AC 6 ms 3444 KB
01-29.txt AC 3 ms 1912 KB
01-30.txt AC 5 ms 3444 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB