Submission #3453483


Source Code Expand

#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int H;
	int W;
	int N;
	int *x;
	int *y;
}node;

int max(int a, int b){
	return a >= b ? a : b;
}

int main(){
	int N, i, j, k, asum = 0, type;
	scanf("%d", &N);
	int *a = (int *)malloc(sizeof(int) * 2 * N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
		if(a[i] == 90){
			a[i] = 1;
		}
		else{
			a[i] = -1;
		}
		asum += a[i];
	}
	if(asum != 4){
		printf("-1\n");
		return 0;
	}
	for(i = 0; i < N; i++){
		a[N + i] = a[i];
	}
	int s[5];
	for(i = 0; a[i] == -1; i++);
	s[0] = i;
	for(k = 0; k < 3; k++){
		for(i = s[k] + 1, asum = 0; asum != 0 || a[i] == -1; i++){
			asum += a[i];
		}
		s[k + 1] = i;
	}
	s[4] = s[0] + N;
	int Ns[4];
	int **a_sub = (int **)malloc(sizeof(int *) * 4);
	node ***nodes = (node ***)malloc(sizeof(node **) * 4);
	node *new, *old, *old1, *old2;
	for(k = 0; k < 4; k++){
//		printf("k = %d\n", k);
		Ns[k] = s[k + 1] - s[k] - 1;
//		printf("Ns[k] = %d\n", Ns[k]);
		if(Ns[k] == 0){
			continue;
		}
		a_sub[k] = (int *)malloc(sizeof(int) * Ns[k]);
		nodes[k] = (node **)malloc(sizeof(node *) * Ns[k]);
		for(i = 0; i < Ns[k]; i++){
			a_sub[k][i] = a[s[k] + 1 + i];
			nodes[k][i] = NULL;
		}
		while(nodes[k][0] == NULL || nodes[k][0]->N < Ns[k]){
			for(i = 0; ; i++){
				if(nodes[k][i] == NULL){
					if(nodes[k][i + 1] == NULL){
						if(a_sub[k][i] + a_sub[k][i + 1] == 0){
							type = 0;
							break;
						}
					}
					else{
						j = i + 1 + nodes[k][i + 1]->N;
						if(nodes[k][j] == NULL && a_sub[k][i] + a_sub[k][j] == 0){
							type = 1;
							break;
						}
					}
				}
				else{
					j = i + nodes[k][i]->N;
					if(nodes[k][j] != NULL){
						type = 2;
						break;
					}
				}
			}
			new = (node *)malloc(sizeof(node));
			if(type == 0){
				new->H = 1;
				new->W = 0;
				new->N = 2;
				new->x = (int *)malloc(sizeof(int) * new->N);
				new->y = (int *)malloc(sizeof(int) * new->N);
				if(a_sub[k][i] == -1){
					new->x[0] = 0;
					new->y[0] = 0;
					new->x[1] = 0;
					new->y[1] = 1;
				}
				else{
					new->x[0] = 0;
					new->y[0] = 1;
					new->x[1] = 0;
					new->y[1] = 0;
				}
			}
			else if(type == 1){
				old = nodes[k][i + 1];
				new->H = old->W + 2;
				new->W = old->H;
				new->N = old->N + 2;
				new->x = (int *)malloc(sizeof(int) * new->N);
				new->y = (int *)malloc(sizeof(int) * new->N);
				if(a_sub[k][i] == -1){
					for(j = 0; j < old->N; j++){
						new->x[j + 1] = old->H - old->y[j];
						new->y[j + 1] = old->x[j] + 1;
					}
					new->x[0] = new->x[1];
					new->y[0] = 0;
					new->x[new->N - 1] = new->x[new->N - 2];
					new->y[new->N - 1] = new->H;
				}
				else{
					for(j = 0; j < old->N; j++){
						new->x[j + 1] = old->y[j];
						new->y[j + 1] = old->W + 1 - old->x[j];
					}
					new->x[0] = new->x[1];
					new->y[0] = new->H;
					new->x[new->N - 1] = new->x[new->N - 2];
					new->y[new->N - 1] = 0;
				}
			}
			else if(type == 2){
				old1 = nodes[k][i];
				old2 = nodes[k][i + old1->N];
				new->H = max(old1->y[old1->N - 1], old2->y[0]) + max(old1->H - old1->y[old1->N - 1], old2->H - old2->y[0]);
				new->W = old1->W + old2->W + 1;
				new->N = old1->N + old2->N;
				new->x = (int *)malloc(sizeof(int) * new->N);
				new->y = (int *)malloc(sizeof(int) * new->N);
				int dh1 = max(old1->y[old1->N - 1], old2->y[0]) - old1->y[old1->N - 1];
				for(j = 0; j < old1->N; j++){
					new->x[j] = old1->x[j];
					new->y[j] = old1->y[j] + dh1;
				}
				int dh2 = max(old1->y[old1->N - 1], old2->y[0]) - old2->y[0];
				for(j = 0; j < old2->N; j++){
					new->x[old1->N + j] = old2->x[j] + old1->W + 1;
					new->y[old1->N + j] = old2->y[j] + dh2;
				}
			}
			nodes[k][i] = new;
		}
	}
	int xo = 500000000, yo = 900000000, center = 500000000;
	int **x = (int **)malloc(sizeof(int *) * 4);
	int **y = (int **)malloc(sizeof(int *) * 4);
	for(k = 0; k < 4; k++){
/*		printf("Ns[%d] = %d\n", k, Ns[k]);
		if(Ns[k] > 0){
			printf("(H, W) = (%d, %d)\n", nodes[k][0]->H, nodes[k][0]->W);
		}
*/		x[k] = (int *)malloc(sizeof(int) * Ns[k]);
		y[k] = (int *)malloc(sizeof(int) * Ns[k]);
		for(i = 0; i < Ns[k]; i++){
//			printf("(%d, %d)\n", nodes[k][0]->x[i], nodes[k][0]->y[i]);
			x[k][i] = nodes[k][0]->x[i] + xo;
			y[k][i] = nodes[k][0]->y[i] + yo;
			for(j = 0; j < k; j++){
				int dx = x[k][i] - center;
				int dy = y[k][i] - center;
				x[k][i] = center + dy;
				y[k][i] = center - dx;
			}
//			printf("(%d, %d)\n", x[k][i], y[k][i]);
		}
	}
	int *ansx = (int *)malloc(sizeof(int) * 3 * N);
	int *ansy = (int *)malloc(sizeof(int) * 3 * N);
	for(i = 0; i < 3 * N; i++){
		ansx[i] = -1;
		ansy[i] = -1;
	}
	for(k = 0; k < 4; k++){
		for(i = 0; i < Ns[k]; i++){
			ansx[s[k] + 1 + i] = x[k][i];
			ansy[s[k] + 1 + i] = y[k][i];
			ansx[s[k] + 1 + i + N] = x[k][i];
			ansy[s[k] + 1 + i + N] = y[k][i];
		}
	}
	for(k = 1; k < 4; k++){
		if(k % 2 == 0){
			ansx[s[k]] = ansx[s[k] - 1];
			ansy[s[k]] = ansy[s[k] + 1];
		}
		else{
			ansx[s[k]] = ansx[s[k] + 1];
			ansy[s[k]] = ansy[s[k] - 1];
		}
		if(ansx[s[k]] == -1){
			if(k == 0 || k == 3){
				ansx[s[k]] = 2 * center - yo;
			}
			else{
				ansx[s[k]] = yo;
			}
		}
		if(ansy[s[k]] == -1){
			if(k == 2 || k == 3){
				ansy[s[k]] = 2 * center - yo;
			}
			else{
				ansy[s[k]] = yo;
			}
		}
	}
	for(k = 0; k < 4; k++){
		if(k % 2 == 0){
			ansx[s[k] + N] = ansx[s[k] + N - 1];
			ansy[s[k] + N] = ansy[s[k] + N + 1];
		}
		else{
			ansx[s[k] + N] = ansx[s[k] + N + 1];
			ansy[s[k] + N] = ansy[s[k] + N - 1];
		}
		if(ansx[s[k] + N] == -1){
			if(k == 0 || k == 3){
				ansx[s[k] + N] = 2 * center - yo;
			}
			else{
				ansx[s[k] + N] = yo;
			}
		}
		if(ansy[s[k] + N] == -1){
			if(k == 2 || k == 3){
				ansy[s[k] + N] = 2 * center - yo;
			}
			else{
				ansy[s[k] + N] = yo;
			}
		}
	}
	for(i = N; i < 2 * N; i++){
		printf("%d %d\n", 2 * center - ansx[i], ansy[i]);
/*		if(ansx[i] < 0 || 2 * center < ansx[i] || ansy[i] < 0 || 2 * center < ansy[i]){
			j = 0;
			ansx[i] /= j;
		}
*/	}
	return 0;
}

