CODE FESTIVAL 2016 Final

Submission #1889848

Source codeソースコード

#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) {
	int pair = little.size();
	int bigPair = 0;
	int maxBigPair = (big.size() - little.size()) / 2;

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

	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 += kind[0].size() / 2;
	if (M % 2 == 0)ans += kind[M / 2].size() / 2;
}

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

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

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

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

	return 0;
}

Submission

Task問題 D - Pair Cards
User nameユーザ名 toa2525
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1975 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
sample - 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,sample-01.txt,sample-02.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 1 ms 256 KB
01-02.txt AC 30 ms 892 KB
01-03.txt AC 29 ms 892 KB
01-04.txt AC 32 ms 1016 KB
01-05.txt AC 31 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 33 ms 896 KB
01-10.txt WA
01-11.txt WA
01-12.txt WA
01-13.txt WA
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 36 ms 1276 KB
01-20.txt AC 43 ms 5872 KB
01-21.txt AC 30 ms 768 KB
01-22.txt AC 31 ms 768 KB
01-23.txt AC 31 ms 896 KB
01-24.txt WA
01-25.txt WA
01-26.txt WA
01-27.txt AC 23 ms 4208 KB
01-28.txt WA
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