CODE FESTIVAL 2016 Final

Submission #1102225

Source codeソースコード

#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

vector<int> x[MAX_N];
int a[MAX_N]; //いくつあるか
int b[MAX_N]; //vectorごとに値を保持

int main()
{
	int n,m,buff,ans=0;
	cin >> n >> m;
	fill(a,a+n,0);
	fill(b,b+n,0);
	rep(i,n){
		scanf("%d",&buff);
		a[buff]++;
		x[buff%m].push_back(buff); 
	}
	for(int i=1;i<=100000;i++){
		int pair = a[i]/2;
		b[i%m] += pair;
	}
	int hoge;
	ans+=x[0].size()/2;
	if(m%2==0){
		ans += x[m/2].size()/2;
		for(int i=1;i<m/2;i++){
			if(x[i].size()>x[m-i].size()){
				hoge = x[i].size()-x[m-i].size();
				ans += (x[m-i].size() + min(hoge/2,b[i]));
			}else if(x[i].size()==x[m-i].size()){
				ans += x[i].size();
			}else{
				hoge = x[m-i].size()-x[i].size();
				ans += (x[i].size() + min(hoge/2,b[m-i]));
			}
		}
	}else{
		for(int i=1;i<=(m-1)/2;i++){
			if(x[i].size()>x[m-i].size()){
				hoge = x[i].size()-x[m-i].size();
				ans += (x[m-i].size() + min(hoge/2,b[i]));
			}else if(x[i].size()==x[m-i].size()){
				ans += x[i].size();
			}else{
				hoge = x[m-i].size()-x[i].size();
				ans += (x[i].size() + min(hoge/2,b[m-i]));
			}
		}
	}
	cout << ans << "\n";
}

Submission

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

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

./Main.cpp: In function ‘int main()’:
./Main.cpp:24:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&buff);
^

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 6 ms 2560 KB
01-02.txt AC 20 ms 3964 KB
01-03.txt AC 18 ms 3964 KB
01-04.txt AC 17 ms 3968 KB
01-05.txt AC 17 ms 3968 KB
01-06.txt AC 18 ms 4096 KB
01-07.txt AC 17 ms 3840 KB
01-08.txt AC 19 ms 3968 KB
01-09.txt AC 20 ms 3968 KB
01-10.txt AC 25 ms 4608 KB
01-11.txt AC 26 ms 5376 KB
01-12.txt AC 17 ms 3964 KB
01-13.txt AC 17 ms 3964 KB
01-14.txt AC 18 ms 3860 KB
01-15.txt AC 17 ms 3968 KB
01-16.txt AC 18 ms 4096 KB
01-17.txt AC 18 ms 3840 KB
01-18.txt AC 21 ms 4224 KB
01-19.txt AC 22 ms 4096 KB
01-20.txt AC 26 ms 6528 KB
01-21.txt AC 18 ms 3968 KB
01-22.txt AC 17 ms 3840 KB
01-23.txt AC 17 ms 3968 KB
01-24.txt AC 19 ms 3968 KB
01-25.txt AC 21 ms 4096 KB
01-26.txt AC 22 ms 4096 KB
01-27.txt AC 16 ms 4736 KB
01-28.txt AC 7 ms 3456 KB
01-29.txt AC 6 ms 3200 KB
01-30.txt AC 6 ms 3072 KB
sample-01.txt AC 6 ms 2560 KB
sample-02.txt AC 6 ms 2560 KB