Submission #415532

#TimeUsernameProblemLanguageResultExecution timeMemory
415532Pro_ktmrStations (IOI20_stations)C++17
100 / 100
1264 ms680 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define repi(i, a, b) for(int (i)=(a); (i)<(b); (i)++)

#include "stations.h"
#include <vector>

void dfs(int v, int p, vector<int> e[], vector<int>& labels, int& c){
	labels[v] = c;
	for(auto i: e[v]){
		if(i == p) continue;
		c++;
		dfs(i, v, e, labels, c);
		c++;
	}
	if(c%2) labels[v] = c;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
	vector<int> e[1000];
	rep(i, n-1){
		e[u[i]].pb(v[i]);
		e[v[i]].pb(u[i]);
	}

	vector<int> labels(n);
	int c = 0;
	dfs(0, -1, e, labels, c);

	vector<int> z = labels;
	sort(all(z));
	rep(i, n) labels[i] = lower_bound(all(z), labels[i]) - z.begin();

	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
	rep(i, c.size()){
		if(t == c[i]) return c[i];
	}
	if(c.back() < s){
		repi(i, 1, c.size()-1){
			if(c[i] < t && t < c[i+1]) return c[i];
		}
		if(c.back() < t && t < s) return c.back();
		return c[0];
	}
	else{
		repi(i, 1, c.size()-1){
			if(c[i-1] < t && t < c[i]) return c[i];
		}
		if(s < t && t < c.front()) return c.front();
		return c.back();
	}
}

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:5:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
      |                           ^
stations.cpp:24:2: note: in expansion of macro 'rep'
   24 |  rep(i, n-1){
      |  ^~~
stations.cpp:5:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
      |                           ^
stations.cpp:35:2: note: in expansion of macro 'rep'
   35 |  rep(i, n) labels[i] = lower_bound(all(z), labels[i]) - z.begin();
      |  ^~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:5:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
      |                           ^
stations.cpp:41:2: note: in expansion of macro 'rep'
   41 |  rep(i, c.size()){
      |  ^~~
stations.cpp:5:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
      |                                  ~~~^~~~
stations.cpp:41:2: note: in expansion of macro 'rep'
   41 |  rep(i, c.size()){
      |  ^~~
stations.cpp:6:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define repi(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
      |                               ^
stations.cpp:45:3: note: in expansion of macro 'repi'
   45 |   repi(i, 1, c.size()-1){
      |   ^~~~
stations.cpp:6:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define repi(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
      |                                        ~~~^~~~
stations.cpp:45:3: note: in expansion of macro 'repi'
   45 |   repi(i, 1, c.size()-1){
      |   ^~~~
stations.cpp:6:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define repi(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
      |                               ^
stations.cpp:52:3: note: in expansion of macro 'repi'
   52 |   repi(i, 1, c.size()-1){
      |   ^~~~
stations.cpp:6:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define repi(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
      |                                        ~~~^~~~
stations.cpp:52:3: note: in expansion of macro 'repi'
   52 |   repi(i, 1, c.size()-1){
      |   ^~~~
#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...