結果
問題 |
No.2804 Fixer And Ratism
|
ユーザー |
|
提出日時 | 2025-02-12 15:30:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,734 bytes |
コンパイル時間 | 1,424 ms |
コンパイル使用メモリ | 109,012 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2025-02-12 15:30:25 |
合計ジャッジ時間 | 3,809 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 は (r, s) の pair を保持する set。 // ※ set は pair の first, second の順で自動的にソートされる set<pair<int, string>> Sr, Sn; // 各文字列 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" で n を x 減少 int x; cin >> x; n -= x; } else { // クエリ "3" // クエリ3: "3 s x" で n を x 増加し、s に対応する (r, s) を Sr に移動 string s; int x; cin >> s >> x; n += x; int r = D[s]; Sr.insert({r, s}); Sn.erase({r, s}); } // Sn と Sr の合計サイズが n を超える間、先頭の要素を出力・削除 while (Sn.size() + Sr.size() > static_cast<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; }