답안 #1067265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067265 2024-08-20T13:41:31 Z slivajan Fire (BOI24_fire) C++17
13 / 100
362 ms 43400 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++;
    }

    cout << time - visited[ptr] << endl;

}
# 결과 실행 시간 메모리 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 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 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 1 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 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 6 ms 1368 KB Output is correct
16 Correct 4 ms 1024 KB Output is correct
17 Correct 4 ms 860 KB Output is correct
18 Correct 5 ms 888 KB Output is correct
19 Correct 6 ms 1372 KB Output is correct
20 Correct 42 ms 5840 KB Output is correct
21 Correct 362 ms 41776 KB Output is correct
22 Correct 342 ms 43400 KB Output is correct
23 Correct 222 ms 23988 KB Output is correct
24 Correct 356 ms 42036 KB Output is correct
25 Correct 230 ms 21172 KB Output is correct
26 Correct 243 ms 24884 KB Output is correct
27 Correct 266 ms 25512 KB Output is correct
28 Correct 305 ms 41088 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 1 ms 348 KB Output is correct
4 Incorrect 1 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Halted 0 ms 0 KB -