CODE FESTIVAL 2016 Final

Submission #991983

Source codeソースコード

#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M, X[101010];
vector<int> S[101010];

pair<int, int> trans(vector<int> &V)
{
	sort(V.begin(), V.end());

	int evepair = 0, odds = 0;

	int con = 0;
	for (int i = 0; i < V.size(); ++i) {
		++con;
		if (i == V.size() - 1 || V[i] != V[i + 1]) {
			evepair += con / 2;
			odds += con % 2;
			con = 0;
		}
	}
	return{ evepair, odds };
}

int solve(vector<int> &A, vector<int> &B)
{
	auto p = trans(A);
	auto q = trans(B);

	int ret = 0;
	ret += min(p.second, q.second);
	p.second -= ret;
	q.second -= ret;
	if (p.second == 0) swap(p, q);

	int oddp = min(p.second, q.first * 2);
	return ret + oddp + p.first + (q.first * 2 - oddp) / 2;
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) {
		scanf("%d", X + i);

		S[X[i] % M].push_back(X[i]);
	}

	int ret = 0;
	for (int i = 0; i < M; ++i) {
		int comp = (M - i) % M;
		if (i <= comp) {
			if (i == comp) ret += S[i].size() / 2;
			else ret += solve(S[i], S[comp]);
		}
	}
	printf("%d\n", ret);
	return 0;
}

Submission

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

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:58:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &M);
^
./Main.cpp:60:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", X + i);
^

Test case

Set

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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 5 ms 2560 KB
01-02.txt AC 16 ms 3576 KB
01-03.txt AC 16 ms 3580 KB
01-04.txt AC 20 ms 3584 KB
01-05.txt AC 19 ms 3712 KB
01-06.txt AC 21 ms 3712 KB
01-07.txt AC 20 ms 3456 KB
01-08.txt AC 20 ms 3584 KB
01-09.txt AC 21 ms 3584 KB
01-10.txt AC 25 ms 4224 KB
01-11.txt AC 28 ms 5120 KB
01-12.txt AC 17 ms 3576 KB
01-13.txt AC 18 ms 3576 KB
01-14.txt AC 16 ms 3472 KB
01-15.txt AC 20 ms 3712 KB
01-16.txt AC 20 ms 3712 KB
01-17.txt AC 19 ms 3584 KB
01-18.txt AC 22 ms 3840 KB
01-19.txt AC 23 ms 3712 KB
01-20.txt AC 26 ms 6144 KB
01-21.txt AC 16 ms 3520 KB
01-22.txt AC 19 ms 3456 KB
01-23.txt AC 19 ms 3584 KB
01-24.txt AC 19 ms 3584 KB
01-25.txt AC 20 ms 3712 KB
01-26.txt AC 21 ms 3712 KB
01-27.txt AC 15 ms 4352 KB
01-28.txt AC 7 ms 2688 KB
01-29.txt AC 5 ms 2688 KB
01-30.txt AC 6 ms 2560 KB
sample-01.txt AC 5 ms 2560 KB
sample-02.txt AC 5 ms 2560 KB