Submission #982546

# Submission time Handle Problem Language Result Execution time Memory
982546 2024-05-14T12:09:56 Z blackslex Stranded Far From Home (BOI22_island) C++17
0 / 100
3 ms 7516 KB
#include<bits/stdc++.h>

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

const int N = 1e5 + 5, K = 320;
int n, m, q, x, y, t, r, ptr[N], cdp[N];
vector<int> v[N], rev[N];
vector<pii> dp[N];
bool f[N], f2[N];

int main() {
    scanf("%d %d %d", &n, &m, &q);
    int k = K;
    while (m--) scanf("%d %d", &x, &y), v[x].emplace_back(y), rev[y].emplace_back(x);
    for (int i = 1; i <= n; i++) cdp[i] = -1e9;
    auto mg = [&] (vector<pii> a, vector<pii> b) {
        vector<pii> res;
        for (int p1 = 0, p2 = 0; res.size() <= k && (p1 < a.size() || p2 < b.size());) {
            if (p1 >= b.size() || (p1 < a.size() && a[p1] > b[p2])) {
                res.emplace_back(a[p1]);
                f2[a[p1++].second] = 1;
            } else {
                res.emplace_back(b[p2]);
                f2[b[p2++].second] = 1;
            }
            while (p1 < a.size() && f2[a[p1].second]) p1++;
            while (p2 < b.size() && f2[b[p2].second]) p2++;
        }
        for (auto &[x, y]: res) f2[y] = 0;
        return res;
    };
    for (int i = 1; i <= n; i++) {
        dp[i] = {{-1, i}, {-1e9, 0}};
        for (auto &e: rev[i]) dp[i] = mg(dp[i], dp[e]);
        for (auto &[x, y]: dp[i]) x++;
    }
    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 {
            cdp[t] = 0;
            for (int i = t; i >= 1; i--) {
                for (auto &e: v[i]) cdp[i] = max(cdp[i], cdp[e] + 1);
                if (!f[i]) ans = max(ans, cdp[i]);
            }
            for (int i = t; i >= 1; i--) cdp[i] = -1e9;
        }
        printf("%d\n", ans);
        for (auto &e: c) f[e] = 0;
    }
}

Compilation message

island.cpp: In lambda function:
island.cpp:20:45: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |         for (int p1 = 0, p2 = 0; res.size() <= k && (p1 < a.size() || p2 < b.size());) {
      |                                  ~~~~~~~~~~~^~~~
island.cpp:20:57: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for (int p1 = 0, p2 = 0; res.size() <= k && (p1 < a.size() || p2 < b.size());) {
      |                                                      ~~~^~~~~~~~~~
island.cpp:20:74: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |         for (int p1 = 0, p2 = 0; res.size() <= k && (p1 < a.size() || p2 < b.size());) {
      |                                                                       ~~~^~~~~~~~~~
island.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |             if (p1 >= b.size() || (p1 < a.size() && a[p1] > b[p2])) {
      |                 ~~~^~~~~~~~~~~
island.cpp:21:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |             if (p1 >= b.size() || (p1 < a.size() && a[p1] > b[p2])) {
      |                                    ~~~^~~~~~~~~~
island.cpp:28:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |             while (p1 < a.size() && f2[a[p1].second]) p1++;
      |                    ~~~^~~~~~~~~~
island.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             while (p2 < b.size() && f2[b[p2].second]) p2++;
      |                    ~~~^~~~~~~~~~
island.cpp: In function 'int main()':
island.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d %d %d", &n, &m, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:16:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     while (m--) scanf("%d %d", &x, &y), v[x].emplace_back(y), rev[y].emplace_back(x);
      |                 ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         scanf("%d %d", &t, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~
island.cpp:42:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         for (auto &e: c) scanf("%d", &e), f[e] = 1;
      |                          ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Output isn't correct
2 Halted 0 ms 0 KB -