結果

問題 No.200 カードファイト!
ユーザー koyumeishikoyumeishi
提出日時 2015-06-01 23:57:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,485 bytes
コンパイル時間 1,106 ms
コンパイル使用メモリ 85,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 09:05:26
合計ジャッジ時間 1,976 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;


int main(){
	int n;
	cin >> n;
	int x;
	cin >> x;
	vector<int> a(x);
	for(int i=0; i<x; i++){cin>>a[i];}
	sort(a.begin(), a.end());

	int y;
	cin >> y;
	vector<int> b(y);
	for(int i=0; i<y; i++){cin>>b[i];}
	sort(b.begin(), b.end());


	int ans = 0;
	set<int> a_(a.begin(), a.end());
	set<int> b_(b.begin(), b.end());

	vector<int> a_cnt(200, 0);
	vector<int> b_cnt(200, 0);
	for(int i=0; i<x; i++) a_cnt[a[i]]++;
	for(int i=0; i<y; i++) b_cnt[b[i]]++;

	auto erase = [&](set<int>& s, vector<int>& cnt, set<int>::iterator itr){
		cnt[*itr]--;
		if(cnt[*itr] == 0){
			s.erase(itr);
		}
	};

	for(int i=0; i<n; i++){
		bool update = false;
		for(auto b_itr = --b_.end(); !update; b_itr--){
			auto itr = a_.lower_bound(*b_itr + 1);
			if(itr != a_.end()){
				//cerr << *itr << " " << *b_itr << endl;
				erase(a_, a_cnt, itr);
				erase(b_, b_cnt, b_itr);
				ans++;
				update = true;
				break;
			}
			if(b_itr == b_.begin()) break;
		}
		if(!update){
			auto itr = a_.begin();
			erase(a_, a_cnt, itr);
			erase(b_, b_cnt, --(b_.end()));
		}

		if(a_.size() == 0){
			for(int j=0; j<x; j++){
				a_.insert(a[j]);
				a_cnt[a[j]]++;
			}
		}
		if(b_.size() == 0){	
			for(int j=0; j<y; j++){
				b_.insert(b[j]);
				b_cnt[b[j]]++;	
			}
		}
	}

	cout << ans << endl;

	return 0;
}
0