Submission #828933

#TimeUsernameProblemLanguageResultExecution timeMemory
828933CSQ31Passport (JOI23_passport)C++17
0 / 100
2117 ms826396 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define sz(a) (int)(a.size()) #define all(a) a.begin(),a.end() #define lb lower_bound #define ub upper_bound #define owo ios_base::sync_with_stdio(0);cin.tie(0); #define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr) #define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\ debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC)) typedef long long int ll; typedef long double ld; typedef pair<ll,ll> PII; typedef pair<int,int> pii; typedef vector<vector<int>> vii; typedef vector<vector<ll>> VII; ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);} const int MAXN = 2e5+5; int a[MAXN],b[MAXN],c[MAXN]; int dist[4][MAXN]; vector<int>adj[MAXN]; int main() { owo int n; cin>>n; queue<pii>q; for(int i=1;i<=n;i++)dist[0][i] = dist[1][i] = dist[2][i] = dist[3][i] = 1e9; for(int i=1;i<=n;i++){ cin>>a[i]>>b[i]; if(a[i]==1)c[i]++; if(b[i]==n)c[i]+=2; for(int j=a[i];j<=b[i];j++)adj[j].pb(i); if(c[i]){ dist[c[i]][i] = 1; q.push({c[i],i}); } } while(!q.empty()){ int x = q.front().se; int c0 = q.front().fi; q.pop(); for(int i:adj[x]){ int c1 = c[i] | c0; if(dist[c1][i] > dist[c0][x] + 1){ dist[c1][i] = dist[c0][x] + 1; q.push({c1,i}); } } } int Q; cin>>Q; while(Q--){ int i; cin>>i; if(dist[3][i]==1e9)cout<<-1<<'\n'; else cout<<dist[3][i]<<'\n'; } }
#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...