# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1019707 | 2024-07-11T07:59:43 Z | beaconmc | Fire (BOI24_fire) | C++14 | 12 ms | 23900 KB |
#include <bits/stdc++.h> typedef long long ll; #define FOR(i,x,y) for(ll i=x; i<y; i++) #define FORNEG(i,x,y) for(ll i=x; i>y; i--) using namespace std; vector<vector<ll>> normal; map<ll, ll> maxis; map<ll,ll> par; ll anc[100005][30]; ll ancc(ll x, ll k){ if (x==1000000000) return 1000000000; if (anc[x][k] != -1) return anc[x][k]; if (k==0){ if (par[x] == x) return anc[x][k] = 1000000000; return anc[x][k] = par[x]; } return anc[x][k] = ancc(ancc(x, k-1), k-1); } int main(){ FOR(i,0,100005) FOR(j,0,30) anc[i][j] = -1; ll n,m; cin >> n >> m; FOR(i,0,n){ ll a,b; cin >> a >> b; if (a<b) normal.push_back({a,b}); else normal.push_back({a,m+b}); } sort(normal.begin(), normal.end()); set<ll> things; for (auto&i : normal){ things.insert(i[0]); things.insert(i[1]); } ll cur = 0; ll maxi = -1; ll maxting = -1; for (auto&i : things){ while (cur < normal.size()){ if (normal[cur][0] <= i){ if (normal[cur][1] > maxi){ maxi = normal[cur][1]; maxting = cur; } }else break; cur++; } maxis[i] = maxting; } FOR(i,0,normal.size()){ par[i] = maxis[normal[i][1]]; } ll realans = 1000000000; FOR(i,0,normal.size()){ ll orig = normal[i][0]; ll ans = 0; ll lo = 0; ll hi = 10000000; while (lo < hi){ ll mid = (lo+hi)/2; ll idk = i; FOR(j,0,30){ if (mid&(1<<j)){ idk = ancc(idk, j); } } if (idk == 1000000000 || normal[idk][1] - orig >= m){ hi = mid; }else{ lo = mid+1; } } if (lo < 1000000) realans = min(realans, lo+1); } if (realans == 1000000000) cout << -1 << endl; else cout << realans << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 23900 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 23900 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 23900 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 23896 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 23900 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 23900 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |