답안 #782358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782358 2023-07-13T20:58:11 Z AmirElarbi Passport (JOI23_passport) C++14
48 / 100
34 ms 3412 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define INF 1e9
#define ve vector
#define vi ve<int>
#define ii pair<int,int>
#define vii ve<ii>
#define pb push_back
#define fi first
#define se second
#define ll long long
using namespace __gnu_pbds;
using namespace std;
const int nax = 1e5+5;
const int kax = 25+5;
const int MOD = 1e9+7;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int r[nax], l[nax], ans[nax], ansl[nax], ansr[nax];
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> l[i] >> r[i];
    queue<int> ql, qr;
    memset(ansl, -1, sizeof ansl);
    memset(ansr, -1, sizeof ansr);
    memset(ans, -1, sizeof ans);
    for (int i = 1; i <= n; ++i)
    {
        if(l[i] == 1){
            ansl[i] = 1; 
            ql.push(i);            
        } 
        if(r[i] == n){
            ansr[i] = 1; 
            qr.push(i);            
        } 
    }
    while(!ql.empty()){
        int u = ql.front();
        ql.pop();
        for (int i = 1; i <= n; ++i)
        {
            if(ansl[i] == -1 && l[i] <= u && u <= r[i]){
                ansl[i] = ansl[u]+1;
                ql.push(i);
            }
        }
    }
    while(!qr.empty()){
        int u = qr.front();
        //cout << u << endl;
        qr.pop();
        if(ansl[u] != -1) ans[u] = ansl[u] + ansr[u] - 1;
        for (int i = 1; i <= n; ++i)
        {
            if(ansr[i] == -1 && l[i] <= u && u <= r[i]){
                ansr[i] = ansr[u]+1;
                qr.push(i);
            }
        }
    }
    vii gt;
    for (int i = 1; i <= n; ++i)
    {
        if(ans[i] != -1) gt.pb({ans[i], i});
    }
    sort(gt.begin(), gt.end());
    for (auto x : gt)
    {
        for (int j = 1; j <= n; ++j)
        {
            if(l[j] <= x.se && x.se <= r[j]) ans[j] = min(ans[x.se]+1, ans[j]);
        }
    }
    int q;
    cin >> q;
    while(q--){
        int x;
        cin >> x;
        cout << ans[x] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1480 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Runtime error 13 ms 3412 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1488 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1480 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1488 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1480 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 18 ms 1492 KB Output is correct
17 Correct 22 ms 1600 KB Output is correct
18 Correct 18 ms 1524 KB Output is correct
19 Correct 26 ms 1544 KB Output is correct
20 Correct 16 ms 1492 KB Output is correct
21 Correct 12 ms 1520 KB Output is correct
22 Correct 6 ms 1496 KB Output is correct
23 Correct 17 ms 1552 KB Output is correct
24 Correct 11 ms 1540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 1 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 2 ms 1492 KB Output is correct
7 Correct 1 ms 1492 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1488 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 1 ms 1492 KB Output is correct
14 Correct 1 ms 1480 KB Output is correct
15 Correct 1 ms 1492 KB Output is correct
16 Correct 18 ms 1492 KB Output is correct
17 Correct 22 ms 1600 KB Output is correct
18 Correct 18 ms 1524 KB Output is correct
19 Correct 26 ms 1544 KB Output is correct
20 Correct 16 ms 1492 KB Output is correct
21 Correct 12 ms 1520 KB Output is correct
22 Correct 6 ms 1496 KB Output is correct
23 Correct 17 ms 1552 KB Output is correct
24 Correct 11 ms 1540 KB Output is correct
25 Correct 1 ms 1488 KB Output is correct
26 Correct 1 ms 1492 KB Output is correct
27 Correct 34 ms 1568 KB Output is correct
28 Correct 19 ms 1560 KB Output is correct
29 Correct 19 ms 1564 KB Output is correct
30 Correct 14 ms 1532 KB Output is correct
31 Correct 27 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 1 ms 1480 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Runtime error 13 ms 3412 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -