Submission #1111513

# Submission time Handle Problem Language Result Execution time Memory
1111513 2024-11-12T09:09:11 Z YSH2020 Fire (BOI24_fire) C++17
0 / 100
1 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
	int n, m; cin >> n >> m;
	vector<pair<int, int>> shifts;
	int max_dist = 0;
	int start_x = 0;
	for (int i = 0; i < n; i++) {
		int x, y; cin >> x >> y;
		if (x > y) y += m;
		if (y-x > max_dist) {max_dist = y-x;start_x = x;}
		shifts.push_back({x, y});
	}
	for (int i=0; i < n; i++) {
		shifts[i] = {(shifts[i].first-start_x+2*m)%m, (shifts[i].second-start_x+2*m)%m};
		if (shifts[i].first > shifts[i].second) shifts[i]={shifts[i].first, shifts[i].second+m};
	}
	sort(shifts.begin(), shifts.end());
	int time = 0;
	int furthest_time = 0;
	for (int i=0; i < n; i++) {
		if (shifts[i].first <= time) furthest_time = max(furthest_time, shifts[i].second);
		else {
			time = furthest_time;
			if (time >= m) break;
			if (shifts[i].first > time) {break;}
			furthest_time = shifts[i].second;
		}
	}
	time = furthest_time;
	if (time < m) {cout << -1; return 0;}
	time -= m;
	//now reshift everything by time
	for (int i=0; i < n; i++) {
		shifts[i] = {(shifts[i].first-time+2*m)%m, (shifts[i].second-time+2*m)%m};
		if (shifts[i].first > shifts[i].second) shifts[i]={shifts[i].first, shifts[i].second+m};
	}
	//do it again
	sort(shifts.begin(), shifts.end());
	time = 0;
	furthest_time = 0;
	int c = 0;
	for (int i=0; i < n; i++) {
		if (shifts[i].first <= time) furthest_time = max(furthest_time, shifts[i].second);
		else {
			c++;
			time = furthest_time;
			if (time >= m) {cout << c; return 0;}
			if (shifts[i].first > time) {cout << -1; return 0;}
			furthest_time = shifts[i].second;
		}
	}
	c++;
	time = furthest_time;
	if (time >= m) {cout << c; return 0;}
	else cout << -1;	
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Incorrect 1 ms 336 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Incorrect 1 ms 336 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -