답안 #878479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878479 2023-11-24T14:10:19 Z prohacker Passport (JOI23_passport) C++17
48 / 100
2000 ms 113824 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int,int>

using namespace std;

const int N = 2e5+10;
const int INF = INT_MAX;
const int mod = 1e9+7;
const string NAME = "solve";

int n,cnt;
int d[3][8*N];
vector<pii> adj[8*N];
int idx[8*N];
int q;

void build(int id = 1, int l = 1, int r = 2*n) {
    if(l == r) {
        idx[id] = l;
        return;
    }
    idx[id] = ++cnt;
    int mid = l + r >> 1;
    build(id << 1,l,mid);
    build(id << 1 | 1,mid+1,r);
    adj[idx[id << 1]].push_back({idx[id],0});
    adj[idx[id << 1 | 1]].push_back({idx[id],0});
}

void update(int root, int u, int v, int id = 1, int l = 1, int r = 2*n) {
    if(r < u or v < l) {
        return;
    }
    if(u <= l and r <= v) {
        adj[idx[id]].push_back({root,1});
        return;
    }
    int mid = l + r >> 1;
    update(root,u,v,id << 1,l,mid);
    update(root,u,v,id << 1 | 1,mid+1,r);
}

queue<int> pq;

void dijkstra(int d[]) {
    while(!pq.empty()) {
        int u = pq.front();
        pq.pop();
        for(auto p:adj[u]) {
            int v = p.first;
            int w = p.second;
            if(d[u] + w < d[v]) {
                d[v] = d[u] + w;
                pq.push(v);
            }
        }
    }
}

signed main()
{
    if (fopen((NAME + ".inp").c_str(), "r")) {
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    cnt = 2*n;
    build();
    for(int i = 1 ; i <= n ; i++) {
        int l,r; cin >> l >> r;
        update(i+n,l,r);
        adj[i+n].push_back({i,0});
    }
    for(int j = 0 ; j < 3 ; j++) {
        for(int i = 1 ; i <= cnt ; i++) {
            d[j][i] = 1e8;
        }
    }
    d[0][1] = 0;
    pq.push(1);
    dijkstra(d[0]);
    d[1][n] = 0;
    pq.push(n);
    dijkstra(d[1]);
    for(int i = 1 ; i <= cnt ; i++) {
        if(i == 1 or i == n) {
            d[2][i] = d[0][i] + d[1][i];
        }
        else {
            if(1 <= i and i <= n) {
                d[2][i] = d[0][i] + d[1][i] - 1;
            }
            else {
                d[2][i] = d[0][i] + d[1][i];
            }
        }
        pq.push(i);
    }
    dijkstra(d[2]);
    cin >> q;
    while(q--) {
        int x; cin >> x;
        if(d[2][x] >= 1e8) {
            d[2][x] = -1;
        }
        cout << d[2][x] << '\n';
    }
    return 0;
}

Compilation message

passport.cpp: In function 'void build(int, int, int)':
passport.cpp:25:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |     int mid = l + r >> 1;
      |               ~~^~~
passport.cpp: In function 'void update(int, int, int, int, int, int)':
passport.cpp:40:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     int mid = l + r >> 1;
      |               ~~^~~
passport.cpp: In function 'int main()':
passport.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen((NAME + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen((NAME + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 45400 KB Output is correct
2 Correct 9 ms 45404 KB Output is correct
3 Correct 9 ms 45400 KB Output is correct
4 Correct 864 ms 113824 KB Output is correct
5 Execution timed out 2036 ms 91732 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 45404 KB Output is correct
2 Correct 9 ms 45400 KB Output is correct
3 Correct 9 ms 45404 KB Output is correct
4 Correct 9 ms 45560 KB Output is correct
5 Correct 10 ms 45604 KB Output is correct
6 Correct 10 ms 45600 KB Output is correct
7 Correct 9 ms 45404 KB Output is correct
8 Correct 9 ms 45564 KB Output is correct
9 Correct 9 ms 45404 KB Output is correct
10 Correct 9 ms 45404 KB Output is correct
11 Correct 10 ms 45556 KB Output is correct
12 Correct 9 ms 45660 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 9 ms 45660 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 45404 KB Output is correct
2 Correct 9 ms 45400 KB Output is correct
3 Correct 9 ms 45404 KB Output is correct
4 Correct 9 ms 45560 KB Output is correct
5 Correct 10 ms 45604 KB Output is correct
6 Correct 10 ms 45600 KB Output is correct
7 Correct 9 ms 45404 KB Output is correct
8 Correct 9 ms 45564 KB Output is correct
9 Correct 9 ms 45404 KB Output is correct
10 Correct 9 ms 45404 KB Output is correct
11 Correct 10 ms 45556 KB Output is correct
12 Correct 9 ms 45660 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 9 ms 45660 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 12 ms 46168 KB Output is correct
17 Correct 12 ms 45912 KB Output is correct
18 Correct 18 ms 46172 KB Output is correct
19 Correct 13 ms 46372 KB Output is correct
20 Correct 12 ms 45916 KB Output is correct
21 Correct 63 ms 46100 KB Output is correct
22 Correct 10 ms 45916 KB Output is correct
23 Correct 11 ms 46076 KB Output is correct
24 Correct 11 ms 46424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 45404 KB Output is correct
2 Correct 9 ms 45400 KB Output is correct
3 Correct 9 ms 45404 KB Output is correct
4 Correct 9 ms 45560 KB Output is correct
5 Correct 10 ms 45604 KB Output is correct
6 Correct 10 ms 45600 KB Output is correct
7 Correct 9 ms 45404 KB Output is correct
8 Correct 9 ms 45564 KB Output is correct
9 Correct 9 ms 45404 KB Output is correct
10 Correct 9 ms 45404 KB Output is correct
11 Correct 10 ms 45556 KB Output is correct
12 Correct 9 ms 45660 KB Output is correct
13 Correct 10 ms 45660 KB Output is correct
14 Correct 9 ms 45660 KB Output is correct
15 Correct 10 ms 45660 KB Output is correct
16 Correct 12 ms 46168 KB Output is correct
17 Correct 12 ms 45912 KB Output is correct
18 Correct 18 ms 46172 KB Output is correct
19 Correct 13 ms 46372 KB Output is correct
20 Correct 12 ms 45916 KB Output is correct
21 Correct 63 ms 46100 KB Output is correct
22 Correct 10 ms 45916 KB Output is correct
23 Correct 11 ms 46076 KB Output is correct
24 Correct 11 ms 46424 KB Output is correct
25 Correct 9 ms 45400 KB Output is correct
26 Correct 10 ms 45404 KB Output is correct
27 Correct 15 ms 46172 KB Output is correct
28 Correct 13 ms 46160 KB Output is correct
29 Correct 11 ms 45916 KB Output is correct
30 Correct 64 ms 46056 KB Output is correct
31 Correct 11 ms 45916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 45400 KB Output is correct
2 Correct 9 ms 45404 KB Output is correct
3 Correct 9 ms 45400 KB Output is correct
4 Correct 864 ms 113824 KB Output is correct
5 Execution timed out 2036 ms 91732 KB Time limit exceeded
6 Halted 0 ms 0 KB -