Submission #1292591

#TimeUsernameProblemLanguageResultExecution timeMemory
1292591thaibeo123Bitaro’s Party (JOI18_bitaro)C++20
14 / 100
833 ms242584 KiB
#include <bits/stdc++.h> using namespace std; #define NAME "A" #define ll long long #define fi first #define se second #define pb push_back #define all(x) x.begin(), x.end() #define MASK(x) (1ll << (x)) #define BIT(x, i) (((x) >> (i)) & 1) const int N = 1e5 + 5; const int inf = 1e9; const int B = 100; int n, m, q; int val[N], dp[N]; bool block[N]; vector<int> g[N]; vector<pair<int, int>> path[N]; void input() { cin >> n >> m >> q; for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; g[v].pb(u); } } void solve() { for (int i = 1; i <= n; i++) { val[i] = -1; } for (int i = 1; i <= n; i++) { path[i].pb({0, i}); vector<int> id; for (int j : g[i]) { for (auto it : path[j]) { if (val[it.se] == -1) { id.pb(it.se); val[it.se] = it.fi + 1; } else { val[it.se] = max(val[it.se], it.fi + 1); } } } for (int x : id) { path[i].pb({val[x], x}); } sort(all(path[i])); while (path[i].size() > B) { path[i].pop_back(); } for (int x : id) { val[x] = -1; } } while (q--) { int t, s; cin >> t >> s; vector<int> cur; for (int i = 1; i <= s; i++) { int x; cin >> x; block[x] = 1; cur.pb(x); } int ans = -1; if (s >= B) { for (int i = 1; i <= t; i++) { dp[i] = -inf; } dp[t] = 0; for (int i = t; i >= 1; i--) { if (block[i] == 0) { ans = max(ans, dp[i]); } for (int x : g[i]) { dp[x] = max(dp[x], dp[i] + 1); } } } else { for (auto it : path[t]) { if (block[it.se] == 0) { ans = max(ans, it.fi); } } } for (int x : cur) { block[x] = 0; } cout << ans << "\n"; } } signed main() { if (fopen(NAME".INP", "r")) { freopen(NAME".INP", "r", stdin); freopen(NAME".OUT", "w", stdout); } cin.tie(0)->sync_with_stdio(0); int t = 1; //cin >> t; while (t--) { input(); solve(); } return 0; }

Compilation message (stderr)

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