提出 #48686403


ソースコード 拡げる

#include <vector>
#include <cassert>
#include <iostream>
#include <utility>

struct Event{
    int event_type;
    int x;
};

int main(){
    int N; std::cin >> N;
    // {(t_i, x_i)}_i
    std::vector<Event> events(N);
    for (int i = 0; i < N; i ++) {
        int t, x; std::cin >> t >> x;
        x--;
        events[i] = {t, x};
    }

    // [i]: 時刻tにおいて、.back()は最後にあったタイプiのポーションの位置を示す。
    // すでに使用したポーションは省かれる。(スタック)
    std::vector<std::vector<int>> position_portion(N);
    // [i]がtrue: 位置iのポーションを取る
    std::vector<bool> getting_portion(N, false);
    for (int t = 0; t < N; t++) {
        const auto [event_type, x] = events[t];
        switch (event_type) {
            case 1:
                position_portion[x].push_back(t);
                break;
            case 2:
                // 取れるポーションが一切なかった場合ゲームオーバー
                if (position_portion[x].empty()){
                    std::cout << -1 << std::endl;
                    return 0;
                }
                // 現地点tから一番近い箇所にいるポーションxの位置
                const int portion_x_nearest = position_portion[x].back();
                position_portion[x].pop_back();
                getting_portion[portion_x_nearest] = true;
                break;
        }
    }
    
    // 値K
    int max_portion_count = 0;
    {
        // 時刻tにおいて持っているポーションの数
        int count_portion = 0;
        for (int t = 0; t < N; t++) {
            if (getting_portion[t]) { count_portion++; }
            if (events[t].event_type == 2) {
                assert(not getting_portion[t]);
                count_portion--;
            }
            max_portion_count = std::max(max_portion_count, count_portion);
        }
    }
    
    std::cout << max_portion_count << std::endl;
    for (int i = 0; i < N; i++) {
        if (events[i].event_type == 1) {
            std::cout << (getting_portion[i] ? 1 : 0);
            if (i != N - 1) { std::cout << " "; }
        }   
    }
    std::cout << std::endl;
    return 0;
}

// メモ
// 命名規則
    // portionに関する何らかの変数が多く宣言されているので
    // portionの何であるかという内容を先に持ってくる命名規則をとった

提出情報

提出日時
問題 E - Takahashi Quest
ユーザ Appbird
言語 C++ 20 (gcc 12.2)
得点 450
コード長 2513 Byte
結果 AC
実行時間 78 ms
メモリ 15500 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 450 / 450
結果
AC × 3
AC × 47
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 02_handmade_39.txt, 02_handmade_40.txt, 02_handmade_41.txt, 02_handmade_42.txt, 02_handmade_43.txt, 02_handmade_44.txt, 02_handmade_45.txt, 02_handmade_46.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3548 KiB
00_sample_01.txt AC 1 ms 3560 KiB
00_sample_02.txt AC 1 ms 3456 KiB
01_random_03.txt AC 4 ms 3688 KiB
01_random_04.txt AC 14 ms 4620 KiB
01_random_05.txt AC 48 ms 8468 KiB
01_random_06.txt AC 50 ms 8644 KiB
01_random_07.txt AC 4 ms 3608 KiB
01_random_08.txt AC 16 ms 4940 KiB
01_random_09.txt AC 27 ms 6620 KiB
01_random_10.txt AC 10 ms 4456 KiB
01_random_11.txt AC 43 ms 8376 KiB
01_random_12.txt AC 13 ms 4684 KiB
01_random_13.txt AC 41 ms 8172 KiB
01_random_14.txt AC 16 ms 5228 KiB
01_random_15.txt AC 46 ms 8128 KiB
01_random_16.txt AC 26 ms 5896 KiB
01_random_17.txt AC 10 ms 4460 KiB
01_random_18.txt AC 26 ms 6040 KiB
01_random_19.txt AC 39 ms 7404 KiB
01_random_20.txt AC 3 ms 3796 KiB
01_random_21.txt AC 62 ms 9756 KiB
01_random_22.txt AC 62 ms 10024 KiB
01_random_23.txt AC 64 ms 10244 KiB
01_random_24.txt AC 51 ms 9432 KiB
01_random_25.txt AC 52 ms 9448 KiB
01_random_26.txt AC 52 ms 9520 KiB
01_random_27.txt AC 61 ms 9708 KiB
01_random_28.txt AC 62 ms 9760 KiB
01_random_29.txt AC 63 ms 9752 KiB
01_random_30.txt AC 58 ms 9496 KiB
01_random_31.txt AC 50 ms 9500 KiB
01_random_32.txt AC 55 ms 9564 KiB
01_random_33.txt AC 78 ms 15500 KiB
01_random_34.txt AC 52 ms 9468 KiB
01_random_35.txt AC 67 ms 12656 KiB
01_random_36.txt AC 39 ms 7668 KiB
01_random_37.txt AC 44 ms 8372 KiB
01_random_38.txt AC 59 ms 9504 KiB
02_handmade_39.txt AC 65 ms 12692 KiB
02_handmade_40.txt AC 68 ms 12692 KiB
02_handmade_41.txt AC 63 ms 12684 KiB
02_handmade_42.txt AC 60 ms 12584 KiB
02_handmade_43.txt AC 60 ms 12852 KiB
02_handmade_44.txt AC 61 ms 12672 KiB
02_handmade_45.txt AC 1 ms 3500 KiB
02_handmade_46.txt AC 1 ms 3560 KiB