Submission #16387

# Submission time Handle Problem Language Result Execution time Memory
16387 2015-08-22T04:47:13 Z comet Parachute rings (IOI12_rings) C++
20 / 100
1662 ms 263168 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define pb push_back
using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;
int N,mode;
vector<int> p[5],r[5];
mat path[5];

void init(int n,int k){
	p[k].resize(n);
	r[k].resize(n,0);
	path[k].assign(n,vec());
	for(int i=0;i<n;i++)p[k][i]=i;
}

int find(int x,int k){
	if(p[k][x]==x)return x;
	return p[k][x]=find(p[k][x],k);
}

bool merge(int x,int y,int k){
	x=find(x,k),y=find(y,k);
	if(x==y)return 0;
	if(r[k][x]>r[k][y])swap(x,y);
	p[k][x]=y;
	if(r[k][x]==r[k][y])r[k][y]++;
	return 1;
}

void finish(int k){
	p[k].clear();
	r[k].clear();
	path[k].clear();
}

bool CircleChk[1000000],chk[4];
int cnt,Ex[4];

void Init(int n){
	N=n;
	init(n,4);
}

int CountCritical(){
	// Base
	if(mode==0){
		return N;
	}

	// Circle
	else if(mode==1){
		return cnt;
	}

	// Divided
	else if(mode==2){
		cnt=0;
		for(int k=0;k<4;k++)if(!chk[k])cnt++;
		if(cnt==0)mode=-1;
		return cnt;
	}

	// End
	else{
		return 0;
	}
}

void CircleBfs(int v){
	queue<int> Q;
	Q.push(v);
	CircleChk[v]=1;
	while(!Q.empty()){
		v=Q.front();
		cnt++;
		Q.pop();
		for(int i=0;i<path[4][v].size();i++){
          	int u=path[4][v][i];
			if(!CircleChk[u]){
				Q.push(u);
				CircleChk[u]=1;
			}
		}
	}
}

void make_graph(int x,int k){
	init(N,k);
	Ex[k]=x;
	for(int i=0;i<N;i++){
		if(x==i)continue;
		for(int t=0;t<path[4][i].size();t++){
			int j=path[4][i][t];
			if(j==x)continue;
			path[k][i].pb(j);
			merge(i,j,k);
		}
		if(path[k][i].size()>2){
			chk[k]=1;
			finish(k);
			return;
		}
	}
}

void Link(int x,int y){
	//End
	if(mode<0)return;

	// Base
	if(mode==0){
		path[4][x].pb(y);
		path[4][y].pb(x);
		if(path[4][x].size()<path[4][y].size())swap(x,y);
		if(path[4][x].size()>2){
			mode=2;
			for(int i=0;i<3;i++)
				make_graph(path[4][x][i],i);
			make_graph(x,3);
			finish(4);
			return;
		}

		if(!merge(x,y,4)){
			cnt=0;
			mode=1;
			CircleBfs(x);
		}
	}


	// Circle
	else if(mode==1){
		path[4][x].pb(y);
		path[4][y].pb(x);
		if(!merge(x,y,4)){
			mode=-1;
			return;
		}
		if(path[4][x].size()<path[4][y].size())swap(x,y);
		if(path[4][x].size()>2){
			if(CircleChk[x]==0&&CircleChk[y]==0){
				mode=-1;
				return;
			}
			mode=2;
			for(int i=0;i<path[4][x].size();i++){
				if(!CircleChk[path[4][x][i]]){
					chk[i]=1;
					continue;
				}
				make_graph(path[4][x][i],i);
			}
			make_graph(x,3);
			finish(4);
			return;
		}
	}

	// Divided
	else if(mode==2){
		for(int k=0;k<4;k++){
			if(chk[k])continue;
			if(Ex[k]==x||Ex[k]==y)continue;
			path[k][x].pb(y);
			path[k][y].pb(x);
			if(!merge(x,y,k))chk[k]=1;
			if(path[k][x].size()<path[k][y].size())swap(x,y);
			if(path[k][x].size()>2){
				chk[k]=1;
				finish(k);
			}
		}
	}
}

Compilation message

rings.cpp: In function 'void CircleBfs(int)':
rings.cpp:81:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<path[4][v].size();i++){
               ~^~~~~~~~~~~~~~~~~~
rings.cpp: In function 'void make_graph(int, int)':
rings.cpp:96:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int t=0;t<path[4][i].size();t++){
               ~^~~~~~~~~~~~~~~~~~
rings.cpp: In function 'void Link(int, int)':
rings.cpp:151:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=0;i<path[4][x].size();i++){
                ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1652 KB Output is correct
3 Correct 7 ms 1652 KB Output is correct
4 Correct 3 ms 1652 KB Output is correct
5 Correct 4 ms 1652 KB Output is correct
6 Correct 6 ms 1652 KB Output is correct
7 Correct 4 ms 1652 KB Output is correct
8 Correct 4 ms 1652 KB Output is correct
9 Correct 8 ms 1836 KB Output is correct
10 Correct 9 ms 2000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 33348 KB Output is correct
2 Correct 1662 ms 195532 KB Output is correct
3 Correct 520 ms 195532 KB Output is correct
4 Correct 1229 ms 195532 KB Output is correct
5 Correct 1243 ms 195532 KB Output is correct
6 Correct 1290 ms 195532 KB Output is correct
7 Correct 470 ms 195532 KB Output is correct
8 Runtime error 1570 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1652 KB Output is correct
3 Correct 7 ms 1652 KB Output is correct
4 Correct 3 ms 1652 KB Output is correct
5 Correct 4 ms 1652 KB Output is correct
6 Correct 6 ms 1652 KB Output is correct
7 Correct 4 ms 1652 KB Output is correct
8 Correct 4 ms 1652 KB Output is correct
9 Correct 8 ms 1836 KB Output is correct
10 Correct 9 ms 2000 KB Output is correct
11 Runtime error 8 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1652 KB Output is correct
3 Correct 7 ms 1652 KB Output is correct
4 Correct 3 ms 1652 KB Output is correct
5 Correct 4 ms 1652 KB Output is correct
6 Correct 6 ms 1652 KB Output is correct
7 Correct 4 ms 1652 KB Output is correct
8 Correct 4 ms 1652 KB Output is correct
9 Correct 8 ms 1836 KB Output is correct
10 Correct 9 ms 2000 KB Output is correct
11 Runtime error 8 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1652 KB Output is correct
3 Correct 7 ms 1652 KB Output is correct
4 Correct 3 ms 1652 KB Output is correct
5 Correct 4 ms 1652 KB Output is correct
6 Correct 6 ms 1652 KB Output is correct
7 Correct 4 ms 1652 KB Output is correct
8 Correct 4 ms 1652 KB Output is correct
9 Correct 8 ms 1836 KB Output is correct
10 Correct 9 ms 2000 KB Output is correct
11 Correct 458 ms 33348 KB Output is correct
12 Correct 1662 ms 195532 KB Output is correct
13 Correct 520 ms 195532 KB Output is correct
14 Correct 1229 ms 195532 KB Output is correct
15 Correct 1243 ms 195532 KB Output is correct
16 Correct 1290 ms 195532 KB Output is correct
17 Correct 470 ms 195532 KB Output is correct
18 Runtime error 1570 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
19 Halted 0 ms 0 KB -