Submission #1018932

# Submission time Handle Problem Language Result Execution time Memory
1018932 2024-07-10T10:58:20 Z beaconmc Fire (BOI24_fire) C++14
0 / 100
2000 ms 11932 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;
vector<vector<ll>> overlap;


int solve(ll lo, ll hi){
	ll ans = 0;
	ll cur = 0;
	while (lo < hi){
		ll maxi = 0;
		while (cur < normal.size()){
			if (normal[cur][0] > lo) break;
			maxi = max(maxi, normal[cur][1]);
			cur++;
		}

		if (maxi > lo) ans += 1, lo = maxi;
		else return -1;
	}
	return ans;


}

int main(){
	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 overlap.push_back({b,a});
	}
	sort(normal.begin(), normal.end());
	ll ans = -1;

	//check twice

	ll left = 0, right = m;
	for (auto&i : overlap) left = max(left, i[0]), right = min(right, i[1]);

	if (solve(left, right) != -1) ans = solve(left, right)+2;


	for (auto&i : overlap){
		ans = min( ans, (ll)solve(i[0], i[1]) + 1);
	}
	
	cout << ans;




}

Compilation message

Main.cpp: In function 'int solve(ll, ll)':
Main.cpp:18:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |   while (cur < normal.size()){
      |          ~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 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 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 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 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 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 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 432 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 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 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 3 ms 704 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Execution timed out 2097 ms 11932 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -