답안 #782362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
782362 2023-07-13T21:04:40 Z AmirElarbi Passport (JOI23_passport) C++14
48 / 100
2000 ms 6000 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 = 2e5+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 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Execution timed out 2074 ms 6000 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 26 ms 2708 KB Output is correct
17 Correct 17 ms 2644 KB Output is correct
18 Correct 19 ms 2768 KB Output is correct
19 Correct 23 ms 2708 KB Output is correct
20 Correct 15 ms 2644 KB Output is correct
21 Correct 12 ms 2740 KB Output is correct
22 Correct 6 ms 2644 KB Output is correct
23 Correct 17 ms 2764 KB Output is correct
24 Correct 9 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 1 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 26 ms 2708 KB Output is correct
17 Correct 17 ms 2644 KB Output is correct
18 Correct 19 ms 2768 KB Output is correct
19 Correct 23 ms 2708 KB Output is correct
20 Correct 15 ms 2644 KB Output is correct
21 Correct 12 ms 2740 KB Output is correct
22 Correct 6 ms 2644 KB Output is correct
23 Correct 17 ms 2764 KB Output is correct
24 Correct 9 ms 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 32 ms 2712 KB Output is correct
28 Correct 27 ms 2644 KB Output is correct
29 Correct 24 ms 2764 KB Output is correct
30 Correct 15 ms 2736 KB Output is correct
31 Correct 20 ms 2764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Execution timed out 2074 ms 6000 KB Time limit exceeded
5 Halted 0 ms 0 KB -