Submission #567329

#TimeUsernameProblemLanguageResultExecution timeMemory
567329shrimbBitaro’s Party (JOI18_bitaro)C++17
100 / 100
1584 ms185604 KiB
// #pragma GCC optimize ("Ofast") // #pragma GCC target ("avx,avx2,fma") #include"bits/stdc++.h" using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class x> using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>; #define int long long #define endl '\n' #define mod 1000000007 //\ #define mod 1686876991 const int maxn = 100001; const int sq = 100; vector<int> adj[maxn], radj[maxn]; int n, m, q; vector<pair<int,int>> dp[maxn]; int dp2[maxn]; int c[maxn]; bitset<maxn> rem, inserted; signed main () { cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> q; for (int i = 0 ; i < m ; i++) { int a, b; cin >> a >> b; adj[a].push_back(b); radj[b].push_back(a); } for (int i = 1 ; i <= n ; i++) { dp[i].push_back({0, i}); } for (int i = 1 ; i <= n ; i++) { vector<pair<int,int>> v = dp[i]; for (int j : radj[i]) { for (auto& k : dp[j]) v.emplace_back(k.first + 1, k.second); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); // cerr << v.size() << endl; int idx = 0; dp[i].resize(sq); for (const auto& j : v) { if (inserted[j.second]) continue; inserted[j.second] =1 ; dp[i][idx] = j; idx++; if (idx >= sq) break; } dp[i].resize(idx); for (const auto& j : v) inserted[j.second] = 0; // cerr << "here\n"; } for (int i = 0 ; i < q ; i++) { int t, y; cin >> t >> y; for (int j = 0 ; j < y ; j++) cin >> c[j], rem[c[j]] = 1; if (y < sq - 1) { for (auto j : dp[t]) { if (!rem[j.second]) { cout << j.first << endl; goto good; } } cout << -1 << endl; good:; } else { for (int j = 1 ; j <= t ; j++) { dp2[j] = (rem[j] ? -1e9 : 0); for (int k : radj[j]) dp2[j] = max(dp2[j], dp2[k] + 1); } if (dp2[t] < 0) cout << -1 << endl; else cout << dp2[t] << endl; } for (int j = 0 ; j < y ; j++) rem[c[j]] = 0; } }

Compilation message (stderr)

bitaro.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...