제출 #786660

#제출 시각아이디문제언어결과실행 시간메모리
786660PanosPaskBitaro’s Party (JOI18_bitaro)C++14
7 / 100
2091 ms483824 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<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<int>& banned) { dp.assign(N, -1); for (int i = 0; i < N; i++) { if (!find(i, banned)) { 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<int> banned) { int ans = -1; for (auto v : dist[c]) { if (!find(v.first, banned)) ans = max(ans, v.second); } return ans; } void 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; } if (temp_dist[dest].size() < BLOCK_SIZE) { temp_dist[dest][src] = len; } else { auto v = *temp_dist[dest].begin(); if (v.second < len) { temp_dist[dest].erase(v.first); temp_dist[dest][src] = len; } } } 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); 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(); for (auto neigh : adj_list[i]) { for (auto city : dist[i]) { insert_to(neigh, city.first, city.second + 1); } } } 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); } sort(curbanned.begin(), curbanned.end()); int ans = 0; if (Y >= BLOCK_SIZE) ans = naive_dp(T, curbanned); else ans = find_from_precalculate(T, curbanned); curbanned.clear(); printf("%d\n", ans); } return 0; }

컴파일 시 표준 에러 (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 'void 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) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     scanf("%d %d %d", &N, &M, &Q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:89:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:114:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         scanf("%d %d", &T, &Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:119:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  119 |             scanf("%d", &c);
      |             ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...