답안 #1095800

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095800 2024-10-03T07:53:14 Z SalihSahin Fire (BOI24_fire) C++14
40 / 100
2000 ms 212464 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;
    }

    map<int, int> upd;
    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){
        if(upd[pos[itr]]) 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;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 1 ms 768 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 712 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 1 ms 768 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 712 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 45 ms 5624 KB Output is correct
40 Correct 47 ms 5720 KB Output is correct
41 Correct 43 ms 5468 KB Output is correct
42 Correct 31 ms 2904 KB Output is correct
43 Correct 22 ms 2648 KB Output is correct
44 Correct 30 ms 3164 KB Output is correct
45 Correct 31 ms 3412 KB Output is correct
46 Correct 31 ms 3164 KB Output is correct
47 Correct 45 ms 5720 KB Output is correct
48 Correct 39 ms 5704 KB Output is correct
49 Correct 37 ms 5724 KB Output is correct
50 Correct 30 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 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 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 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 600 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 45 ms 5652 KB Output is correct
16 Correct 30 ms 2908 KB Output is correct
17 Correct 23 ms 2648 KB Output is correct
18 Correct 29 ms 3164 KB Output is correct
19 Correct 40 ms 5656 KB Output is correct
20 Correct 40 ms 2652 KB Output is correct
21 Execution timed out 2054 ms 212464 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 44 ms 5684 KB Output is correct
13 Correct 30 ms 3320 KB Output is correct
14 Correct 30 ms 2908 KB Output is correct
15 Correct 38 ms 2648 KB Output is correct
16 Execution timed out 2073 ms 108116 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
7 Correct 0 ms 456 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 768 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 2 ms 856 KB Output is correct
35 Correct 1 ms 768 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 1 ms 712 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 45 ms 5624 KB Output is correct
40 Correct 47 ms 5720 KB Output is correct
41 Correct 43 ms 5468 KB Output is correct
42 Correct 31 ms 2904 KB Output is correct
43 Correct 22 ms 2648 KB Output is correct
44 Correct 30 ms 3164 KB Output is correct
45 Correct 31 ms 3412 KB Output is correct
46 Correct 31 ms 3164 KB Output is correct
47 Correct 45 ms 5720 KB Output is correct
48 Correct 39 ms 5704 KB Output is correct
49 Correct 37 ms 5724 KB Output is correct
50 Correct 30 ms 2908 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 604 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 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 600 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 45 ms 5652 KB Output is correct
66 Correct 30 ms 2908 KB Output is correct
67 Correct 23 ms 2648 KB Output is correct
68 Correct 29 ms 3164 KB Output is correct
69 Correct 40 ms 5656 KB Output is correct
70 Correct 40 ms 2652 KB Output is correct
71 Execution timed out 2054 ms 212464 KB Time limit exceeded
72 Halted 0 ms 0 KB -