제출 #530619

#제출 시각아이디문제언어결과실행 시간메모리
530619Killer2501Bitaro’s Party (JOI18_bitaro)C++14
100 / 100
978 ms215064 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define pll pair<ll, ll> #define pii pair<int, int> #define fi first #define se second using namespace std; const int N = 1e5+5; const int M = 250; const int mod = 1e9+7; const ll base = 75; const int inf = 1e9; int m, n, t, b[N], d[N], lab[N], q; int k, a[N]; pii dp[N][M], cur[M]; int ans, tong; vector<int> adj[N], g[N]; vector<int> vi; string s[N]; bool vis[N]; bool cmp(const int& x, const int& y) { return d[x] > d[y]; } void fix(int l, int r) { int i = 0, j = 0, sz = 0; while(i < a[l] || j < a[r]) { if(j == a[r] || (i < a[l] && dp[l][i].fi+1 > dp[r][j].fi)) { if(!vis[dp[l][i].se]) { vis[dp[l][i].se] = true; cur[sz].fi = dp[l][i].fi+1; cur[sz].se = dp[l][i].se; ++sz; if(sz == M)break; } ++i; } else { if(!vis[dp[r][j].se]) { vis[dp[r][j].se] = true; cur[sz] = dp[r][j]; ++sz; if(sz == M)break; } ++j; } } a[r] = sz; swap(cur, dp[r]); for(int j = 0; j < sz; j ++) vis[dp[r][j].se] = false; } void sol() { cin >> n >> m >> q; for(int i = 1; i <= m; i ++) { int x, y; cin >> x >> y; adj[y].pb(x); g[x].pb(y); } for(int i = 1; i <= n; i ++) { dp[i][0].fi = 0; dp[i][0].se = i; a[i] = 1; for(int v: adj[i])fix(v, i); } while(q -- > 0) { cin >> k >> n; for(int i = 1; i <= n; i ++) { cin >> b[i]; vis[b[i]] = true; } if(dp[k][0].fi == -1)cout << -1 << '\n'; else { ans = -1; if(n >= M) { for(int u = 1; u <= k; u ++) { if(vis[u])d[u] = -1; else d[u] = 0; } for(int u = 1; u <= k; u ++) { if(d[u] == -1)continue; for(int v: g[u])d[v] = max(d[v], d[u]+1); } ans = d[k]; } else { for(int i = 0; i < a[k]; i ++) { if(!vis[dp[k][i].se]) { ans = dp[k][i].fi; break; } } } cout << ans << '\n'; } for(int i = 1; i <= n; i ++)vis[b[i]] = false; } } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #define task "test" if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } int test = 1; //cin >> test; while(test -- > 0)sol(); return 0; }

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

bitaro.cpp: In function 'int main()':
bitaro.cpp:130:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:131:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...