Submission #981796

#TimeUsernameProblemLanguageResultExecution timeMemory
981796blackslexBitaro’s Party (JOI18_bitaro)C++17
14 / 100
1117 ms417380 KiB
#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>()), rev(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[x].emplace_back(y), rev[y].emplace_back(x); for (int i = 1; i <= n; i++) { priority_queue<P> pq; pq.emplace(pii(0, i), n + 1); for (auto &e: rev[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, -1e9); 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]); } } printf("%d\n", ans); for (auto &e: c) f[e] = 0; } }

Compilation message (stderr)

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[x].emplace_back(y), rev[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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...