Submission #1142236


Source Code Expand

#include <stdio.h>

char c[51][50];
char b[50][50];

char r[16384][8][2];
int rc;

#define SET(rc, i, x, y) r[rc][i][1] = y; r[rc][i][0] = x; b[y][x] = 1;

#define CU(c)	c[y - 1][x]
#define CD(c)	c[y + 1][x]
#define CL(c)	c[y][x - 1]
#define CR(c)	c[y][x + 1]
#define CUL(c)	c[y - 1][x - 1]
#define CUR(c)	c[y - 1][x + 1]
#define CDL(c)	c[y + 1][x - 1]
#define CDR(c)	c[y + 1][x + 1]

#define CAROUND(c) (CU(c) * CD(c) * CL(c) * CR(c) * \
	CUL(c) * CUR(c) * CDL(c) * CDR(c))
#define CAROUNDS(c) (CU(c) + CD(c) + CL(c) + CR(c) + \
	CUL(c) + CUR(c) + CDL(c) + CDR(c))

#define VALID(x, y) (0 <= x && x < 50 && 0 <= y && y < 50 && c[y][x] != 0 && b[y][x] == 0)

char nList[4][2] = {
	{0, 1},
	{1, 0},
	{-1, 0},
	{0, -1}
};

int main(int argc, char *argv[])
{
	int score;
	int sc;
	int x, y, k, i, t;
	fgets(c[0], 50 * 2, stdin);	// skip first line
	for(y = 0; y < 50; y ++){
		fgets(c[y], 50 * 2, stdin);
	}

	for(y = 0; y < 50; y++){
		for(x = 0; x < 50; x++){
			c[y][x] -= '0';
		}
	}
	// 0の周囲
	/*
	for(y = 1; y < 49; y++){
		for(x = 1; x < 49; x++){
			if(!c[y][x]){
				if(CAROUND(c) != 0 && CAROUNDS(b) == 0){
						SET(rc, 0, x + 1, y + 1);
						SET(rc, 1, x - 1, y - 1);
						SET(rc, 2, x - 1, y + 1);
						SET(rc, 3, x + 1, y - 1);
						SET(rc, 4, x, y + 1);
						SET(rc, 5, x, y - 1);
						SET(rc, 6, x + 1, y);
						SET(rc, 7, x - 1, y);
						rc++;
					}
			}
		}
	}
	*/
/*	
	// 横方向
	for(y = 0; y < 50; y++){
		k = 0;
		for(x = 0; x < 50; x++){
			if(c[y][x] == 0 || b[y][x]){
				k = 0;
			} else{
				k++;
				if(k == 8){
					for(i = 0; i < 8; i++){
						r[rc][i][0] = x - i;
						r[rc][i][1] = y;
						b[y][x - i] = 1;
					}
					rc++;
					k = 0;
				}
			}
		}
	}
	// 縦方向
	for(x = 0; x < 50; x++){
		k = 0;
		for(y = 0; y < 50; y++){
			if(c[y][x] == 0 || b[y][x]){
				k = 0;
			} else{
				k++;
				if(k == 8){
					for(i = 0; i < 8; i++){
						r[rc][i][0] = x;
						r[rc][i][1] = y - i;
						b[y][x] = 1;
					}
					rc++;
					k = 0;
				}
			}
		}
	}
*/
	k = 0;
	int nx, ny, cx, cy;
	for(t = 0; t < 50 * 50; t++){
		y = t / 50;
		x = t % 50;
		if(c[y][x] < 7 || b[y][x] != 0) continue;
		for(k--; k >= 0; k--){
			b[r[rc][k][1]][r[rc][k][0]] = 0;
		}
		k = 0;
		for(;;){
			SET(rc, k, x, y);
			int max = -1;
			for(i = 0; i < 4; i++){
				nx = nList[i][0] + x;
				ny = nList[i][1] + y;
				if(!VALID(nx, ny)) continue;
				if(max < c[ny][nx]){
					max = c[ny][nx];
					cx = nx;
					cy = ny;
				}
			}
			if(max == -1) break;
			x = cx;
			y = cy;
			k++;
			if(k == 8){
				k = 0;
				rc++;
			}
			
		}
	}
	for(t = 0; t < 50 * 50; t++){
		y = t / 50;
		x = t % 50;
		if(c[y][x] == 0 || b[y][x] != 0) continue;
		for(k--; k >= 0; k--){
			b[r[rc][k][1]][r[rc][k][0]] = 0;
		}
		k = 0;
		for(;;){
			SET(rc, k, x, y);
			int max = -1;
			for(i = 0; i < 4; i++){
				nx = nList[i][0] + x;
				ny = nList[i][1] + y;
				if(!VALID(nx, ny)) continue;
				if(max < c[ny][nx]){
					max = c[ny][nx];
					cx = nx;
					cy = ny;
				}
			}
			if(max == -1) break;
			x = cx;
			y = cy;
			k++;
			if(k == 8){
				k = 0;
				rc++;
			}
			
		}
	}

	printf("%d\n", rc);
	score = 0;
	for(i = 0; i < rc; i++){
		sc = 1;
		for(x = 0; x < 8; x++){
			sc *= c[r[i][x][1]][r[i][x][0]];
			printf("%d %d\n", r[i][x][1] + 1, r[i][x][0] + 1);
		}
		fprintf(stderr, "%d\n", sc);
		score += sc;
	}
	fprintf(stderr, "%d\n", score);

	return 0;
}



Submission Info

Submission Time
Task A - Multiple Pieces
User hikalium
Language C (GCC 5.4.1)
Score 411344
Code Size 3581 Byte
Status AC
Exec Time 1 ms
Memory 128 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:39:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  fgets(c[0], 50 * 2, stdin); // skip first line
  ^
./Main.c:41:3: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
   fgets(c[y], 50 * 2, stdin);
   ^

Judge Result

Set Name test_01 test_02 test_03 test_04 test_05 test_06 test_07 test_08 test_09 test_10
Score / Max Score 36364 / 1343058 36263 / 1343058 40487 / 1343058 34334 / 1343058 40635 / 1343058 42817 / 1343058 46365 / 1343058 43148 / 1343058 42803 / 1343058 48128 / 1343058
Status
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
AC × 1
Set Name Test Cases
test_01 subtask_01_01.txt
test_02 subtask_01_02.txt
test_03 subtask_01_03.txt
test_04 subtask_01_04.txt
test_05 subtask_01_05.txt
test_06 subtask_01_06.txt
test_07 subtask_01_07.txt
test_08 subtask_01_08.txt
test_09 subtask_01_09.txt
test_10 subtask_01_10.txt
Case Name Status Exec Time Memory
subtask_01_01.txt AC 1 ms 128 KB
subtask_01_02.txt AC 1 ms 128 KB
subtask_01_03.txt AC 1 ms 128 KB
subtask_01_04.txt AC 1 ms 128 KB
subtask_01_05.txt AC 1 ms 128 KB
subtask_01_06.txt AC 1 ms 128 KB
subtask_01_07.txt AC 1 ms 128 KB
subtask_01_08.txt AC 1 ms 128 KB
subtask_01_09.txt AC 1 ms 128 KB
subtask_01_10.txt AC 1 ms 128 KB