Submission #1095802

# Submission time Handle Problem Language Result Execution time Memory
1095802 2024-10-03T07:56:53 Z SalihSahin Fire (BOI24_fire) C++14
40 / 100
2000 ms 174160 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

const int N = 2e5 + 5;
const int K = 20;
const int mod = 1e9 + 7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin>>n>>m;
    vector<pair<int, int> > a(n);
    set<int> st;
    for(int i = 0; i < n; i++){
        cin>>a[i].first>>a[i].second;
        st.insert(a[i].first);
        st.insert(a[i].second);
        st.insert(a[i].first + m);
        st.insert(a[i].second + m);
    }
    map<int, int> pos;
    int here = 0;
    for(auto itr: st){
        pos[itr] = ++here;
    }

    vector<int> upd(here + 1);
    for(int i = 0; i < n; i++){
        int f = a[i].first, s = a[i].second;
        if(f > s){
            upd[pos[f]] = max(upd[pos[f]], s + m);
        }
        else{
            upd[pos[f]] = max(upd[pos[f]], s);
            upd[pos[f + m]] = max(upd[pos[f]], s + m);
        }
    }
    vector<vector<int> > lift(here + 1, vector<int>(K));
    int val = 0;

    for(auto itr: st){
        val = max(val, upd[pos[itr]]);
        lift[pos[itr]][0] = val;
    }
    
    for(int i = 1; i < K; i++){
        for(int j = 1; j <= here; j++){
            lift[j][i] = lift[pos[lift[j][i-1]]][i-1];
        }
    }

    int ans = n + 23;
    for(int st = 0; st < n; st++){
        int f = a[st].first;
        int cnt = 0;
        bool ok = 1;
        int r = f;
        
        for(int bt = K-1; bt >= 0; bt--){
            if(lift[pos[r]][bt] - f < m){
                cnt += (1 << bt);
                r = lift[pos[r]][bt];
            }
        }

        if(lift[pos[r]][0] - f >= m) ans = min(ans, cnt + 1);
    }

    if(ans == n + 23) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:58:14: warning: unused variable 'ok' [-Wunused-variable]
   58 |         bool ok = 1;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 0 ms 344 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 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 0 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 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 0 ms 344 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 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 0 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 0 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 0 ms 344 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 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 0 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 0 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 35 ms 4700 KB Output is correct
40 Correct 44 ms 4756 KB Output is correct
41 Correct 40 ms 4700 KB Output is correct
42 Correct 25 ms 2652 KB Output is correct
43 Correct 19 ms 2136 KB Output is correct
44 Correct 26 ms 2652 KB Output is correct
45 Correct 24 ms 2652 KB Output is correct
46 Correct 26 ms 2680 KB Output is correct
47 Correct 34 ms 4696 KB Output is correct
48 Correct 32 ms 4696 KB Output is correct
49 Correct 30 ms 4700 KB Output is correct
50 Correct 24 ms 2648 KB Output is correct
# Verdict Execution time Memory 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 1 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 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 39 ms 4716 KB Output is correct
16 Correct 27 ms 2652 KB Output is correct
17 Correct 19 ms 2140 KB Output is correct
18 Correct 26 ms 2652 KB Output is correct
19 Correct 35 ms 4696 KB Output is correct
20 Correct 36 ms 1880 KB Output is correct
21 Execution timed out 2033 ms 174160 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 2 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 608 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 38 ms 4668 KB Output is correct
13 Correct 26 ms 2648 KB Output is correct
14 Correct 24 ms 2652 KB Output is correct
15 Correct 35 ms 1880 KB Output is correct
16 Execution timed out 2033 ms 88076 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 0 ms 344 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 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 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 0 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 0 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 35 ms 4700 KB Output is correct
40 Correct 44 ms 4756 KB Output is correct
41 Correct 40 ms 4700 KB Output is correct
42 Correct 25 ms 2652 KB Output is correct
43 Correct 19 ms 2136 KB Output is correct
44 Correct 26 ms 2652 KB Output is correct
45 Correct 24 ms 2652 KB Output is correct
46 Correct 26 ms 2680 KB Output is correct
47 Correct 34 ms 4696 KB Output is correct
48 Correct 32 ms 4696 KB Output is correct
49 Correct 30 ms 4700 KB Output is correct
50 Correct 24 ms 2648 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 1 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 1 ms 348 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 39 ms 4716 KB Output is correct
66 Correct 27 ms 2652 KB Output is correct
67 Correct 19 ms 2140 KB Output is correct
68 Correct 26 ms 2652 KB Output is correct
69 Correct 35 ms 4696 KB Output is correct
70 Correct 36 ms 1880 KB Output is correct
71 Execution timed out 2033 ms 174160 KB Time limit exceeded
72 Halted 0 ms 0 KB -