Submission #888760

# Submission time Handle Problem Language Result Execution time Memory
888760 2023-12-18T07:24:12 Z vjudge1 Passport (JOI23_passport) C++17
0 / 100
2000 ms 6616 KB
#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 ans = 0;
	int just;
	cin >> just;
	while(just--){
		for(int i = 1; i <= n; i++)dist[i] = 1e9;
		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++){
			//cout << dist[i] <<" ";
			ans = max(dist[i], ans);
		}
		if(ans == 1e9)
			cout << "-1\n";
		else
		cout <<ans << endl;
	}
}

Compilation message

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 time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 6616 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Incorrect 0 ms 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 6616 KB Time limit exceeded
5 Halted 0 ms 0 KB -