Submission #967331

#TimeUsernameProblemLanguageResultExecution timeMemory
967331PringBitaro’s Party (JOI18_bitaro)C++17
100 / 100
796 ms282124 KiB
#include <bits/stdc++.h> using namespace std; #ifdef MIKU string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m"; #define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x) void dout() { cout << dbrs << endl; } template <typename T, typename ...U> void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); } #else #define debug(...) 39 #endif #define fs first #define sc second #define mp make_pair #define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++) using ll = long long; typedef pair<int, int> pii; namespace { const int MXN = 100005, K = 320, INF = 1e9; int n, m, q; vector<int> edge[MXN], edge_inv[MXN]; int ns[MXN]; pii dp[MXN][K + 10]; pii pd[3][K * 2 + 10]; bitset<MXN> b; int dis[MXN]; void DP(int id) { pd[0][0] = mp(0, id); int nn = 1, nnn; for (auto &pre : edge_inv[id]) { debug(id, pre); copy(dp[pre], dp[pre] + ns[pre], pd[2]); FOR(i, 0, ns[pre]) pd[2][i].fs++; merge(pd[0], pd[0] + nn, pd[2], pd[2] + ns[pre], pd[1], greater<pii>()); nnn = nn + ns[pre]; nn = 0; FOR(i, 0, nnn) { if (b[pd[1][i].sc]) continue; b[pd[1][i].sc] = true; pd[0][nn] = pd[1][i]; nn++; } FOR(i, 0, nn) b[pd[0][i].sc] = false; nn = min(nn, K + 1); } copy(pd[0], pd[0] + nn, dp[id]); ns[id] = nn; } void PRE() { FOR(i, 1, n + 1) DP(i); // FOR(i, 1, n + 1) { // cout << ns[i] << '\n'; // FOR(j, 0, ns[i]) cout << '<' << dp[i][j].fs << ' ' << dp[i][j].sc << '>' << ' '; // cout << '\n'; // } } void BAO(int sr) { fill(dis + 1, dis + n + 1, -INF); dis[sr] = 0; for (int id = sr - 1; id; id--) { for (auto &i : edge[id]) dis[id] = max(dis[id], dis[i] + 1); } } int calc(int t, vector<int> &v) { auto DO = [&]() -> int { if (v.size() <= K) { FOR(i, 0, ns[t]) { auto [w, x] = dp[t][i]; if (!b[x]) return w; } return -1; } else { BAO(t); int ans = -1; FOR(i, 1, t + 1) { if (b[i]) continue; ans = max(ans, dis[i]); } return ans; } }; for (auto &i : v) b[i] = true; int x = DO(); for (auto &i : v) b[i] = false; return x; } } vector<int> solve(int N, int M, int Q, vector<int> &S, vector<int> &E, vector<int> &T, vector<vector<int>> &Y) { ::n = N; ::m = M; ::q = Q; FOR(i, 0, M) { edge[S[i]].push_back(E[i]); edge_inv[E[i]].push_back(S[i]); } PRE(); vector<int> ans; FOR(i, 0, q) { ans.push_back(calc(T[i], Y[i])); } return ans; } void miku() { int n, m, q; vector<vector<int>> y; cin >> n >> m >> q; vector<int> s(m), e(m); FOR(i, 0, m) cin >> s[i] >> e[i]; vector<int> t(q); FOR(i, 0, q) { int k; cin >> t[i] >> k; y.push_back(vector<int>(k)); for (auto &i : y.back()) cin >> i; } vector<int> ans = solve(n, m, q, s, e, t, y); for (auto &i : ans) cout << i << '\n'; } int32_t main() { cin.tie(0) -> sync_with_stdio(false); cin.exceptions(cin.failbit); miku(); return 0; }

Compilation message (stderr)

bitaro.cpp: In function 'void {anonymous}::DP(int)':
bitaro.cpp:11:20: warning: statement has no effect [-Wunused-value]
   11 | #define debug(...) 39
      |                    ^~
bitaro.cpp:35:13: note: in expansion of macro 'debug'
   35 |             debug(id, pre);
      |             ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...