Submission #320597

# Submission time Handle Problem Language Result Execution time Memory
320597 2020-11-09T08:24:13 Z kshitij_sodani Stations (IOI20_stations) C++14
0 / 100
919 ms 1132 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define endl '\n'



#include "stations.h"

vector<int> adj[1001];
int co=0;
int st[1001];
int endd[1001];
int levv[1001];
int nn;
void dfs(int no,int par=-1,int levv=0){
	st[no]=co;
	co++;
	for(auto j:adj[no]){
		if(j!=par){
			dfs(j,no,levv+1);
		}
	}

	if(levv%2==1){
		st[no]=1000+co-1;
	}
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	nn=n;
	for(int i=0;i<n;i++){
		adj[i].clear();
	}
	co=0;
	for(int i=0;i<n-1;i++){
		adj[u[i]].pb(v[i]);
		adj[v[i]].pb(u[i]);
	}
	dfs(0);
	vector<int> ans;
	for(int i=0;i<n;i++){
		ans.pb(st[i]);
	//	cout<<st[i];
	}
	//cout<<endl;




	return ans;
}

int find_next_station(int s, int t, std::vector<int> c) {
	
	if(c.size()==1){
		return c[0];
	}


	sort(c.begin(),c.end());
	vector<int> cc;
	for(auto j:c){
		if(j>=1000){
			cc.pb(j-1000);
		}
		else{
			cc.pb(j);
		}
	}
	if(s>=1000){
		s-=1000;
	}
	if(t>=1000){
		t-=1000;
	}
	if(s<c[0]){
		int pre=s-1;

		for(int i=0;i<c.size()-1;i++){
			int la=0;

			if(i==0){
				la=s;
			}
			else{
				la=cc[i-1]+1;
			}
			if(t<=cc[i] and t>=la){
				return c[i];
			}
		}
		return c.back();

	}
	else{
		for(int i=c.size()-1;i>0;i--){
			int la=0;
			if(i==cc.size()-1){
				la=s;
			}
			else{
				la=cc[i+1]-1;
			}
			if(t<=la and t>=cc[i]){
				return c[i];
			}
		}
		return c.back();



	}











	return c[0];
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:83:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |   for(int i=0;i<c.size()-1;i++){
      |               ~^~~~~~~~~~~
stations.cpp:81:7: warning: unused variable 'pre' [-Wunused-variable]
   81 |   int pre=s-1;
      |       ^~~
stations.cpp:102:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |    if(i==cc.size()-1){
      |       ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 612 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1009
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 364 KB Invalid labels (values out of range). scenario=0, k=1000, vertex=1, label=1511
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 640 KB Invalid labels (duplicates values). scenario=1, label=1863
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 919 ms 1132 KB Output is correct
2 Incorrect 682 ms 736 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 492 KB Invalid labels (duplicates values). scenario=1, label=1997
2 Halted 0 ms 0 KB -