結果
問題 |
No.2804 Fixer And Ratism
|
ユーザー |
|
提出日時 | 2025-02-12 15:29:02 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,577 bytes |
コンパイル時間 | 1,328 ms |
コンパイル使用メモリ | 108,428 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2025-02-12 15:29:07 |
合計ジャッジ時間 | 3,839 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 20 |
ソースコード
#include <iostream> #include <set> #include <string> #include <unordered_map> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; // Sr, Sn: pair<int, string> の set。 pair は (r, s) の順で並ぶ set<pair<int, string>> Sr, Sn; // D: 各文字列 s に対しての整数値 r を保持するマップ unordered_map<string, int> D; for (int i = 0; i < q; i++){ string type; cin >> type; if (type == "1") { // クエリ1: "1 s r" の形式 string s; int r; cin >> s >> r; D[s] = r; Sn.insert({r, s}); } else if (type == "2") { // クエリ2: "2 x" の形式 int x; cin >> x; n -= x; } else { // クエリ3: "3 s x" の形式 string s; int x; cin >> s >> x; n += x; int r = D[s]; Sr.insert({r, s}); Sn.erase({r, s}); } // while ループ: Sn と Sr の要素の合計が n を超えている間 while (Sn.size() + Sr.size() > (size_t)n) { if (!Sn.empty()) { auto it = Sn.begin(); cout << it->second << "\n"; Sn.erase(it); } else { auto it = Sr.begin(); cout << it->second << "\n"; Sr.erase(it); } } } return 0; }