답안 #1080554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080554 2024-08-29T10:54:25 Z abouton Fire (BOI24_fire) C++17
100 / 100
462 ms 106492 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

struct ev
{
    int pos, type, id, fin;
    bool operator<(const ev &autre) const
    {
        if (pos == autre.pos) return type < autre.type;
        return pos < autre.pos;
    }
};
const int LOG = 20, PUIS = (1<<20);
const int DEB = -1, FIN = 1;

int N, mod;
int nbI;
int suivs[4*(int)1e5 + 42][LOG];
vector<ev> tri;
vector<pair<int,int>> inters;

void aj(int d, int f)
{
    inters.push_back({d, f});
    tri.push_back({d, DEB, nbI, f});
    tri.push_back({f, FIN, nbI, -1});
    nbI++;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin >> N >> mod;

    for (int i = 0; i < N; i ++)
    {
        int d, f;
        cin >> d >> f;
        if (f<d) f += mod;
        aj(d, f);
        aj(d+mod,f+mod);
    }
    for (int i = 0; i < nbI; i ++)
    {
        for (int j = 0; j < 20;j ++)
        {
            suivs[i][j] = -1;
        }
    }
    sort(tri.begin(), tri.end());
    int ind=-1, maxi=-1;
    for (auto i : tri)
    {
        if (i.type == DEB)
        {
            if (i.fin > maxi)
            {
                maxi = i.fin;
                ind = i.id;
            }
        }
        if (i.type == FIN)
        {
            if (maxi > i.pos) suivs[i.id][0] = ind;
        }
    }
    
    for (int l = 1; l < 20; l ++)
    {
        for (int i = 0; i < nbI; i ++)
        {
            if (suivs[i][l-1] != -1) suivs[i][l] = suivs[suivs[i][l-1]][l-1];
        }
    }

    int mini = 1e9;
    for (int i = 0; i < nbI; i ++)
    {
        int curPos = i;
        int deb = inters[i].first;
        int nbS = 1;
        for (int av = 19; av >= 0; av --)
        {
            if (suivs[curPos][av] == -1) continue;
            if (inters[suivs[curPos][av]].second < deb+mod) {curPos = suivs[curPos][av];nbS += (1<<av);}
            //if (i == 2){cout <<av<<' ' <<curPos<<inters[suivs[curPos][av]].second << ' '<<nbS <<'\n';}
        }
        if (suivs[curPos][0] != -1) mini = min(mini, nbS+1);
    }
    if (mini == (int)1e9) mini = -1;

    cout << mini << '\n';
    //for (int i = 0; i < nbI; i ++) cout << suivs[i][2] << ' ';
}
# 결과 실행 시간 메모리 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 464 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 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 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 1 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 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 464 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 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 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 1 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 0 ms 600 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 416 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 0 ms 604 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 464 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 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 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 1 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 0 ms 600 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 416 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 0 ms 604 KB Output is correct
39 Correct 4 ms 3668 KB Output is correct
40 Correct 5 ms 3156 KB Output is correct
41 Correct 4 ms 3668 KB Output is correct
42 Correct 5 ms 3028 KB Output is correct
43 Correct 5 ms 3156 KB Output is correct
44 Correct 5 ms 3668 KB Output is correct
45 Correct 5 ms 3156 KB Output is correct
46 Correct 5 ms 3152 KB Output is correct
47 Correct 5 ms 3156 KB Output is correct
48 Correct 4 ms 3156 KB Output is correct
49 Correct 4 ms 2900 KB Output is correct
50 Correct 5 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 460 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 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 0 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 5 ms 3028 KB Output is correct
16 Correct 5 ms 2900 KB Output is correct
17 Correct 4 ms 3096 KB Output is correct
18 Correct 6 ms 3152 KB Output is correct
19 Correct 4 ms 3152 KB Output is correct
20 Correct 159 ms 103304 KB Output is correct
21 Correct 249 ms 106232 KB Output is correct
22 Correct 231 ms 106236 KB Output is correct
23 Correct 462 ms 105308 KB Output is correct
24 Correct 323 ms 106444 KB Output is correct
25 Correct 195 ms 105724 KB Output is correct
26 Correct 302 ms 106492 KB Output is correct
27 Correct 430 ms 106364 KB Output is correct
28 Correct 256 ms 106364 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 460 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 604 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 4 ms 3668 KB Output is correct
13 Correct 5 ms 2900 KB Output is correct
14 Correct 5 ms 2900 KB Output is correct
15 Correct 158 ms 103160 KB Output is correct
16 Correct 402 ms 105460 KB Output is correct
17 Correct 271 ms 106228 KB Output is correct
18 Correct 224 ms 106444 KB Output is correct
19 Correct 333 ms 106192 KB Output is correct
20 Correct 412 ms 105460 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 464 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 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 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 1 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 0 ms 600 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 0 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 416 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 0 ms 604 KB Output is correct
39 Correct 4 ms 3668 KB Output is correct
40 Correct 5 ms 3156 KB Output is correct
41 Correct 4 ms 3668 KB Output is correct
42 Correct 5 ms 3028 KB Output is correct
43 Correct 5 ms 3156 KB Output is correct
44 Correct 5 ms 3668 KB Output is correct
45 Correct 5 ms 3156 KB Output is correct
46 Correct 5 ms 3152 KB Output is correct
47 Correct 5 ms 3156 KB Output is correct
48 Correct 4 ms 3156 KB Output is correct
49 Correct 4 ms 2900 KB Output is correct
50 Correct 5 ms 2900 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 0 ms 460 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 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 0 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 0 ms 604 KB Output is correct
64 Correct 1 ms 604 KB Output is correct
65 Correct 5 ms 3028 KB Output is correct
66 Correct 5 ms 2900 KB Output is correct
67 Correct 4 ms 3096 KB Output is correct
68 Correct 6 ms 3152 KB Output is correct
69 Correct 4 ms 3152 KB Output is correct
70 Correct 159 ms 103304 KB Output is correct
71 Correct 249 ms 106232 KB Output is correct
72 Correct 231 ms 106236 KB Output is correct
73 Correct 462 ms 105308 KB Output is correct
74 Correct 323 ms 106444 KB Output is correct
75 Correct 195 ms 105724 KB Output is correct
76 Correct 302 ms 106492 KB Output is correct
77 Correct 430 ms 106364 KB Output is correct
78 Correct 256 ms 106364 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 0 ms 348 KB Output is correct
81 Correct 0 ms 460 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 0 ms 348 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 600 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 4 ms 3668 KB Output is correct
91 Correct 5 ms 2900 KB Output is correct
92 Correct 5 ms 2900 KB Output is correct
93 Correct 158 ms 103160 KB Output is correct
94 Correct 402 ms 105460 KB Output is correct
95 Correct 271 ms 106228 KB Output is correct
96 Correct 224 ms 106444 KB Output is correct
97 Correct 333 ms 106192 KB Output is correct
98 Correct 412 ms 105460 KB Output is correct
99 Correct 240 ms 106252 KB Output is correct
100 Correct 210 ms 106236 KB Output is correct
101 Correct 394 ms 106388 KB Output is correct
102 Correct 371 ms 106340 KB Output is correct
103 Correct 398 ms 106236 KB Output is correct
104 Correct 273 ms 106236 KB Output is correct
105 Correct 200 ms 105208 KB Output is correct