답안 #898375

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
898375 2024-01-04T14:47:43 Z vjudge1 Passport (JOI23_passport) C++17
0 / 100
819 ms 1048576 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define str string
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define all(x) x.begin() , x.end()
#define setpr(x) cout << fixed << setprecision(x) 
#define endl '\n'
 
const int inf = INT_MAX;
const ld eps = 1e-9 , pi = acos(-1.0);
const ll mod = 1e9 + 7; // 998244353;
const int dx[4]{1 , 0 , -1 , 0} , dy[4]{0 , 1 , 0 , -1};

vector<vector<int>> graf;
int n;

int bfs(int x){
    vector<int> dist(n + 1 , -1) , qat(n + 1 , -1);
    queue<int> q;
    auto add = [&](int j , int i , int p){
        if(dist[i] == -1){
            dist[i] = p;
            q.push(i);
            qat[i] = j;
        }
    };
    add(x , x , 0);
    while(!q.empty()){
        int u = q.front();
        q.pop();
        for(int v : graf[u]) add(u , v , dist[u] + 1);
    }
    if(dist[1] == -1 || dist[n] == -1) return -1;
    set<int> st1;
    int h1 = 1 , h2 = n;
    while(h1 != x){
        h1 = qat[h1];
        st1.insert(h1);
    }
    while(h2 != x){
        h2 = qat[h2];
        st1.insert(h2);
    }
    // for(int i : st1) cout << i << " "; cout << endl;
    return st1.size();
}

void solution(){
    cin >> n;
    vector<pair<int , int>> bu(n);
    for(auto &x : bu) cin >> x.F >> x.S;
    graf.resize(n + 1);
    for(int i = 0 ; i < n ; i ++){
        for(int j = bu[i].F ; j <= bu[i].S ; j ++){
            graf[i + 1].pb(j);
        }
    }
    int q; cin >> q;
    while(q --){
        int x; cin >> x;
        cout << bfs(x) << endl; 
    }
}  
 
signed main(){
    IOS;
    int t = 1; // cin >> t;
    while(t --) solution();
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Runtime error 819 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 612 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 612 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 612 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 612 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 612 KB Output is correct
3 Correct 0 ms 352 KB Output is correct
4 Correct 0 ms 360 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 1 ms 612 KB Output is correct
7 Correct 0 ms 360 KB Output is correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 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 1 ms 344 KB Output is correct
4 Runtime error 819 ms 1048576 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -