Submission #888765

#TimeUsernameProblemLanguageResultExecution timeMemory
888765vjudge1Passport (JOI23_passport)C++17
0 / 100
2086 ms6616 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;} int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;} const int N = 2e5 + 10; int dist[N]; main(){ ios :: sync_with_stdio(0); cin.tie(0); // memset(dist, 0x3f3f, sizeof(dist)); int n; cin >> n; vector <pair <int,int> > vp(n + 1); for(int i = 1; i <= n; i++){ cin >> vp[i].ff >> vp[i].ss; } int just; cin >> just; while(just--){ for(int i = 1; i <= n; i++)dist[i] = 1e18; int pos; cin >> pos; queue<int> q; q.push(pos); dist[pos] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (int i = vp[v].ff; i <= vp[v].ss; i++) { int to = i; if(dist[to] > dist[v] + 1){ dist[to] = dist[v] + 1; q.push(to); } } } int ans = 0; for(int i = 1; i <= n; i++){ ans = max(dist[i], ans); } if(n == 1) ans = 1; else if(ans == 1e18) cout << "-1\n"; else cout <<ans << endl; } }

Compilation message (stderr)

passport.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main(){
      | ^~~~
passport.cpp: In function 'void fp(std::string)':
passport.cpp:12:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
passport.cpp:12:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...