結果
| 問題 |
No.2372 既視感
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-07 21:57:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,989 bytes |
| コンパイル時間 | 2,774 ms |
| コンパイル使用メモリ | 216,156 KB |
| 最終ジャッジ日時 | 2025-02-15 07:14:46 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 WA * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
struct QueryType {
int query_type;
vector<pair<string, int>> qe;
string c;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, q;
cin >> n >> k >> q;
vector<QueryType> query(q);
for (int i=0;i<q;++i) {
cin >> query[i].query_type;
if (query[i].query_type == 1) {
cin >> query[i].c;
} else {
vector<pair<string, int>> t(6);
for (int j=0;j<6;++j) cin >> t[j].first >> t[j].second;
query[i].qe = t;
}
}
priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> pque;
int id {1};
auto check = [&](const string& s) {
queue<pair<int, string>> que;
bool is_find {false};
while (!pque.empty()) {
pair<int, string> ct = pque.top(); pque.pop();
if (ct.second == s) is_find = true;
que.push(ct);
}
while (!que.empty()) {
pair<int, string> ct = que.front(); que.pop();
pque.push(ct);
}
return is_find;
};
auto add = [&](const string& s) {
queue<pair<int, string>> que;
while (!pque.empty()) {
pair<int, string> ct = pque.top(); pque.pop();
que.push(ct);
}
bool is_find {false};
while (!que.empty()) {
pair<int, string> ct = que.front(); que.pop();
if (ct.second == s) {
is_find = true;
ct.first = id++;
}
pque.push(ct);
}
if (is_find == false) {
pque.push(make_pair(id++, s));
if (pque.size() > n) pque.pop();
}
};
for (int i=0;i<q;++i) {
if (query[i].query_type == 1) {
add(query[i].c);
} else {
int cnt {};
long long ans {};
for (const auto& e : query[i].qe) {
if (check(e.first)) ans += min(e.second, k);
else ans += e.second;
//cout << ans << ' ';
if (ans > 60ll) break;
++cnt;
}
cout << cnt << '\n';
for (int j=0;j<cnt;++j) {
add(query[i].qe[j].first);
}
}
}
}