Submission #1062066

#TimeUsernameProblemLanguageResultExecution timeMemory
1062066Jarif_RahmanFire (BOI24_fire)C++17
14 / 100
2095 ms13748 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<pair<int, int>> A(n); for(auto &[x, y]: A){ cin >> x >> y; if(x > y) y+=m; } sort(A.begin(), A.end()); map<int, vector<int>> L, R; for(int i = 0; i < n; i++){ L[A[i].first].push_back(i); if(A[i].second < m) R[A[i].second].push_back(i); } vector<int> nxt(n, -1); set<pair<int, int>> st; while(!L.empty() || !R.empty()){ if(R.empty() || (!L.empty() && L.begin()->first <= R.begin()->first)){ auto [t, a] = *L.begin(); L.erase(L.begin()); for(int i: a) st.insert({A[i].second, i}); } else{ auto [t, a] = *R.begin(); R.erase(R.begin()); for(int i: a){ st.erase({A[i].second, i}); int mx = A[i].second, j = -1; for(auto [_, k]: st){ if(A[k].first > A[i].first && A[k].second > mx) mx = A[k].second, j = k; } nxt[i] = j; } } } vector<int> cnt(n, 0), mx(n, 0); int ans = 1e9; for(int i = n-1; i >= 0; i--){ if(nxt[i] == -1){ if(A[i].second >= m) cnt[i] = 1, mx[i] = A[i].second-m; } else if(cnt[nxt[i]] != 0){ cnt[i] = cnt[nxt[i]]+1; mx[i] = mx[nxt[i]]; if(mx[i] >= A[i].first) ans = min(ans, cnt[i]); } } if(ans > n) ans = -1; cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...