Submission #898387

#TimeUsernameProblemLanguageResultExecution timeMemory
898387vjudge1Passport (JOI23_passport)C++17
0 / 100
783 ms1048576 KiB
#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); } return st1.size(); } void solution(){ cin >> n; vector<pair<int , int>> bu(n); for(int i = 0 ; i < n ; i ++) cin >> bu[i].F >> bu[i].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); if(q >= 1) cout << endl; } } signed main(){ IOS; int t = 1; // cin >> t; while(t --) solution(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...