結果

問題 No.2372 既視感
ユーザー hiro71687k
提出日時 2023-07-12 17:18:19
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 2,006 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 212,532 KB
最終ジャッジ日時 2025-02-15 10:05:34
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ld inf=10000999999999900;
int main(){
    ll n,k,q;
    cin >> n >> k >> q;
    map<string,ll>memo;
    queue<string>que;
    vector<ll>ans;
    for (ll i = 0; i < q; i++)
    {
        ll t;
        cin >> t;
        if (t==1)
        {
            string s;
            cin >> s;
            memo[s]++;
            que.push(s);
            while (que.size()>n)
            {
                string t=que.front();
                que.pop();
                memo[t]--;
            }
        }else{
            vector<string>t(6);
            vector<ll>d(6);
            for (ll j = 0; j < 6; j++)
            {
                cin >> t[j] >> d[j];
            }
            ll a=0,x=0;
            bool ok=true;
            for (ll j = 0; j < 6; j++)
            {
                x++;
                if (memo[t[j]]>=1)
                {
                    a+=min(k,d[j]);
                    if (a>60)
                    {
                        a-=min(k,d[j]);
                        x--;
                        ok=false;
                        break;
                    }
                }else{
                    a+=d[j];
                    if (a>60)
                    {
                        a-=d[j];
                        x--;
                        ok=false;
                        break;
                    }
                }
                if (!ok)
                {
                    break;
                }
            }
            for (ll j = 0; j < x; j++)
            {
                memo[t[j]]++;
                que.push(t[j]);
            }
            while (que.size()>n)
            {
                string s=que.front();
                que.pop();
                memo[s]--;
            }
            ans.push_back(x);
        }
    }
    for (ll i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
    
}
0