Submission #1033774

# Submission time Handle Problem Language Result Execution time Memory
1033774 2024-07-25T05:36:08 Z 김은성(#10970) Fire (BOI24_fire) C++17
100 / 100
149 ms 54364 KB
#include <bits/stdc++.h>
using namespace std;
int sp[20][400009];
vector<int> start[400009];
int main(){
    int n, m, i, j, s, e;
    scanf("%d %d", &n, &m);
    vector<pair<int, int> > a;
    vector<pair<int, int> > query;
    vector<int> vec;
    int ans = 1000 * n;
    for(i=0; i<n; i++){
        scanf("%d %d", &s, &e);
        if(s<e)
            a.push_back(make_pair(s, e));
        else
            query.push_back(make_pair(e, s));
        vec.push_back(s);
        vec.push_back(e);
    }
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    int sz = vec.size();
    for(i=0; i<a.size(); i++){
        a[i].first = lower_bound(vec.begin(), vec.end(), a[i].first) - vec.begin();
        a[i].second = lower_bound(vec.begin(), vec.end(), a[i].second) - vec.begin();
    }
    for(i=0; i<query.size(); i++){
        query[i].first = lower_bound(vec.begin(), vec.end(), query[i].first) - vec.begin();
        query[i].second = lower_bound(vec.begin(), vec.end(), query[i].second) - vec.begin();
    }
    for(i=0; i<a.size(); i++)
        start[a[i].first].push_back(a[i].second);
    int mx = 0;
    for(i=0; i<sz; i++){
        for(j=0; j<start[i].size(); j++)
            mx = max(mx, start[i][j]);
        sp[0][i] = mx;
        //printf("i=%d sp=%d\n", i, sp[0][i]);
    }
    for(i=1; i<20; i++){
        for(j=0; j<sz; j++){
            sp[i][j] = sp[i-1][sp[i-1][j]];
        }
    }
    for(i=0; i<query.size(); i++){
        int s = query[i].first, e = query[i].second, cnt = 0;
        for(j=19; j>=0; j--){
            if(sp[j][s] < e){
                cnt += (1<<j);
                s = sp[j][s];
            }
        }
        if(s >= e)
            ans = min(ans, cnt+1);
        else if(sp[0][s] >= e){
            cnt++;
            ans = min(ans, cnt+1);
        }
    }
    if(ans == 1000 * n)
        ans = -1;
    printf("%d\n", ans);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(i=0; i<a.size(); i++){
      |              ~^~~~~~~~~
Main.cpp:28:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(i=0; i<query.size(); i++){
      |              ~^~~~~~~~~~~~~
Main.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(i=0; i<a.size(); i++)
      |              ~^~~~~~~~~
Main.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(j=0; j<start[i].size(); j++)
      |                  ~^~~~~~~~~~~~~~~~
Main.cpp:46:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(i=0; i<query.size(); i++){
      |              ~^~~~~~~~~~~~~
Main.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d %d", &s, &e);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 3 ms 21084 KB Output is correct
10 Correct 3 ms 23132 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21124 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 3 ms 21080 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 3 ms 21084 KB Output is correct
20 Correct 3 ms 21080 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 3 ms 19036 KB Output is correct
23 Correct 3 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 3 ms 21084 KB Output is correct
10 Correct 3 ms 23132 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21124 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 3 ms 21080 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 3 ms 21084 KB Output is correct
20 Correct 3 ms 21080 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 3 ms 19036 KB Output is correct
23 Correct 3 ms 21084 KB Output is correct
24 Correct 2 ms 19036 KB Output is correct
25 Correct 3 ms 21084 KB Output is correct
26 Correct 3 ms 19072 KB Output is correct
27 Correct 3 ms 21084 KB Output is correct
28 Correct 3 ms 21084 KB Output is correct
29 Correct 3 ms 21084 KB Output is correct
30 Correct 3 ms 23172 KB Output is correct
31 Correct 3 ms 23132 KB Output is correct
32 Correct 3 ms 21080 KB Output is correct
33 Correct 2 ms 21084 KB Output is correct
34 Correct 2 ms 21084 KB Output is correct
35 Correct 4 ms 21084 KB Output is correct
36 Correct 3 ms 21084 KB Output is correct
37 Correct 3 ms 21084 KB Output is correct
38 Correct 3 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 3 ms 21084 KB Output is correct
10 Correct 3 ms 23132 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21124 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 3 ms 21080 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 3 ms 21084 KB Output is correct
20 Correct 3 ms 21080 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 3 ms 19036 KB Output is correct
23 Correct 3 ms 21084 KB Output is correct
24 Correct 2 ms 19036 KB Output is correct
25 Correct 3 ms 21084 KB Output is correct
26 Correct 3 ms 19072 KB Output is correct
27 Correct 3 ms 21084 KB Output is correct
28 Correct 3 ms 21084 KB Output is correct
29 Correct 3 ms 21084 KB Output is correct
30 Correct 3 ms 23172 KB Output is correct
31 Correct 3 ms 23132 KB Output is correct
32 Correct 3 ms 21080 KB Output is correct
33 Correct 2 ms 21084 KB Output is correct
34 Correct 2 ms 21084 KB Output is correct
35 Correct 4 ms 21084 KB Output is correct
36 Correct 3 ms 21084 KB Output is correct
37 Correct 3 ms 21084 KB Output is correct
38 Correct 3 ms 21084 KB Output is correct
39 Correct 5 ms 21852 KB Output is correct
40 Correct 5 ms 21852 KB Output is correct
41 Correct 5 ms 21864 KB Output is correct
42 Correct 5 ms 21596 KB Output is correct
43 Correct 4 ms 21648 KB Output is correct
44 Correct 5 ms 21596 KB Output is correct
45 Correct 5 ms 21644 KB Output is correct
46 Correct 5 ms 19804 KB Output is correct
47 Correct 5 ms 21900 KB Output is correct
48 Correct 5 ms 21852 KB Output is correct
49 Correct 4 ms 19844 KB Output is correct
50 Correct 5 ms 21764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 2 ms 21084 KB Output is correct
4 Correct 3 ms 19036 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 2 ms 21092 KB Output is correct
8 Correct 3 ms 21084 KB Output is correct
9 Correct 3 ms 19056 KB Output is correct
10 Correct 3 ms 21084 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21088 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21084 KB Output is correct
15 Correct 6 ms 21852 KB Output is correct
16 Correct 4 ms 19548 KB Output is correct
17 Correct 5 ms 21596 KB Output is correct
18 Correct 5 ms 21596 KB Output is correct
19 Correct 6 ms 23900 KB Output is correct
20 Correct 31 ms 25936 KB Output is correct
21 Correct 135 ms 54184 KB Output is correct
22 Correct 135 ms 54336 KB Output is correct
23 Correct 116 ms 44012 KB Output is correct
24 Correct 140 ms 54172 KB Output is correct
25 Correct 104 ms 40432 KB Output is correct
26 Correct 116 ms 44976 KB Output is correct
27 Correct 113 ms 44148 KB Output is correct
28 Correct 129 ms 53920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23132 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 19036 KB Output is correct
4 Correct 2 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 19036 KB Output is correct
8 Correct 3 ms 21084 KB Output is correct
9 Correct 3 ms 19036 KB Output is correct
10 Correct 3 ms 21084 KB Output is correct
11 Correct 3 ms 19036 KB Output is correct
12 Correct 5 ms 22004 KB Output is correct
13 Correct 6 ms 23692 KB Output is correct
14 Correct 5 ms 21596 KB Output is correct
15 Correct 31 ms 25916 KB Output is correct
16 Correct 111 ms 42408 KB Output is correct
17 Correct 139 ms 54224 KB Output is correct
18 Correct 149 ms 53672 KB Output is correct
19 Correct 125 ms 54196 KB Output is correct
20 Correct 112 ms 45288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 23128 KB Output is correct
2 Correct 3 ms 21084 KB Output is correct
3 Correct 3 ms 21084 KB Output is correct
4 Correct 3 ms 21084 KB Output is correct
5 Correct 3 ms 21084 KB Output is correct
6 Correct 3 ms 21084 KB Output is correct
7 Correct 3 ms 21084 KB Output is correct
8 Correct 2 ms 21084 KB Output is correct
9 Correct 3 ms 21084 KB Output is correct
10 Correct 3 ms 23132 KB Output is correct
11 Correct 3 ms 21084 KB Output is correct
12 Correct 3 ms 21084 KB Output is correct
13 Correct 3 ms 21084 KB Output is correct
14 Correct 3 ms 21124 KB Output is correct
15 Correct 3 ms 21084 KB Output is correct
16 Correct 2 ms 21084 KB Output is correct
17 Correct 3 ms 21080 KB Output is correct
18 Correct 3 ms 21084 KB Output is correct
19 Correct 3 ms 21084 KB Output is correct
20 Correct 3 ms 21080 KB Output is correct
21 Correct 3 ms 23132 KB Output is correct
22 Correct 3 ms 19036 KB Output is correct
23 Correct 3 ms 21084 KB Output is correct
24 Correct 2 ms 19036 KB Output is correct
25 Correct 3 ms 21084 KB Output is correct
26 Correct 3 ms 19072 KB Output is correct
27 Correct 3 ms 21084 KB Output is correct
28 Correct 3 ms 21084 KB Output is correct
29 Correct 3 ms 21084 KB Output is correct
30 Correct 3 ms 23172 KB Output is correct
31 Correct 3 ms 23132 KB Output is correct
32 Correct 3 ms 21080 KB Output is correct
33 Correct 2 ms 21084 KB Output is correct
34 Correct 2 ms 21084 KB Output is correct
35 Correct 4 ms 21084 KB Output is correct
36 Correct 3 ms 21084 KB Output is correct
37 Correct 3 ms 21084 KB Output is correct
38 Correct 3 ms 21084 KB Output is correct
39 Correct 5 ms 21852 KB Output is correct
40 Correct 5 ms 21852 KB Output is correct
41 Correct 5 ms 21864 KB Output is correct
42 Correct 5 ms 21596 KB Output is correct
43 Correct 4 ms 21648 KB Output is correct
44 Correct 5 ms 21596 KB Output is correct
45 Correct 5 ms 21644 KB Output is correct
46 Correct 5 ms 19804 KB Output is correct
47 Correct 5 ms 21900 KB Output is correct
48 Correct 5 ms 21852 KB Output is correct
49 Correct 4 ms 19844 KB Output is correct
50 Correct 5 ms 21764 KB Output is correct
51 Correct 3 ms 19036 KB Output is correct
52 Correct 3 ms 21084 KB Output is correct
53 Correct 2 ms 21084 KB Output is correct
54 Correct 3 ms 19036 KB Output is correct
55 Correct 3 ms 21084 KB Output is correct
56 Correct 3 ms 21084 KB Output is correct
57 Correct 2 ms 21092 KB Output is correct
58 Correct 3 ms 21084 KB Output is correct
59 Correct 3 ms 19056 KB Output is correct
60 Correct 3 ms 21084 KB Output is correct
61 Correct 3 ms 21084 KB Output is correct
62 Correct 3 ms 21088 KB Output is correct
63 Correct 3 ms 21084 KB Output is correct
64 Correct 3 ms 21084 KB Output is correct
65 Correct 6 ms 21852 KB Output is correct
66 Correct 4 ms 19548 KB Output is correct
67 Correct 5 ms 21596 KB Output is correct
68 Correct 5 ms 21596 KB Output is correct
69 Correct 6 ms 23900 KB Output is correct
70 Correct 31 ms 25936 KB Output is correct
71 Correct 135 ms 54184 KB Output is correct
72 Correct 135 ms 54336 KB Output is correct
73 Correct 116 ms 44012 KB Output is correct
74 Correct 140 ms 54172 KB Output is correct
75 Correct 104 ms 40432 KB Output is correct
76 Correct 116 ms 44976 KB Output is correct
77 Correct 113 ms 44148 KB Output is correct
78 Correct 129 ms 53920 KB Output is correct
79 Correct 3 ms 23132 KB Output is correct
80 Correct 3 ms 21084 KB Output is correct
81 Correct 3 ms 19036 KB Output is correct
82 Correct 2 ms 21084 KB Output is correct
83 Correct 3 ms 21084 KB Output is correct
84 Correct 3 ms 21084 KB Output is correct
85 Correct 3 ms 19036 KB Output is correct
86 Correct 3 ms 21084 KB Output is correct
87 Correct 3 ms 19036 KB Output is correct
88 Correct 3 ms 21084 KB Output is correct
89 Correct 3 ms 19036 KB Output is correct
90 Correct 5 ms 22004 KB Output is correct
91 Correct 6 ms 23692 KB Output is correct
92 Correct 5 ms 21596 KB Output is correct
93 Correct 31 ms 25916 KB Output is correct
94 Correct 111 ms 42408 KB Output is correct
95 Correct 139 ms 54224 KB Output is correct
96 Correct 149 ms 53672 KB Output is correct
97 Correct 125 ms 54196 KB Output is correct
98 Correct 112 ms 45288 KB Output is correct
99 Correct 130 ms 54364 KB Output is correct
100 Correct 133 ms 54228 KB Output is correct
101 Correct 120 ms 54188 KB Output is correct
102 Correct 131 ms 54196 KB Output is correct
103 Correct 114 ms 46336 KB Output is correct
104 Correct 136 ms 53472 KB Output is correct
105 Correct 87 ms 52912 KB Output is correct