Submission #1027575

# Submission time Handle Problem Language Result Execution time Memory
1027575 2024-07-19T07:42:39 Z Issa Fire (BOI24_fire) C++17
0 / 100
2000 ms 4700 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 3e5 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 350;
const int P = 31;

int n, m;
pii a[maxn];
pii b[maxn];

int f(int i, int j){
	if(j >= i) return j - i;
	return m + j - i;
}

void test(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i].first >> a[i].second;
	}
	int ans = inf;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			b[j] = a[j];
			if(a[j].first < a[i].first){
				b[j].first += m;
				b[j].second += m;
			} else if(a[j].second < a[j].first){
				b[j].second += m;
			}
		}
		int x = 0, y = 0, cnt = 0;
		sort(b + 1, b + n + 1, [](pii i, pii j){
			if(i.first != j.first) return i < j;
			return i.second > j.second;
		});
		for(int j = 1; j <= n && x < m; j++){
			if(f(b[i].first, b[j].first) > x){
				x = y; cnt++;
			}
			if(f(b[i].first, b[j].first) <= x){
				y = max(y, f(b[i].first, b[j].second));
			} else cnt = inf;
		}
		if(x < m) x = y, cnt++;
		if(x >= m) ans = min(ans, cnt);
	}
	if(ans == inf) ans = -1;
	cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t; t = 1;
    while(t--) test();
    cout << ent;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Incorrect 1 ms 2396 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 4 ms 2396 KB Output is correct
9 Correct 4 ms 2396 KB Output is correct
10 Correct 4 ms 2396 KB Output is correct
11 Correct 4 ms 2396 KB Output is correct
12 Correct 1310 ms 2536 KB Output is correct
13 Correct 1328 ms 2528 KB Output is correct
14 Correct 1329 ms 2532 KB Output is correct
15 Execution timed out 2058 ms 4700 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -