Submission #1142338

#TimeUsernameProblemLanguageResultExecution timeMemory
1142338hoa208Bitaro’s Party (JOI18_bitaro)C++20
14 / 100
1262 ms212788 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define pa pair<ll, ll> #define fi first #define se second #define bit(mask, j) ((mask >> j) & 1) #define t_test int t;cin >> t;while(t--) const ll mod = 1e9 + 7; const ll INF = 1e17; const ll B = 100; const ll N = 1e5 + 5; ll n, m, q; ll a[N], dx[N], dp[N]; vector<ll> r_g[N]; vector<pa> dist[N]; void slove2(ll &t, ll &y) { FORD(i, t, 1) { dp[i] = -1; } dp[t] = 0; FORD(i, t, 1) { if(dp[i] == -1) continue; for(auto v : r_g[i]) { dp[v] = max(dp[i] + 1, dp[v]); } } ll ans = -1; FOR(i, 1, t) { if(!dx[i]) { ans = max(ans, dp[i]); } } cout << ans << '\n'; FOR(i, 1, y) { dx[a[i]] = 0; } } void hbmt() { // inp cin >> n >> m >> q; FOR(i, 1, m) { ll u, v; cin >> u >> v; r_g[v].push_back(u); } // pre FOR(i, 1, n) { vector<pa> vt; for(auto v : r_g[i]) { for(auto e : dist[v]) { vt.push_back({e.fi + 1, e.se}); } vt.push_back({1, v}); } vt.push_back({0, i}); sort(vt.begin(), vt.end(), greater<pa>()); vt.erase(unique(vt.begin(), vt.end()), vt.end()); while(vt.size() > B) { vt.pop_back(); } for(auto v : vt) { dist[i].push_back(v); } } ll t, y; FOR(i, 1, q) { cin >> t >> y; FOR(j, 1, y) { cin >> a[j]; dx[a[j]] = 1; } if(y >= B) { slove2(t, y); continue; } bool ok = false; for(auto e : dist[t]) { if(dx[e.se] == 0) { ok = true; cout << e.fi << '\n'; break; } } if(!ok) cout << -1 << '\n'; FOR(j, 1, y) { dx[a[j]] = 0; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); if(fopen("hbmt.inp", "r")) { freopen("hbmt.inp", "r", stdin); freopen("hbmt.out", "w", stdout); } // t_test hbmt(); return 0; }

Compilation message (stderr)

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