結果

問題 No.2372 既視感
ユーザー 259-Momone
提出日時 2024-03-19 20:37:53
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 3,744 ms
コンパイル使用メモリ 334,212 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-09-30 05:39:02
合計ジャッジ時間 4,568 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>

int main() {
    using namespace std;
    unsigned N, K, Q;
    cin >> N >> K >> Q;

    map<string, unsigned> counter;
    deque<string> viewed(N);
    counter[""] = N;

    const auto add{[&counter, &viewed](const auto &S) {
        ++counter[S];
        viewed.emplace_back(S);
        if (!--counter[viewed.front()])
            counter.erase(viewed.front());
        viewed.pop_front();
    }};

    for (unsigned i{}; i < Q; ++i) {
        unsigned type;
        cin >> type;
        if (type == 1) {
            string S;
            cin >> S;
            add(S);
        } else {
            array<string, 6> s{};
            array<unsigned, 6> v{};
            for (unsigned j{}; j < 6; ++j) {
                cin >> s[j];
                unsigned time;
                cin >> time;
                if (counter.contains(s[j]))
                    v[j] = min(time, K);
                else
                    v[j] = time;
            }
            const auto x{
                [&]() -> unsigned {
                    for (unsigned i{}, a{}; i < 6; ++i) {
                        if (a + v[i] <= 60)
                            a += v[i];
                        else
                            return i;
                    }
                    return 6;
                }()};
            cout << x << endl;
            for (unsigned j{}; j < x; ++j)
                add(s[j]);
        }
    }
    return 0;
}
0