結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 8 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 12 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 225 ms
4,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 229 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 (const auto& e : query[i].qe) {
        add(e.first);
      }
    }
  }
}
0