Submission Info

Submission Time
Task I - 90 and 270
User abc050
Language C (GCC 5.4.1)
Score 1500
Code Size 6203 Byte
Status AC
Exec Time 94 ms
Memory 97024 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:18:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ^
./Main.c:21:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1500 / 1500
Status
AC × 2
AC × 46
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 1 ms 128 KB
001.txt AC 1 ms 128 KB
002.txt AC 1 ms 128 KB
003.txt AC 1 ms 640 KB
004.txt AC 1 ms 384 KB
005.txt AC 1 ms 512 KB
006.txt AC 1 ms 768 KB
007.txt AC 1 ms 384 KB
008.txt AC 1 ms 256 KB
009.txt AC 1 ms 896 KB
010.txt AC 2 ms 1664 KB
011.txt AC 1 ms 128 KB
012.txt AC 2 ms 1152 KB
013.txt AC 3 ms 2688 KB
014.txt AC 1 ms 256 KB
015.txt AC 1 ms 512 KB
016.txt AC 5 ms 5376 KB
017.txt AC 1 ms 128 KB
018.txt AC 5 ms 4992 KB
019.txt AC 2 ms 1280 KB
020.txt AC 26 ms 21504 KB
021.txt AC 1 ms 128 KB
022.txt AC 40 ms 49792 KB
023.txt AC 2 ms 2048 KB
024.txt AC 2 ms 2176 KB
025.txt AC 2 ms 2560 KB
026.txt AC 3 ms 3712 KB
027.txt AC 3 ms 3584 KB
028.txt AC 8 ms 8448 KB
029.txt AC 4 ms 4352 KB
030.txt AC 6 ms 6272 KB
031.txt AC 4 ms 3840 KB
032.txt AC 5 ms 4608 KB
033.txt AC 10 ms 11136 KB
034.txt AC 13 ms 12800 KB
035.txt AC 14 ms 14848 KB
036.txt AC 12 ms 10240 KB
037.txt AC 30 ms 29824 KB
038.txt AC 13 ms 9856 KB
039.txt AC 43 ms 41728 KB
040.txt AC 52 ms 49152 KB
041.txt AC 94 ms 97024 KB
042.txt AC 63 ms 77824 KB
043.txt AC 1 ms 128 KB
example0.txt AC 1 ms 128 KB
example1.txt AC 1 ms 128 KB