Submission #931499

# Submission time Handle Problem Language Result Execution time Memory
931499 2024-02-22T00:32:54 Z beaboss Stations (IOI20_stations) C++14
0 / 100
503 ms 948 KB

#include "bits/stdc++.h"

using namespace std;

#define s second
#define f first
#define pb push_back

typedef long long ll;

typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef vector<int> vi;

#define FOR(i, a, b) for (int i = (a); i<b; i++)

bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }

bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }

const int N = 1010;
vi adj[N];
vi out;
int cnt = 0;
void dfs(int cur, int d = 0, int p = -1) {
	// cout << cur << endl;
	// return;
	if (d % 2 == 0) out[cur] = cnt;
	cnt++;
	for (auto val: adj[cur]) if (val != p) dfs(val, d + 1, cur);

	if (d % 2 == 1) out[cur] = cnt;
	cnt++; 
}



vi label(int n, int k, vi u, vi v) {
	cnt = 0;
	out.resize(0);
	FOR(i, 0, N) adj[i].clear();



	FOR(i, 0, n-1) {
		// cout << u[i] << v[i] << endl;
		adj[u[i]].pb(v[i]);
		adj[v[i]].pb(u[i]);
	}

	out.resize(n);
	// cout << ' '  <<out.size() << endl;
	// cout << 'd' << endl;
	dfs(0);
	// cout << 'd' << endl;
	vi other = out;
	sort(other.begin(), other.end());
	FOR(i, 0, out.size()) out[i] = lower_bound(other.begin(), other.end(), out[i]) - other.begin();

	return out;
}

int find_next_station(int s, int t, vi c) {
	assert(s <= c[0] || s >= c[c.size() - 1]);

	if (s < c[0]) { // everything is end
		int p = c[c.size() - 1];
		int st = s; // inclusive boud
		int en = s; // inclusive
		if (c.size() >= 2) en = max(en, c[c.size() - 2]-1);
		if (t > en || t < st) return p;

		return *lower_bound(c.begin(), c.begin() + c.size() - 1, t);
	} else {
		int p = c[0];
		int st = s-1; // inclusive
		int en = s-1; // inclusive
		// cout << st << en << endl;
		if (c.size() >= 2) st = min(st, c[1]);
		// cout << st << en << endl;
		if (t > en || t < st) return p;

		// cout << t << endl;
		return *prev(upper_bound(c.begin() + 1, c.end(), t), 1);
	}
	

	
 

}

// int main() {
// 	ios::sync_with_stdio(false);
// 	cin.tie(nullptr);

// 	int n;
// 	cin >> n;

// 	vi a(n - 1), b(n-1);

// 	FOR(i, 0, n-1) {
// 		cin >> a[i] >> b[i];
// 	}

// 	vi res = label(n, n-1, a, b);
// 	for (auto val: res) cout << val << endl;

// 		cin >> n;

// 	a = vi(n-1);
// 	b = vi(n-1);

// 	FOR(i, 0, n-1) {
// 		cin >> a[i] >> b[i];
// 	}

// 	res = label(n, n-1, b, a);
// 	for (auto val: res) cout << val << endl;

// 	// while (true) {
// 	// 	int a, b, c, d;;
// 	// 	cin >> a >> b;
// 	// 	cin >> c;
// 	// 	vi val;
// 	// 	FOR(i, 0, c) {
// 	// 		cin >> d;
// 	// 		val.pb(d);
// 	// 	}
// 	// 	cout << find_next_station(a, b, val) << endl;
// 	// }
// }












Compilation message

stations.cpp: In function 'vi label(int, int, vi, vi)':
stations.cpp:18:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 | #define FOR(i, a, b) for (int i = (a); i<b; i++)
......
   61 |  FOR(i, 0, out.size()) out[i] = lower_bound(other.begin(), other.end(), out[i]) - other.begin();
      |      ~~~~~~~~~~~~~~~~                    
stations.cpp:61:2: note: in expansion of macro 'FOR'
   61 |  FOR(i, 0, out.size()) out[i] = lower_bound(other.begin(), other.end(), out[i]) - other.begin();
      |  ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 308 ms 932 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 266 ms 876 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 364 ms 948 KB Wrong query response.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 503 ms 684 KB Output is correct
2 Incorrect 414 ms 680 KB Wrong query response.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 287 ms 932 KB Wrong query response.
2 Halted 0 ms 0 KB -