結果
| 問題 |
No.2804 Fixer And Ratism
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-07-15 14:56:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 43 ms / 2,000 ms |
| コード長 | 1,815 bytes |
| コンパイル時間 | 1,909 ms |
| コンパイル使用メモリ | 96,856 KB |
| 最終ジャッジ日時 | 2025-02-23 15:46:25 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%d%d", &n, &qn);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:57:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | scanf("%d", &op);
| ~~~~~^~~~~~~~~~~
main.cpp:62:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
62 | scanf("%s%d", s, &r);
| ~~~~~^~~~~~~~~~~~~~~
main.cpp:70:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
70 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
main.cpp:77:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
77 | scanf("%s%d", s, &x);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2804.cc: No.2804 Fixer And Ratism - yukicoder
*/
#include<cstdio>
#include<string>
#include<vector>
#include<unordered_map>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
/* constant */
const int MAX_M = 100;
const int MAX_L = 100;
/* typedef */
using vi = vector<int>;
using pii = pair<int,int>;
using umsi = unordered_map<string,int>;
using spii = set<pii>;
using vpii = vector<pii>;
/* global variables */
string ss[MAX_M];
int rs[MAX_M];
umsi sids;
/* subroutines */
int allocid(char s[], int &m) {
string w(s);
auto mit = sids.find(w);
if (mit != sids.end()) return mit->second;
ss[m] = w;
return (sids[w] = m++);
}
/* main */
int main() {
int n, qn;
scanf("%d%d", &n, &qn);
int m = 0;
spii ps0, ps1;
vi rts;
for (int i = 0; i < qn; i++) {
int op;
scanf("%d", &op);
if (op == 1) {
char s[MAX_L + 4];
int r;
scanf("%s%d", s, &r);
int u = allocid(s, m);
rs[u] = r;
ps1.insert({r, u});
}
else if (op == 2) {
int x;
scanf("%d", &x);
n -= x;
}
else { // op == 3
char s[MAX_L + 4];
int x;
scanf("%s%d", s, &x);
int u = allocid(s, m);
ps1.erase({rs[u], u});
ps0.insert({rs[u], u});
n += x;
}
vpii tmp;
while (! ps1.empty() && ps0.size() + ps1.size() > n) {
tmp.push_back(*ps1.begin());
ps1.erase(ps1.begin());
}
while (ps0.size() > n) {
tmp.push_back(*ps0.begin());
ps0.erase(ps0.begin());
}
if (! tmp.empty()) {
sort(tmp.begin(), tmp.end());
for (auto [r, u]: tmp) rts.push_back(u);
}
//printf(" i=%d, op=%d, n=%d, tmp=%d\n", i, op, n, (int)tmp.size());
}
for (auto u: rts) puts(ss[u].c_str());
return 0;
}
tnakao0123