Submission #1080431

# Submission time Handle Problem Language Result Execution time Memory
1080431 2024-08-29T09:52:55 Z Arturgo Fire (BOI24_fire) C++14
100 / 100
669 ms 113920 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int DEBUT = -1;
const int FIN = 1;

struct Event {
    int pos, id, type, data;
};

bool operator < (const Event& a, const Event& b) {
    if(a.pos == b.pos) return a.type < b.type;
    return a.pos < b.pos;
}

int nbInters, nbCoords;

int nbProjs = 0;
vector<pair<int, int>> inters;
vector<Event> events;

void ajoute_inter(int deb, int fin) {
    inters.push_back({deb, fin});
    events.push_back({deb, nbProjs, DEBUT, fin});
    events.push_back({fin, nbProjs, FIN, -1});
    nbProjs++;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin >> nbInters >> nbCoords;

    for(int iInter = 0;iInter < nbInters;iInter++) {
        int deb, fin;
        cin >> deb >> fin;
        if(fin < deb) fin += nbCoords;
        ajoute_inter(deb, fin);
        ajoute_inter(deb + nbCoords, fin + nbCoords);
    }

    sort(events.begin(), events.end());

    vector<vector<int>> suivs(nbProjs, vector<int>(20, -1));

    pair<int, int> meilleureFin = {-1, -1}; // pos, id
    for(Event& ev : events) {
        if(ev.type == DEBUT) {
            if(ev.data > meilleureFin.first) {
                meilleureFin.first = ev.data;
                meilleureFin.second = ev.id;
            }
        } else if(ev.type == FIN) {
            if(meilleureFin.first > ev.pos) {
                suivs[ev.id][0] = meilleureFin.second;
            }
        }
    }

    for(int puis = 1;puis < 20;puis++) {
        for(int iProj = 0;iProj < nbProjs;iProj++) {
            if(suivs[iProj][puis - 1] != -1) {
                suivs[iProj][puis] = suivs[suivs[iProj][puis - 1]][puis - 1];
            }
        }
    }

    int minSelects = 1e9;
    for(int iProj = 0;iProj < nbProjs;iProj++) {
        int debActuel = inters[iProj].first;
        int nbSelects = 1;

        int iFin = iProj;
        for(int puis = 19;puis >= 0;puis--) {
            if(suivs[iFin][puis] == -1) continue;
            int finActuel = inters[suivs[iFin][puis]].second;
            if(finActuel < debActuel + nbCoords) {
                nbSelects += (1 << puis);
                iFin = suivs[iFin][puis];
            }
        }

        if(suivs[iFin][0] != -1) {
            minSelects = min(minSelects, nbSelects + 1);
        }
    }

    if(minSelects == 1e9) cout << -1 << endl;
    else cout << minSelects << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 0 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 412 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 0 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 412 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 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 604 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 600 KB Output is correct
31 Correct 1 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 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 1 ms 608 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 0 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 412 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 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 604 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 600 KB Output is correct
31 Correct 1 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 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 1 ms 608 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 6 ms 3164 KB Output is correct
40 Correct 6 ms 3156 KB Output is correct
41 Correct 6 ms 3160 KB Output is correct
42 Correct 7 ms 3248 KB Output is correct
43 Correct 5 ms 3160 KB Output is correct
44 Correct 6 ms 3152 KB Output is correct
45 Correct 7 ms 3156 KB Output is correct
46 Correct 7 ms 3324 KB Output is correct
47 Correct 6 ms 3156 KB Output is correct
48 Correct 5 ms 3156 KB Output is correct
49 Correct 5 ms 3156 KB Output is correct
50 Correct 6 ms 3156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 356 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 352 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 600 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 1 ms 600 KB Output is correct
15 Correct 5 ms 3084 KB Output is correct
16 Correct 10 ms 3280 KB Output is correct
17 Correct 5 ms 3264 KB Output is correct
18 Correct 6 ms 3156 KB Output is correct
19 Correct 5 ms 3156 KB Output is correct
20 Correct 178 ms 110648 KB Output is correct
21 Correct 349 ms 113820 KB Output is correct
22 Correct 278 ms 113908 KB Output is correct
23 Correct 591 ms 112884 KB Output is correct
24 Correct 446 ms 113912 KB Output is correct
25 Correct 228 ms 113148 KB Output is correct
26 Correct 457 ms 113912 KB Output is correct
27 Correct 619 ms 113908 KB Output is correct
28 Correct 342 ms 113912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 604 KB Output is correct
9 Correct 1 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 5 ms 3156 KB Output is correct
13 Correct 6 ms 3156 KB Output is correct
14 Correct 6 ms 3152 KB Output is correct
15 Correct 179 ms 110692 KB Output is correct
16 Correct 669 ms 112892 KB Output is correct
17 Correct 342 ms 113736 KB Output is correct
18 Correct 293 ms 113908 KB Output is correct
19 Correct 464 ms 113652 KB Output is correct
20 Correct 615 ms 112732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 0 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 412 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 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 604 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 600 KB Output is correct
31 Correct 1 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 604 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 608 KB Output is correct
37 Correct 1 ms 608 KB Output is correct
38 Correct 1 ms 464 KB Output is correct
39 Correct 6 ms 3164 KB Output is correct
40 Correct 6 ms 3156 KB Output is correct
41 Correct 6 ms 3160 KB Output is correct
42 Correct 7 ms 3248 KB Output is correct
43 Correct 5 ms 3160 KB Output is correct
44 Correct 6 ms 3152 KB Output is correct
45 Correct 7 ms 3156 KB Output is correct
46 Correct 7 ms 3324 KB Output is correct
47 Correct 6 ms 3156 KB Output is correct
48 Correct 5 ms 3156 KB Output is correct
49 Correct 5 ms 3156 KB Output is correct
50 Correct 6 ms 3156 KB Output is correct
51 Correct 1 ms 356 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 352 KB Output is correct
55 Correct 0 ms 344 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 452 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 604 KB Output is correct
60 Correct 1 ms 600 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 604 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 600 KB Output is correct
65 Correct 5 ms 3084 KB Output is correct
66 Correct 10 ms 3280 KB Output is correct
67 Correct 5 ms 3264 KB Output is correct
68 Correct 6 ms 3156 KB Output is correct
69 Correct 5 ms 3156 KB Output is correct
70 Correct 178 ms 110648 KB Output is correct
71 Correct 349 ms 113820 KB Output is correct
72 Correct 278 ms 113908 KB Output is correct
73 Correct 591 ms 112884 KB Output is correct
74 Correct 446 ms 113912 KB Output is correct
75 Correct 228 ms 113148 KB Output is correct
76 Correct 457 ms 113912 KB Output is correct
77 Correct 619 ms 113908 KB Output is correct
78 Correct 342 ms 113912 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 0 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 1 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 604 KB Output is correct
88 Correct 2 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 5 ms 3156 KB Output is correct
91 Correct 6 ms 3156 KB Output is correct
92 Correct 6 ms 3152 KB Output is correct
93 Correct 179 ms 110692 KB Output is correct
94 Correct 669 ms 112892 KB Output is correct
95 Correct 342 ms 113736 KB Output is correct
96 Correct 293 ms 113908 KB Output is correct
97 Correct 464 ms 113652 KB Output is correct
98 Correct 615 ms 112732 KB Output is correct
99 Correct 300 ms 113912 KB Output is correct
100 Correct 276 ms 113844 KB Output is correct
101 Correct 562 ms 113716 KB Output is correct
102 Correct 504 ms 113912 KB Output is correct
103 Correct 524 ms 113736 KB Output is correct
104 Correct 355 ms 113920 KB Output is correct
105 Correct 238 ms 112632 KB Output is correct