Submission #985665

#TimeUsernameProblemLanguageResultExecution timeMemory
985665SmuggingSpunBitaro’s Party (JOI18_bitaro)C++14
14 / 100
94 ms13576 KiB
#include<bits/stdc++.h> #define taskname "A" using namespace std; const int INF = 1e9; template<class T>void maximize(T& a, T b){ if(a < b){ a = b; } } int n, m, q; namespace sub12{ const int lim = 1e5 + 5; vector<int>e[lim]; int dp[lim]; void solve(){ for(int _ = 0; _ < m; _++){ int u, v; cin >> u >> v; e[v].emplace_back(u); } int t, y; cin >> t >> y; bitset<lim>busy; busy.reset(); for(int _ = 0; _ < y; _++){ int x; cin >> x; busy.set(x); } for(int i = 1; i <= n; i++){ dp[i] = (busy.test(i) ? -INF : 0); for(int& v : e[i]){ maximize(dp[i], dp[v] + 1); } } cout << max(dp[t], -1); } } namespace sub3{ const int lim = 1e5 + 5; vector<int>e[lim]; int deg[lim], dp[lim], f[lim]; bitset<lim>busy; void work(int index){ busy.reset(index); f[index] = 0; for(int& x : e[index]){ if(!busy.test(x)){ maximize(f[index], f[x] + 1); break; } work(x); maximize(f[index], f[x] + 1); } } void solve(){ for(int _ = 0; _ < m; _++){ int u, v; cin >> u >> v; e[v].emplace_back(u); } memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++){ sort(e[i].begin(), e[i].end(), [&] (int i, int j) -> bool{ return dp[i] > dp[j]; }); if(!e[i].empty()){ dp[i] = dp[e[i][0]] + 1; } f[i] = dp[i]; } busy.reset(); for(int _ = 0; _ < q; _++){ int t, y; cin >> t >> y; vector<int>a(y); for(int& x : a){ cin >> x; busy.set(x); } work(t); cout << f[t] << "\n"; for(int& x : a){ busy.reset(x); f[x] = dp[x]; } f[t] = dp[t]; } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); } cin >> n >> m >> q; if(q == 1){ sub12::solve(); } else{ sub3::solve(); } }

Compilation message (stderr)

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