Submission #922

# Submission time Handle Problem Language Result Execution time Memory
922 2013-05-26T01:24:13 Z tncks0121 보도블록 (KOI11_block) C++
22 / 22
3 ms 884 KB
#include<stdio.h> 

int H,W; 

int main(){ 

	scanf("%d%d",&H,&W); 

	int x,y,c; 

	printf("%d",2*H*W); 
	if(H%2==0){ 
		x=1; y=2; c=0; 
		printf("\n1 1 1\n1 1 0"); 
		for(;x!=1||y!=1;){ 
			printf("\n%d %d %d",x,y,c); 
			if(x==H){ 
				if(c==y%2)c=1-y%2; 
				else{ 
					if(y==1)x--,y=1,c=1; 
					else y--,c=y%2; 
				} 

			}else if(y==1){ 
				if(c)c=0; 
				else{ 
					x--; c=1; 
				} 
			}else if(x%2==1){ 
				if(!c)c=1; 
				else{ 
					if(y==W)x++,y=W,c=(W%2); 
					else y++,c=0; 
				} 
			}else if(x%2==0){ 
				if(c==y%2)c=1-y%2; 
				else{ 
					if(y==2)x++,y=2,c=0; 
					else y--,c=y%2; 
				} 
			} 
		} 
	}else if(W%2==0){ 
		x=1; y=2; c=0; 
		printf("\n1 1 1\n1 1 0"); 
		for(;x!=1||y!=1;){ 
			printf("\n%d %d %d",x,y,c); 
			if(x==1){ 
				if(!c)c=1; 
				else{ 
					if(y==W)x++,c=0; 
					else y++,c=0; 
				} 
			} else if(y==1){ 
				if(c)c=0; 
				else x--,c=1; 
			} else if(y%2==0){ 
				if(x==H){ 
					if(c)c=0; 
					else y--,c=1; 
				}else{ 
					if(c==x%2)c=1-c; 
					else c=(++x)%2; 
				} 
			} else if(y%2==1){ 
				if(x==2){ 
					if(c)c=0; 
					else y--,c=0; 
				}else{ 
					if(c)c=0; 
					else c=1,x--; 
				} 
			} 
		} 
	}else if(H==3){ 
		printf("\n3 1 1\n3 1 0\n2 1 1\n2 1 0\n1 1 1\n1 1 0\n1 2 0\n2 2 0\n1 2 1"); 

		x=1; y=3; c=0; 
		for(;x==1;){ 
			printf("\n%d %d %d",x,y,c); 
			if(!c)c=1; 
			else{ 
				if(y==W)x=2,y=W,c=1; 
				else y++,c=0; 
			} 
		} 

		for(int i=0;x!=3||y!=3||c!=1;i++){ 
			printf("\n%d %d %d",x,y,c); 
			switch((i/2)%4){ 
			case 0: 
				if(c)c=0; 
				else x++,c=0; 
				break; 
			case 1: 
				if(!c)c=1; 
				else y--,c=1; 
				break; 
			case 2: 
				if(c)c=0; 
				else x--,c=1; 
				break; 
			case 3: 
				if(c)c=0; 
				else y--,c=1; 
				break; 
			} 
		} 

		printf("\n2 3 1\n2 2 1\n2 3 0"); 
	}else{ 
		x=H; y=1; c=1; 
		for(;x!=1||y!=1||c!=0;){ 
			printf("\n%d %d %d",x,y,c); 
			if(c)c=0; 
			else x--,c=1; 
		} 

		for(;x!=1||y!=W-2||c!=0;){ 
			printf("\n%d %d %d",x,y,c); 
			if(x==H-2&&y==2&&!c)printf("\n%d 2 0",H-1); 
			if(y%2){ 
				if(c)c=0; 
				else{ 
					if(x==1)y++,c=0; 
					else x--,c=1; 
				} 
			}else{ 
				if(!c)c=1; 
				else{ 
					if(x==H-2)y++,c=1; 
					else x++,c=0; 
				}                    
			} 
		} 

		printf("\n%d %d %d",x,y,c); 
		y++; 
		for(;x<H-1;){ 
			printf("\n%d %d %d",x,y,c); 
			if(x%2){ 
				if(!c)c=1; 
				else{ 
					if(y==W)x++,c=y%2; 
					else y++,c=0; 
				} 
			}else{ 
				if(c==y%2)c=1-c; 
				else{ 
					if(y==W-1)x++,c=0; 
					else c=(--y)%2; 
				} 
			} 
		} 

		for(int i=0;y>2;i++){ 
			printf("\n%d %d %d",x,y,c); 
			switch((i/2)%4){ 
			case 0: 
				if(c)c=0; 
				else x++,c=0; 
				break; 
			case 1: 
				if(!c)c=1; 
				else y--,c=1; 
				break; 
			case 2: 
				if(c)c=0; 
				else x--,c=1; 
				break; 
			case 3: 
				if(c)c=0; 
				else y--,c=1; 
				break; 
			} 
		} 

		printf("\n%d 2 1\n%d 2 1\n%d 2 0",H,H-1,H); 
	} 
	return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 884 KB Output is correct
2 Correct 0 ms 884 KB Output is correct
3 Correct 0 ms 884 KB Output is correct
4 Correct 0 ms 884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 884 KB Output is correct
2 Correct 0 ms 884 KB Output is correct
3 Correct 0 ms 884 KB Output is correct
4 Correct 0 ms 884 KB Output is correct
5 Correct 0 ms 884 KB Output is correct
6 Correct 0 ms 884 KB Output is correct
7 Correct 1 ms 884 KB Output is correct
8 Correct 0 ms 884 KB Output is correct
9 Correct 0 ms 884 KB Output is correct
10 Correct 2 ms 884 KB Output is correct
11 Correct 2 ms 884 KB Output is correct
12 Correct 3 ms 884 KB Output is correct
13 Correct 2 ms 884 KB Output is correct
14 Correct 3 ms 884 KB Output is correct
15 Correct 3 ms 884 KB Output is correct
16 Correct 3 ms 884 KB Output is correct