제출 #786649

#제출 시각아이디문제언어결과실행 시간메모리
786649PanosPaskBitaro’s Party (JOI18_bitaro)C++14
7 / 100
1758 ms524288 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>> dist; vector<vector<int>> adj_list; int BLOCK_SIZE; vector<int> curbanned; vector<bool> ban; vector<int> dp; 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; } void insert_to(int dest, int src, int len) { if (dist[dest].find(src) != dist[dest].end()) { dist[dest][src] = max(dist[dest][src], len); return; } if (dist[dest].size() < BLOCK_SIZE) { dist[dest][src] = len; } else { auto v = *dist[dest].begin(); if (v.second < len) { dist[dest].erase(v.first); dist[dest][src] = len; } } } int main(void) { scanf("%d %d %d", &N, &M, &Q); BLOCK_SIZE = ceil(sqrt(N)); ban.resize(N); adj_list.resize(N); dist.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 neigh : adj_list[i]) { for (auto city : dist[i]) { insert_to(neigh, city.first, city.second + 1); } } } 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; } 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; }

컴파일 시 표준 에러 (stderr) 메시지

bitaro.cpp: In function 'void insert_to(int, int, int)':
bitaro.cpp:55:27: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |     if (dist[dest].size() < BLOCK_SIZE) {
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%d %d %d", &N, &M, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         scanf("%d %d", &T, &Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:103:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |             scanf("%d", &c);
      |             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...