Submission #1042581

# Submission time Handle Problem Language Result Execution time Memory
1042581 2024-08-03T07:43:14 Z Theo830 Fire (BOI24_fire) C++17
0 / 100
1 ms 456 KB
#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;
    ll mini = m+5;
    f(i,0,n){
        ll s,e;
        cin>>s>>e;
        if(s < e){
            ex.pb(ii(s,e));
        }
        else{
            mini = min(mini,s);
        }
    }
    sort(all(ex));
    ll ans = 1;
    ll pos = 0;
    ll cur = 0;
    while(pos < ex.size()){
        ll go = cur;
        while(pos < ex.size() && ex[pos].F <= cur){
            go = max(go,ex[pos].S);
            pos++;
        }
        ans++;
        if(cur == go){
            break;
        }
        cur = go;
    }
    if(cur < mini){
        ans = -1;
    }
    cout<<ans<<"\n";
}
/*
4 10
0 2
1 3
2 4
3 0
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:46:15: 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]
   46 |     while(pos < ex.size()){
      |           ~~~~^~~~~~~~~~~
Main.cpp:48: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]
   48 |         while(pos < ex.size() && ex[pos].F <= cur){
      |               ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -