Submission #121455

# Submission time Handle Problem Language Result Execution time Memory
121455 2019-06-26T14:18:37 Z TadijaSebez Teleporters (IOI08_teleporters) C++11
90 / 100
1000 ms 55188 KB
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define pb push_back
const int N=1000050;
const int M=2*N;
int x[M],my[M];
vector<int> id;
int go[M];
bool comp(int i, int j){ return x[i]<x[j];}
bool was[M];
int sz;
void DFS(int u)
{
	if(was[u]) return;
	was[u]=1;if(u!=1) sz++;
	if(go[u]) DFS(go[u]);
}
int main()
{
	int n,m,i;
	scanf("%i %i",&n,&m);
	for(i=1;i<=n;i++)
	{
		id.pb(i<<1);
		id.pb(i<<1|1);
		scanf("%i %i",&x[i<<1],&x[i<<1|1]);
	}
	sort(id.begin(),id.end(),comp);
	id.pb(1);
	for(i=0;i<id.size();i++) my[id[i]]=i;
	for(i=0;i<id.size()-1;i++)
	{
		int g=id[i]^1;
		int p=my[g];
		go[id[i]]=id[p+1];
	}
	DFS(id[0]);
	int path=sz;
	//printf("path:%i\n",path);
	vector<int> cyc;
	for(i=1;i<id.size()-1;i++)
	{
		if(!was[id[i]]) sz=0,DFS(id[i]),cyc.pb(sz);//,printf("cycle:%i\n",sz);
	}
	int sol=path;
	sort(cyc.rbegin(),cyc.rend());
	int k=0;
	for(i=0;i<m && i<cyc.size();i++)
	{
		sol+=cyc[i]+2;
		k++;
	}
	m-=k;
	int ok=0;
	while(m--)
	{
		if(ok) sol+=3;
		else sol+=1;
		ok^=1;
	}
	printf("%i\n",sol);
	return 0;
}

Compilation message

teleporters.cpp: In function 'int main()':
teleporters.cpp:32:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<id.size();i++) my[id[i]]=i;
          ~^~~~~~~~~~
teleporters.cpp:33:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<id.size()-1;i++)
          ~^~~~~~~~~~~~
teleporters.cpp:43:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=1;i<id.size()-1;i++)
          ~^~~~~~~~~~~~
teleporters.cpp:50:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<m && i<cyc.size();i++)
                 ~^~~~~~~~~~~
teleporters.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
teleporters.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i %i",&x[i<<1],&x[i<<1|1]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 7 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 512 KB Output is correct
2 Correct 10 ms 1024 KB Output is correct
3 Correct 17 ms 1752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 5280 KB Output is correct
2 Correct 232 ms 11524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 8576 KB Output is correct
2 Correct 323 ms 16604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 564 ms 25084 KB Output is correct
2 Correct 689 ms 29580 KB Output is correct
3 Correct 674 ms 35308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 930 ms 33352 KB Output is correct
2 Correct 928 ms 36360 KB Output is correct
3 Execution timed out 1004 ms 33888 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 967 ms 40500 KB Output is correct
2 Execution timed out 1042 ms 55188 KB Time limit exceeded
3 Halted 0 ms 0 KB -