Submission #981777

# Submission time Handle Problem Language Result Execution time Memory
981777 2024-05-13T14:41:38 Z blackslex Bitaro’s Party (JOI18_bitaro) C++17
0 / 100
1 ms 600 KB
#include<bits/stdc++.h>

using namespace std;
using pii = pair<int, int>;
using P = pair<pii, int>;

int n, m, q, x, y, t, r;

int main() {
    scanf("%d %d %d", &n, &m, &q);
    int k = ceil(sqrt(n));
    vector<vector<int>> v(n + 5, vector<int>());
    vector<vector<pii>> dp(n + 5, vector<pii>());
    vector<int> ptr(n + 5);
    while (m--) scanf("%d %d", &x, &y), v[y].emplace_back(x);
    for (int i = 1; i <= n; i++) {
        priority_queue<P> pq;
        pq.emplace(pii(0, i), n + 5);
        for (auto &e: v[i]) {
            auto [x, y] = dp[e][0];
            pq.emplace(pii(x + 1, y), e);
            ptr[e] = 1;
        }
        while (!pq.empty() && dp[i].size() < k) {
            auto [x, y] = pq.top(); pq.pop();
            dp[i].emplace_back(x);
            if (ptr[y] < dp[y].size()) {
                auto [cx, cy] = dp[y][ptr[y]]; ptr[y]++;
                pq.emplace(pii(cx + 1, cy), y);
            }
        }
    }
    vector<bool> f(n + 5);
    while (q--) {
        scanf("%d %d", &t, &r);
        vector<int> c(r);
        for (auto &e: c) scanf("%d", &e), f[e] = 1;
        int ans = -1;
        if (r <= k) {
            for (auto &[x, y]: dp[t]) if (!f[y]) {ans = x; break;}
        } else {
            vector<int> cdp(n + 5);
            for (int i = 1; i <= t; i++) {
                for (auto &e: v[i]) cdp[i] = max(cdp[i], cdp[e] + 1);
                if (!f[i]) ans = max(ans, cdp[i]);
            }
        }
        printf("%d\n", ans);
        for (auto &e: c) f[e] = 0;
    }
}

Compilation message

bitaro.cpp: In function 'int main()':
bitaro.cpp:24:44: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |         while (!pq.empty() && dp[i].size() < k) {
      |                               ~~~~~~~~~~~~~^~~
bitaro.cpp:27:24: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (ptr[y] < dp[y].size()) {
bitaro.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:15:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     while (m--) scanf("%d %d", &x, &y), v[y].emplace_back(x);
      |                 ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d %d", &t, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:37:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         for (auto &e: c) scanf("%d", &e), f[e] = 1;
      |                          ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 1 ms 348 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -