Submission #786677

#TimeUsernameProblemLanguageResultExecution timeMemory
786677PanosPaskBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2098 ms441816 KiB
#include <bits/stdc++.h> #define pb push_back using namespace std; typedef pair<int, int> pi; int N, M, Q; vector<map<int, int>> temp_dist; vector<vector<pi>> dist; vector<vector<int>> adj_list; int BLOCK_SIZE; vector<bool> ban; vector<int> curbanned; vector<int> dp; int find(int i, vector<int>& v) { int p = lower_bound(v.begin(), v.end(), i) - v.begin(); if (p < v.size() && v[p] == i) return true; else return false; } int naive_dp(int dest, vector<bool>& banned) { dp.assign(N, -1); for (int i = 0; i < N; i++) { if (!banned[i]) { dp[i] = max(dp[i], 0); } if (dp[i] == -1) { continue; } for (auto v : adj_list[i]) dp[v] = max(dp[v], dp[i] + 1); } return dp[dest]; } int find_from_precalculate(int c, vector<bool>& banned) { int ans = -1; for (auto v : dist[c]) { if (!banned[v.first]) ans = max(ans, v.second); } return ans; } bool insert_to(int dest, int src, int len) { if (temp_dist[dest].find(src) != temp_dist[dest].end()) { temp_dist[dest][src] = max(temp_dist[dest][src], len); return true; } if (temp_dist[dest].size() < BLOCK_SIZE) { temp_dist[dest][src] = len; return true; } else { auto v = *temp_dist[dest].begin(); if (v.second < len) { temp_dist[dest].erase(v.first); temp_dist[dest][src] = len; return true; } else { return false; } } } int main(void) { scanf("%d %d %d", &N, &M, &Q); BLOCK_SIZE = ceil(sqrt(N)); adj_list.resize(N); dist.resize(N); temp_dist.resize(N); ban.resize(N); for (int i = 0; i < M; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; adj_list[u].pb(v); } // Precalculate best cities for (int i = 0; i < N; i++) { insert_to(i, i, 0); for (auto v : temp_dist[i]) dist[i].push_back(v); temp_dist[i].clear(); assert(dist[i].size() <= BLOCK_SIZE); sort(dist[i].begin(), dist[i].end(), [](pi& a, pi& b) {return a.second > b.second;}); for (auto neigh : adj_list[i]) { for (auto city : dist[i]) { if (!insert_to(neigh, city.first, city.second + 1)) break; } } } temp_dist.clear(); for (int i = 0; i < Q; i++) { int T, Y; scanf("%d %d", &T, &Y); T--; for (int j = 0; j < Y; j++) { int c; scanf("%d", &c); c--; curbanned.push_back(c); ban[c] = true; } sort(curbanned.begin(), curbanned.end()); int ans = 0; if (Y >= BLOCK_SIZE) ans = naive_dp(T, ban); else ans = find_from_precalculate(T, ban); while (curbanned.size()) { ban[curbanned.back()] = false; curbanned.pop_back(); } printf("%d\n", ans); } return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'int find(int, std::vector<int>&)':
bitaro.cpp:21:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     if (p < v.size() && v[p] == i)
      |         ~~^~~~~~~~~~
bitaro.cpp: In function 'bool insert_to(int, int, int)':
bitaro.cpp:65:32: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |     if (temp_dist[dest].size() < BLOCK_SIZE) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from bitaro.cpp:1:
bitaro.cpp: In function 'int main()':
bitaro.cpp:109:31: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  109 |         assert(dist[i].size() <= BLOCK_SIZE);
      |                ~~~~~~~~~~~~~~~^~~~~~~~~~~~~
bitaro.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |     scanf("%d %d %d", &N, &M, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:95:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:125:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         scanf("%d %d", &T, &Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:130:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |             scanf("%d", &c);
      |             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...