提出 #48589854


ソースコード 拡げる

#include <bits/stdc++.h>
#include <atcoder/modint>

namespace {
    using ModInt [[maybe_unused]] = atcoder::modint998244353;
    using Num [[maybe_unused]] = long long int;
    using Vec [[maybe_unused]] = std::vector<Num>;
    using Set [[maybe_unused]] = std::set<Num>;
    using Mset [[maybe_unused]] = std::multiset<Num>;
    using Edges [[maybe_unused]] = std::vector<std::vector<Num>>;

    template<typename T>
    using Q [[maybe_unused]] = std::queue<T>;

    template<typename T>
    using PQ [[maybe_unused]] = std::priority_queue<T, std::vector<T>, std::greater<T>>;
}

void solve(std::istream& is, std::ostream& os) {
    Num n {0};
    is >> n;

    std::vector<Num> ts;
    std::vector<Num> t1s;
    std::vector<std::vector<std::pair<Num, Num>>> events(200009);
    for(Num i{0}; i<n; ++i) {
        Num t, x;
        is >> t >> x;
        events[x].push_back(std::make_pair(t, i));
        ts.push_back(t);
        if (t == 1) {
            t1s.push_back(i);
        }
    }

    Num total {0};
    Vec actions(200009, 0);
    Num idx {0};
    for(const auto& seq : events) {
        Num max_s {0};
        Num s {0};
        for(auto it = seq.rbegin(); it != seq.rend(); ++it) {
            const auto e = it->first;
            const auto i = it->second;
            if (e == 2) {
                s += 1;
                max_s = std::max(max_s, s);
            } else {
                if (s > 0) {
                    actions.at(i) = 1;
                }
                s = std::max(0LL, s-1);
            }
        }

        if (s > 0) {
            os << "-1\n";
            return;
        }

        total += max_s;
        ++idx;
    }

    Num ans {0};
    Num ct {0};
    for(Num i{0}; i<n; ++i) {
        const auto t = ts.at(i);
        if (t == 1) {
            ct += actions.at(i);
            ans = std::max(ans, ct);
        } else {
            --ct;
        }
    }
    os << ans << "\n";

    auto size = t1s.size();
    for(size_t i{0}; i<size; ++i) {
        const auto t = t1s.at(i);
        os << actions.at(t);
        if ((i+1) == size) {
            os << "\n";
        } else {
            os << " ";
        }
    }
}

int main(void) {
    solve(std::cin, std::cout);
    return 0;
}

提出情報

提出日時
問題 E - Takahashi Quest
ユーザ zettsut
言語 C++ 20 (gcc 12.2)
得点 450
コード長 2324 Byte
結果 AC
実行時間 83 ms
メモリ 18876 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 4 ms 9548 KiB
00_sample_01.txt AC 4 ms 9484 KiB
00_sample_02.txt AC 4 ms 9508 KiB
01_random_03.txt AC 7 ms 9676 KiB
01_random_04.txt AC 18 ms 11108 KiB
01_random_05.txt AC 58 ms 15248 KiB
01_random_06.txt AC 58 ms 15320 KiB
01_random_07.txt AC 7 ms 9776 KiB
01_random_08.txt AC 19 ms 11304 KiB
01_random_09.txt AC 36 ms 13144 KiB
01_random_10.txt AC 15 ms 10688 KiB
01_random_11.txt AC 52 ms 15328 KiB
01_random_12.txt AC 17 ms 11308 KiB
01_random_13.txt AC 56 ms 15024 KiB
01_random_14.txt AC 24 ms 11948 KiB
01_random_15.txt AC 54 ms 14892 KiB
01_random_16.txt AC 29 ms 12536 KiB
01_random_17.txt AC 15 ms 10436 KiB
01_random_18.txt AC 29 ms 12412 KiB
01_random_19.txt AC 45 ms 14152 KiB
01_random_20.txt AC 6 ms 9760 KiB
01_random_21.txt AC 72 ms 16764 KiB
01_random_22.txt AC 74 ms 16756 KiB
01_random_23.txt AC 80 ms 16820 KiB
01_random_24.txt AC 77 ms 16836 KiB
01_random_25.txt AC 75 ms 16720 KiB
01_random_26.txt AC 64 ms 16620 KiB
01_random_27.txt AC 74 ms 16396 KiB
01_random_28.txt AC 72 ms 16404 KiB
01_random_29.txt AC 74 ms 16388 KiB
01_random_30.txt AC 61 ms 15792 KiB
01_random_31.txt AC 55 ms 16036 KiB
01_random_32.txt AC 58 ms 15892 KiB
01_random_33.txt AC 83 ms 18876 KiB
01_random_34.txt AC 71 ms 17992 KiB
01_random_35.txt AC 80 ms 16944 KiB
01_random_36.txt AC 46 ms 13908 KiB
01_random_37.txt AC 52 ms 15356 KiB
01_random_38.txt AC 66 ms 16240 KiB
02_handmade_39.txt AC 82 ms 17488 KiB
02_handmade_40.txt AC 80 ms 17352 KiB
02_handmade_41.txt AC 79 ms 17580 KiB
02_handmade_42.txt AC 70 ms 16464 KiB
02_handmade_43.txt AC 69 ms 16576 KiB
02_handmade_44.txt AC 69 ms 16444 KiB
02_handmade_45.txt AC 4 ms 9488 KiB
02_handmade_46.txt AC 4 ms 9496 KiB