結果

問題 No.2804 Fixer And Ratism
ユーザー silv723silv723
提出日時 2024-07-05 10:53:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 2,780 ms
コンパイル使用メモリ 237,328 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-11 23:11:24
合計ジャッジ時間 6,552 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 43 ms
6,940 KB
testcase_04 AC 27 ms
6,944 KB
testcase_05 AC 11 ms
6,944 KB
testcase_06 AC 75 ms
6,944 KB
testcase_07 AC 25 ms
6,944 KB
testcase_08 AC 26 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 21 ms
6,940 KB
testcase_11 AC 76 ms
6,944 KB
testcase_12 AC 61 ms
6,940 KB
testcase_13 AC 16 ms
6,944 KB
testcase_14 AC 59 ms
6,940 KB
testcase_15 AC 7 ms
6,940 KB
testcase_16 AC 63 ms
6,944 KB
testcase_17 AC 24 ms
6,940 KB
testcase_18 AC 102 ms
6,940 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 9 ms
6,940 KB
testcase_21 AC 97 ms
6,940 KB
testcase_22 AC 5 ms
6,940 KB
testcase_23 AC 153 ms
6,940 KB
testcase_24 AC 143 ms
6,944 KB
testcase_25 AC 150 ms
6,944 KB
testcase_26 AC 149 ms
6,944 KB
testcase_27 AC 147 ms
6,940 KB
testcase_28 AC 153 ms
6,940 KB
testcase_29 AC 145 ms
6,940 KB
testcase_30 AC 146 ms
6,940 KB
testcase_31 AC 140 ms
6,944 KB
testcase_32 AC 148 ms
6,940 KB
testcase_33 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
bool isok(string &s){
	for(auto c:s){
		if('a' > c || 'z' < c) return false;
	}
	return true;
}
int main(){
	int n, q;
	cin >> n >> q;
	assert(1 <= n && n <= 100);
	assert(1 <= q && q <= 100000);
	set<string> sv;
	set<pair<int, string>> s1, s2;
	map<string, int> rt;
	while(q--){
		int t;
		cin >> t;
		assert(1 <= t && t <= 3);
		if(t == 1){
			string s;
			int r;
			cin >> s >> r;
			assert(isok(s));
			assert(1 <= (int)s.size() && (int)s.size() <= 100);
			assert(0 <= r && r <= 4000);
			s2.insert({r, s});
			rt[s] = r;
			assert(!sv.count(s));
			sv.insert(s);
		}else if(t == 2){
			int x;
			cin >> x;
			assert(1 <= x && x <= 10);
			n -= x;
		}else if(t == 3){
			string s;
			int x;
			cin >> s >> x;
			assert(isok(s));
			assert(1 <= (int)s.size() && (int)s.size() <= 100);
			assert(1 <= x && x <= 10);
			n += x;
			assert(rt.count(s));
			int r = rt[s];
			s2.erase({r, s});
			s1.insert({r, s});
		}
		vector<pair<int, string>> ans;
		while((int)s2.size() + (int)s1.size() > n){
			if((int)s2.size() > 0){
				auto [p, q] = *s2.begin();
				s2.erase({p, q});
				rt.erase(q);
				ans.push_back({p, q});
			}else{
				auto [p, q] = *s1.begin();
				s1.erase({p, q});
				rt.erase(q);
				ans.push_back({p, q});
			}
		}
		sort(ans.begin(), ans.end());
		for(auto s:ans) cout << s.second << '\n';
	}
	assert((int)sv.size() <= 100);
}
0