Submission #1069297

# Submission time Handle Problem Language Result Execution time Memory
1069297 2024-08-21T19:01:33 Z Essa2006 Fire (BOI24_fire) C++14
40 / 100
2000 ms 7320 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
   
 
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    
    vector<int> All;
    All.reserve(2 * n);
    
    vector<array<int, 2>> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i][0] >> A[i][1];
        
        All.push_back(A[i][0]);
        All.push_back(A[i][1]);
    }
    
    sort(all(All));
    map<int, int> new_;
    int cnt = 0;
    for (int i = 0; i < All.size(); i++) {
        if (!i || All[i] != All[i - 1]) {
            new_[All[i]] = cnt++;
        }
    }
    int sz = cnt;
    
    for (int i = 0; i < n; i++) {
        A[i][0] = new_[A[i][0]], A[i][1] = new_[A[i][1]];
    }
    
    int ans = n + 1;
    for (int k = 0; k < n; k++) {
        int cur = A[k][0];
        vector<array<int, 2>> B = A;
        
        vector<vector<int>> Events(sz + 1);
        for (int i = 0; i < n; i++) {
            if (A[i][0] >= cur) {
                A[i][0] -= cur;
            }   
            else {
                A[i][0] += sz - cur;
            }
            if (A[i][1] >= cur) {
                A[i][1] -= cur;
            }   
            else {
                A[i][1] += sz - cur;
            }
            
            if (A[i][0] > A[i][1]) {
                A[i][1] = sz;
            }
            
            Events[A[i][0]].push_back(i);
        }
        
        
        vector<int> Prf(sz + 1, n + 1);
        Prf[0] = 0;
        int mx = 0;
        for (int i = 0; i <= sz; i++) {
            for (auto j : Events[i]) {
                mx = max(mx, A[j][1]);
            }
            
            Prf[mx] = min(Prf[mx], Prf[i] + 1);
        }
        
        ans = min(ans, Prf[sz]);
        
        swap(A, B);
    }
    if (ans == n + 1) { 
        ans = -1;
    }
    
    cout << ans;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < All.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 360 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 360 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 524 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 4 ms 500 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 4 ms 520 KB Output is correct
38 Correct 4 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 360 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 524 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 4 ms 500 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 4 ms 520 KB Output is correct
38 Correct 4 ms 500 KB Output is correct
39 Correct 1480 ms 1628 KB Output is correct
40 Correct 1254 ms 1700 KB Output is correct
41 Correct 1496 ms 1392 KB Output is correct
42 Correct 1135 ms 1136 KB Output is correct
43 Correct 990 ms 860 KB Output is correct
44 Correct 1078 ms 1116 KB Output is correct
45 Correct 1124 ms 1220 KB Output is correct
46 Correct 1107 ms 1200 KB Output is correct
47 Correct 1331 ms 1548 KB Output is correct
48 Correct 1411 ms 1696 KB Output is correct
49 Correct 1037 ms 1492 KB Output is correct
50 Correct 1072 ms 1136 KB Output is correct
# 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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 456 KB Output is correct
9 Correct 7 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 508 KB Output is correct
14 Correct 6 ms 600 KB Output is correct
15 Correct 1426 ms 1548 KB Output is correct
16 Correct 1126 ms 1132 KB Output is correct
17 Correct 949 ms 848 KB Output is correct
18 Correct 1076 ms 1116 KB Output is correct
19 Correct 1333 ms 1388 KB Output is correct
20 Execution timed out 2024 ms 7320 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 5 ms 600 KB Output is correct
9 Correct 4 ms 496 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 1448 ms 1392 KB Output is correct
13 Correct 1086 ms 1360 KB Output is correct
14 Correct 1066 ms 1116 KB Output is correct
15 Execution timed out 2031 ms 7064 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 360 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 604 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 524 KB Output is correct
26 Correct 5 ms 344 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 4 ms 500 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 5 ms 348 KB Output is correct
37 Correct 4 ms 520 KB Output is correct
38 Correct 4 ms 500 KB Output is correct
39 Correct 1480 ms 1628 KB Output is correct
40 Correct 1254 ms 1700 KB Output is correct
41 Correct 1496 ms 1392 KB Output is correct
42 Correct 1135 ms 1136 KB Output is correct
43 Correct 990 ms 860 KB Output is correct
44 Correct 1078 ms 1116 KB Output is correct
45 Correct 1124 ms 1220 KB Output is correct
46 Correct 1107 ms 1200 KB Output is correct
47 Correct 1331 ms 1548 KB Output is correct
48 Correct 1411 ms 1696 KB Output is correct
49 Correct 1037 ms 1492 KB Output is correct
50 Correct 1072 ms 1136 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 452 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 456 KB Output is correct
59 Correct 7 ms 348 KB Output is correct
60 Correct 8 ms 348 KB Output is correct
61 Correct 4 ms 344 KB Output is correct
62 Correct 4 ms 348 KB Output is correct
63 Correct 4 ms 508 KB Output is correct
64 Correct 6 ms 600 KB Output is correct
65 Correct 1426 ms 1548 KB Output is correct
66 Correct 1126 ms 1132 KB Output is correct
67 Correct 949 ms 848 KB Output is correct
68 Correct 1076 ms 1116 KB Output is correct
69 Correct 1333 ms 1388 KB Output is correct
70 Execution timed out 2024 ms 7320 KB Time limit exceeded
71 Halted 0 ms 0 KB -