답안 #736936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
736936 2023-05-06T11:27:55 Z Cookie Passport (JOI23_passport) C++14
54 / 100
2000 ms 81196 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("WINTER.inp");
ofstream fout("WINTER.out");
 
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
const int x[4] = {1, -1, 0, 0};
const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 2e5, mxm = 1e5, sq = 400;
const int base = (1 << 18);
const ll inf = 1e9;
const ld pre = 1e-6;
//cool problem!
int n;
int l[mxn + 1], r[mxn + 1], id, lson[4 * mxn + 1], rson[4 * mxn + 1];
vt<pii>adj[4 * mxn + 1];
vt<int>d1, d2, d3;
int build(int nd, int l, int r){
    if(l == r)return(l);
    int mid = (l + r) >> 1;
    int ls = build(nd << 1, l, mid), rs = build(nd << 1 | 1, mid + 1, r);
    ++id;
    lson[id] = ls; rson[id] = rs;
    
    adj[lson[id]].pb(make_pair(id, 0)); adj[rson[id]].pb({id, 0});
    return(id);
}
void upd(int nd, int l, int r, int ql, int qr, int u){
    if(ql > r || qr < l)return;
    if(ql <= l && qr >= r){
        
        adj[nd].pb(make_pair(u, 1));
        return;
    }
    int mid = (l + r) >> 1;
    upd(lson[nd], l, mid, ql, qr, u); upd(rson[nd], mid + 1, r, ql, qr, u);
}
void find(vt<int>&d){
    deque<int>dq;
    for(int i = 1; i <= n; i++){
        if(d[i] != inf)dq.pb(i);
    }
   
    while(!dq.empty()){
        int u = dq.front(); dq.pop_front();
        for(auto [v, w]: adj[u]){
            if(d[v] > d[u] + w){
                d[v] = d[u] + w;
                if(w){
                    dq.pb(v);
                }else{
                    dq.push_front(v);
                }
            }
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    id = n;
    int root = build(1, 1, n);
    
    forr(i, 1, n + 1){
        cin >> l[i] >> r[i];
        upd(root, 1, n, l[i], r[i], i);
    }
    d1.resize(4 * n + 1, inf); d1[1] = 0;
    find(d1); 
    d1[1] = 1;
    d2.resize(4 * n + 1, inf); d2[n] = 0;
    
    find(d2);
    d2[n] = 1;
    
    d3.resize(4 * n + 1, inf);
    for(int i = 1; i <= n; i++){
        d3[i] = d1[i] + d2[i]; 
    }
    find(d3);
    int q; cin >> q;
    forr(i, 0, q){
        int x; cin >> x;
        if(d3[x] >= 1e9)cout << -1 << "\n";
        else cout << d3[x] - 1 << "\n";
    }
    return(0);
}

Compilation message

passport.cpp: In function 'void find(std::vector<int>&)':
passport.cpp:59:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |         for(auto [v, w]: adj[u]){
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 19064 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 10 ms 19132 KB Output is correct
4 Correct 488 ms 73112 KB Output is correct
5 Correct 191 ms 53328 KB Output is correct
6 Correct 135 ms 48184 KB Output is correct
7 Correct 80 ms 45880 KB Output is correct
8 Correct 92 ms 51052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19116 KB Output is correct
2 Correct 11 ms 19156 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 12 ms 19028 KB Output is correct
5 Correct 11 ms 19056 KB Output is correct
6 Correct 10 ms 19052 KB Output is correct
7 Correct 13 ms 19040 KB Output is correct
8 Correct 13 ms 19028 KB Output is correct
9 Correct 11 ms 19028 KB Output is correct
10 Correct 10 ms 19028 KB Output is correct
11 Correct 10 ms 19156 KB Output is correct
12 Correct 11 ms 19156 KB Output is correct
13 Correct 12 ms 19156 KB Output is correct
14 Correct 11 ms 19212 KB Output is correct
15 Correct 10 ms 19156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19116 KB Output is correct
2 Correct 11 ms 19156 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 12 ms 19028 KB Output is correct
5 Correct 11 ms 19056 KB Output is correct
6 Correct 10 ms 19052 KB Output is correct
7 Correct 13 ms 19040 KB Output is correct
8 Correct 13 ms 19028 KB Output is correct
9 Correct 11 ms 19028 KB Output is correct
10 Correct 10 ms 19028 KB Output is correct
11 Correct 10 ms 19156 KB Output is correct
12 Correct 11 ms 19156 KB Output is correct
13 Correct 12 ms 19156 KB Output is correct
14 Correct 11 ms 19212 KB Output is correct
15 Correct 10 ms 19156 KB Output is correct
16 Correct 11 ms 19540 KB Output is correct
17 Correct 11 ms 19540 KB Output is correct
18 Correct 16 ms 19768 KB Output is correct
19 Correct 12 ms 19704 KB Output is correct
20 Correct 11 ms 19448 KB Output is correct
21 Correct 30 ms 19540 KB Output is correct
22 Correct 11 ms 19412 KB Output is correct
23 Correct 16 ms 19596 KB Output is correct
24 Correct 13 ms 19668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19116 KB Output is correct
2 Correct 11 ms 19156 KB Output is correct
3 Correct 10 ms 19028 KB Output is correct
4 Correct 12 ms 19028 KB Output is correct
5 Correct 11 ms 19056 KB Output is correct
6 Correct 10 ms 19052 KB Output is correct
7 Correct 13 ms 19040 KB Output is correct
8 Correct 13 ms 19028 KB Output is correct
9 Correct 11 ms 19028 KB Output is correct
10 Correct 10 ms 19028 KB Output is correct
11 Correct 10 ms 19156 KB Output is correct
12 Correct 11 ms 19156 KB Output is correct
13 Correct 12 ms 19156 KB Output is correct
14 Correct 11 ms 19212 KB Output is correct
15 Correct 10 ms 19156 KB Output is correct
16 Correct 11 ms 19540 KB Output is correct
17 Correct 11 ms 19540 KB Output is correct
18 Correct 16 ms 19768 KB Output is correct
19 Correct 12 ms 19704 KB Output is correct
20 Correct 11 ms 19448 KB Output is correct
21 Correct 30 ms 19540 KB Output is correct
22 Correct 11 ms 19412 KB Output is correct
23 Correct 16 ms 19596 KB Output is correct
24 Correct 13 ms 19668 KB Output is correct
25 Correct 12 ms 19128 KB Output is correct
26 Correct 12 ms 19028 KB Output is correct
27 Correct 14 ms 19596 KB Output is correct
28 Correct 13 ms 19568 KB Output is correct
29 Correct 12 ms 19540 KB Output is correct
30 Correct 34 ms 19456 KB Output is correct
31 Correct 16 ms 19540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 19064 KB Output is correct
2 Correct 10 ms 19028 KB Output is correct
3 Correct 10 ms 19132 KB Output is correct
4 Correct 488 ms 73112 KB Output is correct
5 Correct 191 ms 53328 KB Output is correct
6 Correct 135 ms 48184 KB Output is correct
7 Correct 80 ms 45880 KB Output is correct
8 Correct 92 ms 51052 KB Output is correct
9 Correct 9 ms 19116 KB Output is correct
10 Correct 11 ms 19156 KB Output is correct
11 Correct 10 ms 19028 KB Output is correct
12 Correct 12 ms 19028 KB Output is correct
13 Correct 11 ms 19056 KB Output is correct
14 Correct 10 ms 19052 KB Output is correct
15 Correct 13 ms 19040 KB Output is correct
16 Correct 13 ms 19028 KB Output is correct
17 Correct 11 ms 19028 KB Output is correct
18 Correct 10 ms 19028 KB Output is correct
19 Correct 10 ms 19156 KB Output is correct
20 Correct 11 ms 19156 KB Output is correct
21 Correct 12 ms 19156 KB Output is correct
22 Correct 11 ms 19212 KB Output is correct
23 Correct 10 ms 19156 KB Output is correct
24 Correct 11 ms 19540 KB Output is correct
25 Correct 11 ms 19540 KB Output is correct
26 Correct 16 ms 19768 KB Output is correct
27 Correct 12 ms 19704 KB Output is correct
28 Correct 11 ms 19448 KB Output is correct
29 Correct 30 ms 19540 KB Output is correct
30 Correct 11 ms 19412 KB Output is correct
31 Correct 16 ms 19596 KB Output is correct
32 Correct 13 ms 19668 KB Output is correct
33 Correct 12 ms 19128 KB Output is correct
34 Correct 12 ms 19028 KB Output is correct
35 Correct 14 ms 19596 KB Output is correct
36 Correct 13 ms 19568 KB Output is correct
37 Correct 12 ms 19540 KB Output is correct
38 Correct 34 ms 19456 KB Output is correct
39 Correct 16 ms 19540 KB Output is correct
40 Correct 565 ms 73944 KB Output is correct
41 Correct 223 ms 54868 KB Output is correct
42 Execution timed out 2052 ms 81196 KB Time limit exceeded
43 Halted 0 ms 0 KB -