Submission #1042586

#TimeUsernameProblemLanguageResultExecution timeMemory
1042586Theo830Fire (BOI24_fire)C++17
40 / 100
2100 ms13228 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ii,ll> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///Training int main(void){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,m; cin>>n>>m; vector<ii>ex,ar; f(i,0,n){ ll s,e; cin>>s>>e; if(s < e){ ex.pb(ii(s,e)); } else{ ar.pb((ii(s,e))); ex.pb(ii(0,e)); ex.pb(ii(s,m)); } } sort(all(ex)); ll ans = INF; for(auto x:ar){ ll res = 1; ll pos = 0; ll cur = x.S; while(pos < ex.size() && cur < x.F){ ll go = cur; while(pos < ex.size() && ex[pos].F <= cur){ go = max(go,ex[pos].S); pos++; } res++; if(cur == go){ break; } cur = go; } if(cur < x.F){ res = INF; } ans = min(ans,res); } if(ans == INF){ ans = -1; } cout<<ans<<"\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:49:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         while(pos < ex.size() && cur < x.F){
      |               ~~~~^~~~~~~~~~~
Main.cpp:51:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |             while(pos < ex.size() && ex[pos].F <= cur){
      |                   ~~~~^~~~~~~~~~~
#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...