답안 #1069304

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069304 2024-08-21T19:05:40 Z Essa2006 Fire (BOI24_fire) C++14
53 / 100
2000 ms 44924 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);
    bool crc = 1;
    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]);
        
        if (A[i][0] > A[i][1] && A[i][1] != 0) {
            crc = 0;
        }
    }
    
    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];
        if (crc) {
            cur = 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 (crc) {
            break;
        }
    }
    if (ans == n + 1) { 
        ans = -1;
    }
    
    cout << ans;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int i = 0; i < All.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 4 ms 428 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 348 KB Output is correct
37 Correct 4 ms 348 KB Output is correct
38 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 4 ms 428 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 348 KB Output is correct
37 Correct 4 ms 348 KB Output is correct
38 Correct 4 ms 348 KB Output is correct
39 Correct 1488 ms 1644 KB Output is correct
40 Correct 1261 ms 1628 KB Output is correct
41 Correct 4 ms 1372 KB Output is correct
42 Correct 3 ms 1092 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 3 ms 980 KB Output is correct
45 Correct 1097 ms 1224 KB Output is correct
46 Correct 1184 ms 1116 KB Output is correct
47 Correct 5 ms 1368 KB Output is correct
48 Correct 1337 ms 1700 KB Output is correct
49 Correct 1080 ms 1496 KB Output is correct
50 Correct 1135 ms 1156 KB Output is correct
# 결과 실행 시간 메모리 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 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 360 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 4 ms 1372 KB Output is correct
16 Correct 3 ms 1116 KB Output is correct
17 Correct 2 ms 860 KB Output is correct
18 Correct 4 ms 1148 KB Output is correct
19 Correct 4 ms 1368 KB Output is correct
20 Correct 24 ms 6864 KB Output is correct
21 Correct 271 ms 44884 KB Output is correct
22 Correct 263 ms 44816 KB Output is correct
23 Correct 178 ms 29012 KB Output is correct
24 Correct 233 ms 44876 KB Output is correct
25 Correct 172 ms 25352 KB Output is correct
26 Correct 181 ms 30036 KB Output is correct
27 Correct 182 ms 30008 KB Output is correct
28 Correct 245 ms 44048 KB Output is correct
# 결과 실행 시간 메모리 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 452 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 4 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 4 ms 348 KB Output is correct
12 Correct 4 ms 1368 KB Output is correct
13 Correct 3 ms 1116 KB Output is correct
14 Correct 1091 ms 1144 KB Output is correct
15 Correct 24 ms 6868 KB Output is correct
16 Correct 178 ms 29012 KB Output is correct
17 Execution timed out 2076 ms 44924 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 452 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 5 ms 348 KB Output is correct
26 Correct 4 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 5 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 4 ms 428 KB Output is correct
34 Correct 4 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 6 ms 348 KB Output is correct
37 Correct 4 ms 348 KB Output is correct
38 Correct 4 ms 348 KB Output is correct
39 Correct 1488 ms 1644 KB Output is correct
40 Correct 1261 ms 1628 KB Output is correct
41 Correct 4 ms 1372 KB Output is correct
42 Correct 3 ms 1092 KB Output is correct
43 Correct 3 ms 856 KB Output is correct
44 Correct 3 ms 980 KB Output is correct
45 Correct 1097 ms 1224 KB Output is correct
46 Correct 1184 ms 1116 KB Output is correct
47 Correct 5 ms 1368 KB Output is correct
48 Correct 1337 ms 1700 KB Output is correct
49 Correct 1080 ms 1496 KB Output is correct
50 Correct 1135 ms 1156 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 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 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 360 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 4 ms 1372 KB Output is correct
66 Correct 3 ms 1116 KB Output is correct
67 Correct 2 ms 860 KB Output is correct
68 Correct 4 ms 1148 KB Output is correct
69 Correct 4 ms 1368 KB Output is correct
70 Correct 24 ms 6864 KB Output is correct
71 Correct 271 ms 44884 KB Output is correct
72 Correct 263 ms 44816 KB Output is correct
73 Correct 178 ms 29012 KB Output is correct
74 Correct 233 ms 44876 KB Output is correct
75 Correct 172 ms 25352 KB Output is correct
76 Correct 181 ms 30036 KB Output is correct
77 Correct 182 ms 30008 KB Output is correct
78 Correct 245 ms 44048 KB Output is correct
79 Correct 0 ms 344 KB Output is correct
80 Correct 0 ms 348 KB Output is correct
81 Correct 1 ms 348 KB Output is correct
82 Correct 0 ms 452 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 1 ms 348 KB Output is correct
86 Correct 4 ms 348 KB Output is correct
87 Correct 0 ms 348 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 4 ms 348 KB Output is correct
90 Correct 4 ms 1368 KB Output is correct
91 Correct 3 ms 1116 KB Output is correct
92 Correct 1091 ms 1144 KB Output is correct
93 Correct 24 ms 6868 KB Output is correct
94 Correct 178 ms 29012 KB Output is correct
95 Execution timed out 2076 ms 44924 KB Time limit exceeded
96 Halted 0 ms 0 KB -