Submission #1280178

#TimeUsernameProblemLanguageResultExecution timeMemory
1280178MinhKienBitaro’s Party (JOI18_bitaro)C++20
100 / 100
773 ms410820 KiB
#include <iostream> #include <vector> #define MASK(i) (1 << (i)) #define pub push_back #define all(v) v.begin(), v.end() #define compact(v) v.erase(unique(all(v)), end(v)) #define ii pair < int, int > #define fi first #define se second #define endl "\n" #define sz(v) (int)(v).size() #define dbg(x) "[" #x " = " << (x) << "]" #define vi vector<int> using namespace std; template<class T> bool minimize(T& a, T b){if(a > b) return a = b, true;return false;} template<class T> bool maximize(T& a, T b){if(a < b) return a = b, true;return false;} typedef long long ll; typedef long double ld; const int MAX = 1e5 + 15; const int block_sz = 350; int n, m, q; vector<int> g[MAX]; vector<ii> dp[MAX]; bool busy[MAX]; int f[MAX]; bool opt[MAX]; vector <ii> combine(vector <ii> &a, vector <ii> &b) { vector<ii> c; int i = 0, j = 0; while(i < sz(a) || j < sz(b)){ if(sz(c) == block_sz) break; if(i == sz(a)){ if(!opt[b[j].se]){ opt[b[j].se] = true; c.push_back(b[j]); c.back().fi++; } j++; continue; } if(j == sz(b)){ if(!opt[a[i].se]){ opt[a[i].se] = true; c.push_back(a[i]); } i++; continue; } if(a[i].fi > b[j].fi){ if(!opt[a[i].se]){ opt[a[i].se] = true; c.push_back(a[i]); } i++; } else{ if(!opt[b[j].se]){ opt[b[j].se] = true; c.push_back(b[j]); c.back().fi++; } j++; } } for(auto e : c) opt[e.se] = false; return c; } void solve(){ cin >> n >> m >> q; for(int i = 1; i <= m; i++){ int u, v; cin >> u >> v; g[v].push_back(u); //reverse edge } for(int u = 1; u <= n; u++){ for(int v : g[u]){ dp[u] = combine(dp[u], dp[v]); } dp[u].push_back(ii(0, u)); } while(q--){ int u, num; cin >> u >> num; vector<int> ban; while(num--){ int x; cin >> x; ban.push_back(x); busy[x] = true; } if(sz(ban) < block_sz){ bool ok = false; for(auto &[k, node] : dp[u]){ if(!busy[node]){ ok = true; cout << k << endl; break; } } if(!ok) cout << -1 << endl; } else{ fill(f + 1, f + 1 + n, 0); int ans = 0; f[u]++;//push idx +1 for(int i = u; i >= 1; i--){ if(!f[i]) continue; if(!busy[i]) maximize(ans, f[i]); for(int j : g[i]) maximize(f[j], f[i] + 1); } ans--; cout << ans << endl; } for(int x : ban) busy[x] = false; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define task "task" if(fopen(task".INP", "r")){ freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int t; t = 1; //cin >> t; while(t--) solve(); }

Compilation message (stderr)

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