Submission #1067293

# Submission time Handle Problem Language Result Execution time Memory
1067293 2024-08-20T14:09:10 Z slivajan Fire (BOI24_fire) C++17
100 / 100
351 ms 43056 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long un;
typedef vector<un> vuc;
typedef pair<un, un> pun;

#define REP(i, a, b) for (un i = (un)a; i < (un)b; i++)
#define FEAC(i, a) for (auto&& i : a)
#define vec vector
#define ALL(x) (x).begin(), (x).end()
#define DEB(x) cerr << #x << " = " << (x) << endl;


int main(){
    un N, M;
    cin >> N >> M;

    vec<pun> vstup;
    map<un, un> mapa;

    REP(i, 0, N){
        un a, b;
        cin >> a >> b;
        vstup.push_back({a, b});
        mapa[a] = 0;
        mapa[b] = 0;
    }


    vuc imapa;
    un counter = 0;
    FEAC(kv, mapa){
        un key;
        tie(key, ignore) = kv;
        mapa[key] = counter;
        counter++;

        imapa.push_back(key);

    }

    sort(ALL(vstup));

    un K = imapa.size();
    vuc delky(K, 0);


    FEAC(kd, vstup){
        un key, destination;
        tie(key, destination) = kd;
        
        delky[mapa[key]] = (M+destination-key) % M;
    }

    un curr = 0;
    REP(ign, 0, 2){
        REP(i, 0, K){
            curr -= (M+imapa[i] - imapa[(K+i-1)%K]) % M;
            curr = max(curr, delky[i]);
            delky[i] = curr;
        }
    }

    vuc visited(K, 0);

    un ptr = 0;
    un time = 1;
    while(not visited[ptr]){
        visited[ptr] = time;
        if (delky[ptr] == 0) {
            cout << -1 << endl;
            return 0;
        }
        ptr = mapa[(imapa[ptr] + delky[ptr]) % M];
        time++;
    }

    un ret = 2;
    un goal = ptr;
    ptr = mapa[(imapa[ptr] + delky[ptr]) % M];
    un next_ptr = mapa[(imapa[ptr] + delky[ptr]) % M];

    while(((M + imapa[goal] - imapa[ptr]) % M) + ((M + imapa[next_ptr] - imapa[goal]) % M) >= M){
        ptr = next_ptr;
        next_ptr = mapa[(imapa[ptr] + delky[ptr]) % M];
        ret++;
    }

    cout << ret << endl;

}
# 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 0 ms 348 KB Output is correct
11 Correct 0 ms 404 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 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 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 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 0 ms 348 KB Output is correct
11 Correct 0 ms 404 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 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 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 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 432 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 440 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 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 0 ms 348 KB Output is correct
11 Correct 0 ms 404 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 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 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 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 432 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 440 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 6 ms 1364 KB Output is correct
40 Correct 7 ms 1372 KB Output is correct
41 Correct 6 ms 1452 KB Output is correct
42 Correct 5 ms 860 KB Output is correct
43 Correct 4 ms 860 KB Output is correct
44 Correct 6 ms 1072 KB Output is correct
45 Correct 5 ms 860 KB Output is correct
46 Correct 6 ms 1116 KB Output is correct
47 Correct 6 ms 1372 KB Output is correct
48 Correct 6 ms 1372 KB Output is correct
49 Correct 4 ms 1372 KB Output is correct
50 Correct 5 ms 856 KB Output is correct
# 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 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 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 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 8 ms 1372 KB Output is correct
16 Correct 4 ms 860 KB Output is correct
17 Correct 5 ms 860 KB Output is correct
18 Correct 6 ms 860 KB Output is correct
19 Correct 6 ms 1368 KB Output is correct
20 Correct 43 ms 5836 KB Output is correct
21 Correct 347 ms 37940 KB Output is correct
22 Correct 346 ms 37936 KB Output is correct
23 Correct 235 ms 21688 KB Output is correct
24 Correct 348 ms 37928 KB Output is correct
25 Correct 218 ms 18964 KB Output is correct
26 Correct 261 ms 22200 KB Output is correct
27 Correct 243 ms 21940 KB Output is correct
28 Correct 297 ms 37168 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 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 6 ms 1284 KB Output is correct
13 Correct 4 ms 1056 KB Output is correct
14 Correct 5 ms 860 KB Output is correct
15 Correct 42 ms 6788 KB Output is correct
16 Correct 233 ms 23972 KB Output is correct
17 Correct 316 ms 41776 KB Output is correct
18 Correct 351 ms 41928 KB Output is correct
19 Correct 333 ms 41924 KB Output is correct
20 Correct 257 ms 23988 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 0 ms 348 KB Output is correct
11 Correct 0 ms 404 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 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 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 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 432 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 440 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 6 ms 1364 KB Output is correct
40 Correct 7 ms 1372 KB Output is correct
41 Correct 6 ms 1452 KB Output is correct
42 Correct 5 ms 860 KB Output is correct
43 Correct 4 ms 860 KB Output is correct
44 Correct 6 ms 1072 KB Output is correct
45 Correct 5 ms 860 KB Output is correct
46 Correct 6 ms 1116 KB Output is correct
47 Correct 6 ms 1372 KB Output is correct
48 Correct 6 ms 1372 KB Output is correct
49 Correct 4 ms 1372 KB Output is correct
50 Correct 5 ms 856 KB Output is correct
51 Correct 1 ms 344 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 0 ms 348 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 8 ms 1372 KB Output is correct
66 Correct 4 ms 860 KB Output is correct
67 Correct 5 ms 860 KB Output is correct
68 Correct 6 ms 860 KB Output is correct
69 Correct 6 ms 1368 KB Output is correct
70 Correct 43 ms 5836 KB Output is correct
71 Correct 347 ms 37940 KB Output is correct
72 Correct 346 ms 37936 KB Output is correct
73 Correct 235 ms 21688 KB Output is correct
74 Correct 348 ms 37928 KB Output is correct
75 Correct 218 ms 18964 KB Output is correct
76 Correct 261 ms 22200 KB Output is correct
77 Correct 243 ms 21940 KB Output is correct
78 Correct 297 ms 37168 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 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 0 ms 348 KB Output is correct
87 Correct 1 ms 348 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 0 ms 348 KB Output is correct
90 Correct 6 ms 1284 KB Output is correct
91 Correct 4 ms 1056 KB Output is correct
92 Correct 5 ms 860 KB Output is correct
93 Correct 42 ms 6788 KB Output is correct
94 Correct 233 ms 23972 KB Output is correct
95 Correct 316 ms 41776 KB Output is correct
96 Correct 351 ms 41928 KB Output is correct
97 Correct 333 ms 41924 KB Output is correct
98 Correct 257 ms 23988 KB Output is correct
99 Correct 322 ms 41780 KB Output is correct
100 Correct 333 ms 41776 KB Output is correct
101 Correct 328 ms 43056 KB Output is correct
102 Correct 330 ms 41780 KB Output is correct
103 Correct 253 ms 25524 KB Output is correct
104 Correct 296 ms 40240 KB Output is correct
105 Correct 190 ms 42268 KB Output is correct