제출 #47805

#제출 시각아이디문제언어결과실행 시간메모리
47805qoo2p5Bitaro’s Party (JOI18_bitaro)C++17
14 / 100
1004 ms247116 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = (int) 1e9 + 1e6 + 123; const ll LINF = (ll) 1e18 + 1e9 + 123; #define rep(i, s, t) for (auto i = (s); i < (t); ++(i)) #define per(i, s, t) for (auto i = (s); i >= (t); --(i)) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back bool mini(auto &x, const auto &y) { if (y < x) { x = y; return 1; } return 0; } bool maxi(auto &x, const auto &y) { if (y > x) { x = y; return 1; } return 0; } void run(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); run(); return 0; } const int N = (int) 1e5 + 123; const int K = 300; int n, m, q; vector<int> g[N]; int ans[N]; int t[N], y[N]; vector<int> c[N]; int dp[N]; int naive(int id) { fill(dp, dp + N, 0); for (int v : c[id]) { dp[v] = -INF; } rep(i, 1, n + 1) { for (int j : g[i]) { if (dp[j] != -INF) { maxi(dp[i], dp[j] + 1); } } } return (dp[t[id]] == -INF ? -1 : dp[t[id]]); } bool used[N]; int cnt[N]; pair<int, int> best[N][K]; pair<int, int> tmp[2 * K]; int small(int id) { for (int v : c[id]) { used[v] = 1; } int res = -INF; rep(i, 0, cnt[t[id]]) { auto &it = best[t[id]][i]; if (!used[it.second]) { maxi(res, it.first); } } for (int v : c[id]) { used[v] = 0; } return (res == -INF ? -1 : res); } void run() { cin >> n >> m >> q; rep(i, 0, m) { int u, v; cin >> u >> v; g[v].pb(u); } rep(i, 0, N) { rep(j, 0, K) { cnt[i] = 0; best[i][j] = {-INF, -1}; } } rep(i, 1, n + 1) { cnt[i] = 1; best[i][0] = {0, i}; for (int j : g[i]) { rep(t, 0, cnt[j]) { best[j][t].first++; } merge(best[i], best[i] + cnt[i], best[j], best[j] + cnt[j], tmp); rep(t, 0, cnt[j]) { best[j][t].first--; } int tot = cnt[i] + cnt[j]; cnt[i] = min(tot, K); int id = 1; per(t, cnt[i] - 1, 0) { best[i][t] = tmp[tot - id]; id++; } } } rep(i, 0, q) { cin >> t[i] >> y[i]; c[i].resize(y[i]); rep(j, 0, y[i]) { cin >> c[i][j]; } if (y[i] >= K) { ans[i] = naive(i); } else { ans[i] = small(i); } } rep(i, 0, q) { cout << ans[i] << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...