CODE FESTIVAL 2016 Final

Submission #992609

Source codeソースコード

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n, m;
	cin>>n>>m;
	vi x(n);
	map<int,int> mp;
	rep(i, n){
		cin>>x[i];
		mp[x[i]]++;
	}
	vi v(1e5+10), p(1e5+10);
	for(auto i : mp){
		v[i.fi%m]+= i.se;
		p[i.fi] = i.se / 2;
	}
	// rep(i, 10){
	// 	cout<<" "<<i<<" "<<v[i]<<endl;
	// }
	int ans = 0;
	for(int i = 1; i < m / 2; i++){
		int k = min(v[i], v[m-i]);
		//cout<<"  "<<i<<"  "<<k<<endl;
		ans += k;
		v[i] -= k;
		v[m-i] -= k;
	}
	if(m % 2 == 0){
		ans += v[m/2]/2;
		v[m/2] = 0;
	}
	else{
		int k = min(v[m/2], v[m-m/2]);
		ans += k;
		v[m/2] -= k;
		v[m-m/2] -= k;
	}
	ans += v[0]/2;
	v[0] = 0;
	rep(i, 1e5 + 10){
		if(p[i] > 0 && v[i % m] >= 2){
			int k = min(p[i], v[i % m] / 2);
			ans += k;
			v[i % m] -= k * 2;
		}
	}
	cout<<ans<<endl;
}

Submission

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

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 3 ms 1024 KB
01-02.txt AC 62 ms 4352 KB
01-03.txt AC 63 ms 4352 KB
01-04.txt AC 62 ms 4352 KB
01-05.txt AC 62 ms 4352 KB
01-06.txt AC 62 ms 4352 KB
01-07.txt AC 62 ms 4352 KB
01-08.txt AC 63 ms 4352 KB
01-09.txt AC 62 ms 4352 KB
01-10.txt AC 62 ms 4352 KB
01-11.txt AC 62 ms 4352 KB
01-12.txt AC 32 ms 1408 KB
01-13.txt AC 31 ms 1408 KB
01-14.txt AC 70 ms 6144 KB
01-15.txt AC 70 ms 6144 KB
01-16.txt AC 73 ms 6144 KB
01-17.txt AC 70 ms 6144 KB
01-18.txt AC 71 ms 6144 KB
01-19.txt AC 70 ms 6144 KB
01-20.txt AC 70 ms 6144 KB
01-21.txt AC 41 ms 1536 KB
01-22.txt AC 41 ms 1536 KB
01-23.txt AC 41 ms 1536 KB
01-24.txt AC 41 ms 1536 KB
01-25.txt AC 41 ms 1536 KB
01-26.txt AC 41 ms 1536 KB
01-27.txt AC 35 ms 3584 KB
01-28.txt AC 5 ms 1152 KB
01-29.txt AC 4 ms 1024 KB
01-30.txt AC 4 ms 1024 KB
sample-01.txt AC 4 ms 1024 KB
sample-02.txt AC 4 ms 1024 KB