Submission #1068898

# Submission time Handle Problem Language Result Execution time Memory
1068898 2024-08-21T12:58:39 Z Essa2006 Fire (BOI24_fire) C++14
31 / 100
2000 ms 1884 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)

const int N = 1 << 14;
array<int, 2> bad = {(int)2e5, (int)2e5};
vector<array<int, 2>> S;

void clear_them() {
    S.clear();
    S.resize(2 * N, bad);
}

void update(int j, int id, int val) {
    id += N;
    S[id][j] = val;
    while (id /= 2) {
        S[id] = min(S[id * 2], S[id * 2 + 1]);
    }
}

int get(int j, int id, int u, int v, int l, int r) {
    if (l > v || r < u) {
        return 2e5;
    }
    
    if (l >= u && r <= v) {
        return S[id][j];
    }
    
    int md = (l + r) / 2;
    return min(get(j, id * 2, u, v, l, md), get(j, id * 2 + 1, u, v, md + 1, r));
}   

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]];
    }
    for (int i = 0; i < All.size(); i++) {
        All[i] = new_[All[i]];
    }
    
    int ans = n + 1;
    for (int k = 0; k < All.size(); k++) {
        if (k && All[k] == All[k - 1]) {
            continue;
        }
        
        clear_them();
        int cur = All[k];
        vector<array<int, 2>> B = A;

        vector<int> Events[(int)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);
            Events[A[i][1]].push_back(i);
        }
        
        
        int  Prf[(int)sz + 1], Suf[(int)sz + 1];
        for (int i = 0; i <= sz; i++) {
            Prf[i] = Suf[i] = n + 1;
        }
        
        Prf[0] = 0;
        update(0, 0, Prf[0]);
        for (int i = 1; i <= sz; i++) {
            for (auto j : Events[i]) {
                if (i != A[j][1]) {
                    continue;
                }
                
                Prf[i] = min(Prf[i], get(0, 1, A[j][0], A[j][1] - 1, 0, N - 1) + 1);
            }
            update(0, i, Prf[i]);
        }
        
        Suf[sz] = 0;
        update(1, sz, Suf[sz]);
        for (int i = sz; i >= 0; i--) {
            for (auto j : Events[i]) {
                if (i != A[j][0]) {
                    continue;
                }
                
                Suf[i] = min(Suf[i], get(1, 1, A[j][0] + 1, A[j][1], 0, N - 1) + 1);
            }
            update(1, i, Suf[i]);
        }
        
        for (int i = 1; i <= sz; i++) {
            Suf[i] = min(Suf[i], Suf[i - 1]);
        }
        for (int i = sz - 1; i >= 0; i--) {
            Prf[i] = min(Prf[i], Prf[i + 1]);
        }
        
        for (int i = 0; i <= sz; i++) {
            ans = min(ans, Prf[i] + Suf[i]);
        }
        
        swap(A, B);
    }
    if (ans == n + 1) { 
        ans = -1;
    }
    cout << ans;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for (int i = 0; i < All.size(); i++) {
      |                     ~~^~~~~~~~~~~~
Main.cpp:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for (int i = 0; i < All.size(); i++) {
      |                     ~~^~~~~~~~~~~~
Main.cpp:75:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int k = 0; k < All.size(); k++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 110 ms 796 KB Output is correct
26 Correct 80 ms 600 KB Output is correct
27 Correct 32 ms 604 KB Output is correct
28 Correct 95 ms 600 KB Output is correct
29 Correct 100 ms 600 KB Output is correct
30 Correct 39 ms 604 KB Output is correct
31 Correct 34 ms 600 KB Output is correct
32 Correct 33 ms 604 KB Output is correct
33 Correct 33 ms 604 KB Output is correct
34 Correct 43 ms 604 KB Output is correct
35 Correct 103 ms 600 KB Output is correct
36 Correct 105 ms 600 KB Output is correct
37 Correct 85 ms 604 KB Output is correct
38 Correct 34 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 110 ms 796 KB Output is correct
26 Correct 80 ms 600 KB Output is correct
27 Correct 32 ms 604 KB Output is correct
28 Correct 95 ms 600 KB Output is correct
29 Correct 100 ms 600 KB Output is correct
30 Correct 39 ms 604 KB Output is correct
31 Correct 34 ms 600 KB Output is correct
32 Correct 33 ms 604 KB Output is correct
33 Correct 33 ms 604 KB Output is correct
34 Correct 43 ms 604 KB Output is correct
35 Correct 103 ms 600 KB Output is correct
36 Correct 105 ms 600 KB Output is correct
37 Correct 85 ms 604 KB Output is correct
38 Correct 34 ms 604 KB Output is correct
39 Execution timed out 2028 ms 1880 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 32 ms 604 KB Output is correct
10 Correct 100 ms 604 KB Output is correct
11 Correct 39 ms 604 KB Output is correct
12 Correct 34 ms 604 KB Output is correct
13 Correct 34 ms 604 KB Output is correct
14 Correct 106 ms 600 KB Output is correct
15 Execution timed out 2024 ms 1880 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 79 ms 604 KB Output is correct
9 Correct 31 ms 600 KB Output is correct
10 Correct 100 ms 604 KB Output is correct
11 Correct 37 ms 600 KB Output is correct
12 Execution timed out 2005 ms 1884 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 0 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 110 ms 796 KB Output is correct
26 Correct 80 ms 600 KB Output is correct
27 Correct 32 ms 604 KB Output is correct
28 Correct 95 ms 600 KB Output is correct
29 Correct 100 ms 600 KB Output is correct
30 Correct 39 ms 604 KB Output is correct
31 Correct 34 ms 600 KB Output is correct
32 Correct 33 ms 604 KB Output is correct
33 Correct 33 ms 604 KB Output is correct
34 Correct 43 ms 604 KB Output is correct
35 Correct 103 ms 600 KB Output is correct
36 Correct 105 ms 600 KB Output is correct
37 Correct 85 ms 604 KB Output is correct
38 Correct 34 ms 604 KB Output is correct
39 Execution timed out 2028 ms 1880 KB Time limit exceeded
40 Halted 0 ms 0 KB -