結果
問題 | No.433 ICPC国内予選の選抜ルールがこんな感じだったらうれしい |
ユーザー |
![]() |
提出日時 | 2016-10-28 19:32:08 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 426 ms / 4,000 ms |
コード長 | 1,669 bytes |
コンパイル時間 | 1,276 ms |
コンパイル使用メモリ | 106,836 KB |
実行使用メモリ | 19,840 KB |
最終ジャッジ日時 | 2024-11-24 05:21:08 |
合計ジャッジ時間 | 9,388 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 48 |
ソースコード
#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; }