結果

問題 No.2372 既視感
ユーザー KoseTKoseT
提出日時 2023-07-07 21:57:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,989 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 220,588 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 23:08:10
合計ジャッジ時間 4,578 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 29 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 91 ms
4,380 KB
testcase_24 AC 88 ms
4,376 KB
testcase_25 AC 93 ms
4,380 KB
testcase_26 AC 92 ms
4,376 KB
testcase_27 AC 91 ms
4,376 KB
testcase_28 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
      }
    }
  }
}
0