Submission #721218

# Submission time Handle Problem Language Result Execution time Memory
721218 2023-04-10T14:09:03 Z n1k Roller Coaster Railroad (IOI16_railroad) C++17
0 / 100
257 ms 17100 KB
#include <bits/stdc++.h>
#include "railroad.h"

#define ll long long
#define vt vector
#define pb push_back
#define ar array
#define all(x) (x).begin(), (x).end()
#define sz(x) (x).size()

using namespace std;

/*
 1. simplify
 2. add new elements
 3. brute force solution
 4. optimize
 5. start implementing
*/

// --- templates ---
// --- code ---

vt<int> p;

int find(int u){
	if(p[u] == u){
		return u;
	}
	return p[u] = find(p[u]);
}

bool join(int u, int v){
	if((u = find(u)) == (v = find(v))){
		return false;
	}
	p[u] = v;
	return true;
}

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
	int n = sz(s);
	vt<int> comp;
	comp.insert(comp.begin(), all(s));
	comp.insert(comp.begin(), all(t));

	sort(all(comp));

	vt<int> a(sz(comp));
	p.resize(sz(comp));
	iota(all(p), 0);

	for(int i = 0; i < n; i++){
		s[i] = lower_bound(all(comp), s[i]) - comp.begin();
		t[i] = lower_bound(all(comp), t[i]) - comp.begin();

		a[s[i]]++;
		a[t[i]]--;

		join(s[i], t[i]);
	}
	ll ans = 0;
	vt<ar<int, 2>> e;
	for(int i = 0; i < sz(comp) - 1; i++){
		a[i + 1] += a[i];
		ans += max(0, (a[i] - 1) * comp[i + 1] - comp[i]);
		if(a[i] != 1){
			join(i, i + 1);
		}
		e.pb({comp[i + 1] - comp[i], i});
	}
	sort(all(e));
	for(int i = 0; i < sz(e); i++){
		if(join(e[i][1], e[i][1] + 1)){
			ans += e[i][0];
		}
	}
	return ans;
}

Compilation message

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  for(int i = 0; i < sz(comp) - 1; i++){
      |                 ~~^~~~~~~~~~~~~~
railroad.cpp:73:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |  for(int i = 0; i < sz(e); i++){
      |                   ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB answer is not correct: 3050982680 instead of 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB answer is not correct: 3050982680 instead of 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 257 ms 17100 KB answer is not correct: 1 instead of 0
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB answer is not correct: 3050982680 instead of 0
2 Halted 0 ms 0 KB -