Submission #95026

# Submission time Handle Problem Language Result Execution time Memory
95026 2019-01-27T03:29:35 Z Retro3014 Teleporters (IOI08_teleporters) C++17
65 / 100
746 ms 66560 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>

#define MAX_X 2000000
using namespace std;
int N, M;
struct S{
	S(int x, int y) : x(x), y(y) {}
	int x, y;
};
vector<S> v;
int g[MAX_X+1];
vector<int> v2;
int l[MAX_X+1], r[MAX_X+1];
bool vst[MAX_X+1];

vector<int> cycle;
int ans;

void dfs(int x, int y){
	if(vst[x]){
		cycle.push_back(y);
		return;
	}
	vst[x] = true;
	if(x==v2.size()-1){
		ans+=y;
		return;
	}
	dfs(r[x], y+1);
}

int main(){
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; i++){
		int a, b; scanf("%d%d", &a, &b);
		v.push_back({a, b});
		v2.push_back(a); v2.push_back(b);
	}
	v2.push_back(0); sort(v2.begin(), v2.end());
	for(int i=0; i<v2.size(); i++){
		g[v2[i]] = i;
	}
	for(int i=0; i<v.size(); i++){
		S now = v[i];
		r[g[now.x]-1] = g[now.y];
		l[g[now.x]] = g[now.y]-1;
		r[g[now.y]-1] = g[now.x];
		l[g[now.y]] = g[now.x]-1;
	}
	for(int i=0; i<v2.size(); i++){
		if(vst[i])	continue;
		dfs(i, 0);
	}
	sort(cycle.begin(), cycle.end());
	while(M--){
		if(cycle.empty()){
			ans+=2;
		}else{
			ans+=2+cycle.back();
			cycle.pop_back();
		}
	}
	printf("%d", ans);
	return 0;
}

Compilation message

teleporters.cpp: In function 'void dfs(int, int)':
teleporters.cpp:28:6: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(x==v2.size()-1){
     ~^~~~~~~~~~~~~
teleporters.cpp: In function 'int main()':
teleporters.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v2.size(); i++){
               ~^~~~~~~~~~
teleporters.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++){
               ~^~~~~~~~~
teleporters.cpp:53:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v2.size(); i++){
               ~^~~~~~~~~~
teleporters.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
teleporters.cpp:38:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 6 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 11492 KB Output is correct
2 Correct 211 ms 26816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 18584 KB Output is correct
2 Incorrect 325 ms 42056 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 46028 KB Output is correct
2 Correct 535 ms 53332 KB Output is correct
3 Runtime error 553 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Incorrect 689 ms 63444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 746 ms 66560 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -