제출 #1103422

#제출 시각아이디문제언어결과실행 시간메모리
1103422manhlinh1501Bitaro’s Party (JOI18_bitaro)C++17
100 / 100
1234 ms118420 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using pii = pair<int, int>; using i64 = long long; const int MAXN = 2e5 + 5; const int BLOCK_SIZE = 90; #define ALL(a) (a).begin(), (a).end() int N, M, Q; vector<int> adj[MAXN]; bool is_deleted[MAXN]; vector<pii> dp[MAXN]; int dist[MAXN]; bool vis[MAXN]; vector<pii> merge_vector(vector<pii> a, vector<pii> b) { int x = 0, y = 0; for(auto &[x, y] : b) x++; vector<pii> ans; while(x < a.size() and y < b.size() and ans.size() < BLOCK_SIZE) { while(x < a.size() and vis[a[x].second]) x++; while(y < b.size() and vis[b[y].second]) y++; if(x == a.size() or y == b.size()) break; if(a[x].first > b[y].first) { if(vis[a[x].second] == false) { vis[a[x].second] = true; ans.emplace_back(a[x]); } x++; } else { if(vis[b[y].second] == false) { vis[b[y].second] = true; ans.emplace_back(b[y]); } y++; } } while(x < a.size() and ans.size() < BLOCK_SIZE) { if(vis[a[x].second] == false) { vis[a[x].second] = true; ans.emplace_back(a[x]); } x++; } while(y < b.size() and ans.size() < BLOCK_SIZE) { if(vis[b[y].second] == false) { vis[b[y].second] = true; ans.emplace_back(b[y]); } y++; } for(auto [x, y] : ans) vis[y] = false; return ans; } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M >> Q; for(int i = 1; i <= M; i++) { int u, v; cin >> u >> v; adj[v].emplace_back(u); } for(int u = 1; u <= N; u++) { dp[u].emplace_back(0, u); for(int v : adj[u]) dp[u] = merge_vector(dp[u], dp[v]); } while(Q--) { int u; cin >> u; int sz; cin >> sz; vector<int> a(sz, 0); for(int &x : a) cin >> x; for(int x : a) is_deleted[x] = true; if(a.size() >= BLOCK_SIZE) { for(int u = 1; u <= N; u ++) { dist[u] = 0; } for(int x : a) { dist[x] = -1e9; } for(int u = 1; u <= N; u ++) { for(int v : adj[u]) { dist[u] = max(dist[u], dist[v] + 1); } } cout << max(-1, dist[u]) << endl; } else { int ans = -1; for(auto [x, y] : dp[u]) { if(is_deleted[y] == false) ans = max(ans, x); } cout << ans << "\n"; } for(int x : a) is_deleted[x] = false; } return (0 ^ 0); }

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

bitaro.cpp: In function 'std::vector<std::pair<int, int> > merge_vector(std::vector<std::pair<int, int> >, std::vector<std::pair<int, int> >)':
bitaro.cpp:22:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     while(x < a.size() and y < b.size() and ans.size() < BLOCK_SIZE) {
      |           ~~^~~~~~~~~~
bitaro.cpp:22:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     while(x < a.size() and y < b.size() and ans.size() < BLOCK_SIZE) {
      |                            ~~^~~~~~~~~~
bitaro.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         while(x < a.size() and vis[a[x].second]) x++;
      |               ~~^~~~~~~~~~
bitaro.cpp:24:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         while(y < b.size() and vis[b[y].second]) y++;
      |               ~~^~~~~~~~~~
bitaro.cpp:25:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         if(x == a.size() or y == b.size()) break;
      |            ~~^~~~~~~~~~~
bitaro.cpp:25:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         if(x == a.size() or y == b.size()) break;
      |                             ~~^~~~~~~~~~~
bitaro.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     while(x < a.size() and ans.size() < BLOCK_SIZE) {
      |           ~~^~~~~~~~~~
bitaro.cpp:47:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     while(y < b.size() and ans.size() < BLOCK_SIZE) {
      |           ~~^~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...