Submission #320464

# Submission time Handle Problem Language Result Execution time Memory
320464 2020-11-08T20:01:02 Z nikatamliani Stations (IOI20_stations) C++14
0 / 100
1073 ms 1240 KB
#include <bits/stdc++.h>
#include "stations.h"
using namespace std;
void dfs(int x, int p, vector < vector < int > > &adj, vector < int > &labels, int depth) {
	static int timer = -1;
	++timer;
	if(depth) labels[x] = timer;
	for(int to : adj[x]) {
		if(to != p) {
			dfs(to, x, adj, labels, depth ^ 1);
		}
	}
	++timer;
	if(!depth) labels[x] = timer;
}
vector < int > label(int n, int k, vector < int > u, vector < int > v) {
	vector < int > labels(n);
	vector< vector < int > > adj(n, vector < int >());
	for(int i = 0; i < n - 1; ++i) {
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
	}
	dfs(0, -1, adj, labels, 0);
	vector < vector < int > > g;
	for(int i = 0; i < n; ++i) {
	    g.push_back({labels[i], i});
	}
	sort(g.begin(), g.end());
	for(int i = 0, cnt = -1; i < n; ++i) {
	    if(i == 0 || g[i][0] != g[i][1]) ++cnt;
	    labels[g[i][1]] = cnt;
	}
	return labels;
}

int find_next_station(int s, int t, vector < int > c) {
    if(c.size() == 1) return c[0];
	sort(c.begin(), c.end());
	if(s == 0) {
	    int my_in = 0;
	    int my_out = c.back();
	    for(int i = 0; i < c.size(); ++i) {
	        int cur_in, cur_out;
	        if(i == 0) {
	            cur_in = my_in;
	        } else {
	            cur_in = c[i - 1] + 1;
	        }
	        cur_out = c[i];
	        if(cur_in <= t && t <= cur_out) {
	            return c[i];
	        }
	    }
	} else {
	    int my_in = -1, my_out = -1;
	    if(s < c[0]) {
	        my_in = s;
	        my_out = c[(int)c.size() - 2];
	        for(int i = 0; i < (int)c.size() - 1; ++i) {
	            int cur_in, cur_out;
	            cur_out = c[i];
	            if(i == 0) {
	                cur_in = my_in;
	            } else {
	                cur_in = c[i - 1] + 1; 
	            }
	            if(cur_in <= t && t <= cur_out) return c[i];
	        }
	        return c.back();
	    } else {
	        my_in = c[1];
	        my_out = s;
	        for(int i = 1; i < (int)c.size(); ++i) {
	            int cur_in, cur_out;
	            cur_in = c[i];
	            if(i == (int)c.size() - 1) {
	                cur_out = s;
	            } else {
	                cur_out = c[i + 1] - 1;
	            }
	            if(cur_in <= t && t <= cur_out) return c[i];
	        }
	        return c[0];
	    }
	}
}
// int main() {
//     vector < int > x = label(5, 10, {0, 1, 1, 2}, {1, 2, 3, 4});
//     // for(int i : x) cout << i << ' ';
//     cout << find_next_station(3, 9, {5}) << '\n';  
// }

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |      for(int i = 0; i < c.size(); ++i) {
      |                     ~~^~~~~~~~~~
stations.cpp:41:10: warning: unused variable 'my_out' [-Wunused-variable]
   41 |      int my_out = c.back();
      |          ^~~~~~
stations.cpp:55:22: warning: variable 'my_out' set but not used [-Wunused-but-set-variable]
   55 |      int my_in = -1, my_out = -1;
      |                      ^~~~~~
stations.cpp:86:1: warning: control reaches end of non-void function [-Wreturn-type]
   86 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 492 KB Invalid labels (duplicates values). scenario=0, label=1
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 492 KB Invalid labels (duplicates values). scenario=0, label=339
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 693 ms 928 KB Output is correct
2 Correct 493 ms 1012 KB Output is correct
3 Correct 958 ms 864 KB Output is correct
4 Correct 653 ms 864 KB Output is correct
5 Correct 622 ms 556 KB Output is correct
6 Correct 546 ms 884 KB Output is correct
7 Incorrect 1 ms 492 KB Invalid labels (duplicates values). scenario=0, label=4
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 813 ms 1012 KB Output is correct
2 Correct 652 ms 868 KB Output is correct
3 Correct 722 ms 876 KB Output is correct
4 Incorrect 1 ms 364 KB Invalid labels (duplicates values). scenario=0, label=0
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 532 ms 1240 KB Output is correct
2 Correct 406 ms 1048 KB Output is correct
3 Correct 1073 ms 756 KB Output is correct
4 Correct 626 ms 860 KB Output is correct
5 Incorrect 1 ms 364 KB Invalid labels (duplicates values). scenario=0, label=0
6 Halted 0 ms 0 KB -