제출 #1108060

#제출 시각아이디문제언어결과실행 시간메모리
1108060kiethm07Bitaro’s Party (JOI18_bitaro)C++11
100 / 100
1060 ms92620 KiB
#include <bits/stdc++.h> #define pii pair<int,int> #define iii pair<int,pii> #define fi first #define se second #define vi vector<int> #define all(x) x.begin(),x.end() #define TEXT "a" using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const int inf = 1e9 + 7; const ld eps = 1e-8; const double pi = acos(-1); const int N = 1e5 + 5; const int BLOCK = 100; vector<int> a[N]; bool del[N]; int n,m,q; int dp[N]; bool used[N]; pair<int,int> f[N][BLOCK]; int sz[N]; int cal(int u){ if (dp[u] != -inf) return dp[u]; dp[u] = del[u] ? -1 : 0; for (int v : a[u]){ int f = cal(v); if (f != -1) dp[u] = max(dp[u], f + 1); } return dp[u]; } void precompute(){ for (int u = 1; u <= n; u++){ priority_queue<pii> pq; for (int v : a[u]){ for (int i = 0; i < sz[v]; i++) pq.push(f[v][i]); } vector<int> tmp; while(!pq.empty() && sz[u] < BLOCK){ pii t = pq.top(); pq.pop(); if (t.fi == -1) break; if (used[t.se] == 0){ used[t.se] = 1; tmp.push_back(t.se); } else continue; t.fi++; f[u][sz[u]++] = t; } if (sz[u] < BLOCK) f[u][sz[u]++] = pii(0,u); for (int i : tmp) used[i] = 0; } } void heavy(int str, vector<int>& v){ for (int i = 1; i <= n; i++) dp[i] = -inf; for (int i : v) del[i] = 1; cout << cal(str) << "\n"; for (int i : v) del[i] = 0; } void light(int str, vector<int>& v){ int i = 0; for (int i : v) used[i] = 1; int res = -1; for (int i = 0; i < sz[str]; i++){ int dis = f[str][i].fi; int id = f[str][i].se; if (used[id]) continue; res = dis; break; } for (int i : v) used[i] = 0; cout << res << "\n"; } int main(){ cin.tie(0) -> sync_with_stdio(0); if (fopen(TEXT".inp","r")){ freopen(TEXT".inp","r",stdin); freopen(TEXT".out","w",stdout); } cin >> n >> m >> q; for (int i = 1; i <= m; i++){ int u,v; cin >> u >> v; a[v].push_back(u); } precompute(); // for (int u = 1; u <= n; u++) cout << u << " " << sz[u] << "\n"; while(q--){ int str; cin >> str; int num; cin >> num; vector<int> v(num); for (int& i : v) cin >> i; if (v.size() >= BLOCK) heavy(str,v); else light(str,v); } return 0; }

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

bitaro.cpp: In function 'void light(int, std::vector<int>&)':
bitaro.cpp:75:9: warning: unused variable 'i' [-Wunused-variable]
   75 |     int i = 0;
      |         ^
bitaro.cpp: In function 'int main()':
bitaro.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen(TEXT".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(TEXT".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...