結果

問題 No.433 ICPC国内予選の選抜ルールがこんな感じだったらうれしい
ユーザー kyuridenamidakyuridenamida
提出日時 2016-10-28 19:32:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 421 ms / 4,000 ms
コード長 1,669 bytes
コンパイル時間 1,240 ms
コンパイル使用メモリ 106,692 KB
実行使用メモリ 19,716 KB
最終ジャッジ日時 2023-08-15 20:47:01
合計ジャッジ時間 9,599 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 381 ms
19,540 KB
testcase_01 AC 338 ms
19,716 KB
testcase_02 AC 242 ms
16,060 KB
testcase_03 AC 270 ms
12,528 KB
testcase_04 AC 259 ms
11,632 KB
testcase_05 AC 269 ms
16,976 KB
testcase_06 AC 421 ms
18,772 KB
testcase_07 AC 278 ms
19,632 KB
testcase_08 AC 222 ms
14,748 KB
testcase_09 AC 166 ms
6,816 KB
testcase_10 AC 118 ms
4,908 KB
testcase_11 AC 132 ms
4,476 KB
testcase_12 AC 133 ms
4,932 KB
testcase_13 AC 79 ms
4,720 KB
testcase_14 AC 97 ms
4,656 KB
testcase_15 AC 63 ms
4,376 KB
testcase_16 AC 136 ms
4,572 KB
testcase_17 AC 149 ms
5,004 KB
testcase_18 AC 144 ms
4,912 KB
testcase_19 AC 81 ms
4,620 KB
testcase_20 AC 101 ms
4,632 KB
testcase_21 AC 92 ms
4,704 KB
testcase_22 AC 129 ms
4,508 KB
testcase_23 AC 108 ms
4,724 KB
testcase_24 AC 82 ms
4,560 KB
testcase_25 AC 120 ms
4,568 KB
testcase_26 AC 86 ms
4,396 KB
testcase_27 AC 110 ms
4,428 KB
testcase_28 AC 81 ms
4,776 KB
testcase_29 AC 119 ms
4,584 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 177 ms
5,220 KB
testcase_33 AC 182 ms
4,884 KB
testcase_34 AC 172 ms
8,548 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 10 ms
4,380 KB
testcase_42 AC 9 ms
4,376 KB
testcase_43 AC 9 ms
4,380 KB
testcase_44 AC 9 ms
4,376 KB
testcase_45 AC 4 ms
4,380 KB
testcase_46 AC 29 ms
4,380 KB
testcase_47 AC 28 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
#include <cstdio>
#include <sstream>
#include <set>
#include <cassert>
#include <map>
#include <array>
using namespace std;
typedef unsigned __int128 Hash;



map<int, priority_queue<pair<int,int>>  > g[11];
int N,K;
vector<int> res;

map<int,int> picked_counter; // [univ] = #
priority_queue< array<int,3> > Q;

int get_best_univ(map<int,priority_queue< pair<int,int> > > &score){

	while(Q.size()){
		auto q = Q.top();

		int id = q[2];

		bool bad = false;
		if( score[id].size() == 0 ){
			Q.pop();
			continue;
		}
		if( score[id].top().first != q[1] ) bad = true;
		if( picked_counter[id] != q[0] ) bad = true;

		if( bad ){
			Q.pop();
			//Q.push({picked_counter[id],score[id].top().first,id});
		}else{
			return id;
		}
	}
	return -1;
}
void pick(int id,map<int,priority_queue< pair<int,int> > > &score){
	assert(score[id].size()>0);

	int me = score[id].top().second;
	picked_counter[id]--;
	score[id].pop();
	Q.push({picked_counter[id],score[id].top().first,id});
	res.push_back(me);
	K--;
}


void solve(map<int, priority_queue< pair<int,int> > > &score){
	Q = priority_queue< array<int,3> >();

	for( auto i : score ){
		Q.push({picked_counter[i.first],i.second.top().first,i.first});
	}
	while(K>0){
		int uid = get_best_univ(score);
		if( uid == -1 ) break;
		pick(uid,score);
	}

}
int main(){
	cin >> N >> K;

	set<int> univ;
	for(int i = 0 ; i < N ; i++){
		int S,P,U;
		cin >> S >> P >> U;
		g[S][U].push({-P,i});
		univ.insert(U);
	}

	for(int i = 10 ; i >= 0 ; i--){
		solve(g[i]);
	}
	for(int i = 0 ; i < res.size() ; i++)
		cout << res[i] << endl;

}
0