Submission #24427

# Submission time Handle Problem Language Result Execution time Memory
24427 2017-06-07T13:29:49 Z gs14004 Roller Coaster Railroad (IOI16_railroad) C++11
0 / 100
256 ms 11444 KB
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;

struct disj{
  int pa[400005];
  void init(int n){
    for(int i=0; i<=n; i++) pa[i] = i;
  }
  int find(int x){
    return pa[x] = (pa[x] == x ? x : find(pa[x]));
  }
  bool uni(int p, int q){
    p = find(p);
    q = find(q);
    if(p == q) return 0;
    pa[q] = p;
    return 1;
  }
}disj;
int dx[400005];
map<int, int> mp;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
	vector<int> v;
	vector<int> crd;
	int n = (int) s.size();
	for(int i=0; i<n; i++){
		crd.push_back(s[i]);
		crd.push_back(t[i]);
	}
	sort(crd.begin(), crd.end());
	crd.resize(unique(crd.begin(), crd.end()) - crd.begin());
	disj.init(crd.size());
	for(int i=0; i<n; i++){
		s[i] = lower_bound(crd.begin(), crd.end(), s[i]) - crd.begin();
		t[i] = lower_bound(crd.begin(), crd.end(), t[i]) - crd.begin();
		dx[s[i]]--;
		dx[t[i]]++;
		disj.uni(s[i], t[i]);
	}
	int cur = 1;
	for(int i=0; i<crd.size(); i++){
		cur += dx[i];
		if(cur < 0) return 0;
		if(cur > 0 && i+1 < crd.size()) disj.uni(i, i+1);
	}
	for(int i=1; i<crd.size(); i++){
		if(disj.find(0) != disj.find(i)) return 1;
	}
	return 0;
}

Compilation message

railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<crd.size(); i++){
                ^
railroad.cpp:46:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(cur > 0 && i+1 < crd.size()) disj.uni(i, i+1);
                     ^
railroad.cpp:48:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<crd.size(); i++){
                ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB n = 2
2 Correct 0 ms 5152 KB n = 2
3 Correct 0 ms 5152 KB n = 2
4 Correct 0 ms 5152 KB n = 2
5 Correct 0 ms 5152 KB n = 2
6 Incorrect 0 ms 5152 KB answer is not correct: 0 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB n = 2
2 Correct 0 ms 5152 KB n = 2
3 Correct 0 ms 5152 KB n = 2
4 Correct 0 ms 5152 KB n = 2
5 Correct 0 ms 5152 KB n = 2
6 Incorrect 0 ms 5152 KB answer is not correct: 0 instead of 523688153
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 213 ms 11444 KB n = 199999
2 Incorrect 256 ms 11444 KB answer is not correct: 0 instead of 1
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB n = 2
2 Correct 0 ms 5152 KB n = 2
3 Correct 0 ms 5152 KB n = 2
4 Correct 0 ms 5152 KB n = 2
5 Correct 0 ms 5152 KB n = 2
6 Incorrect 0 ms 5152 KB answer is not correct: 0 instead of 523688153
7 Halted 0 ms 0 KB -