Submission #1316300
Source Code Expand
#include<stdio.h>
#include <time.h>
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define N 50
typedef struct {
int y;
int x;
} Point;
Point point_list[N*N];
int point_len;
int xorshift32() {
static int x = 123456789;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
if(x < 0) x *= -1;
return x;
}
void count_area(int y, int x, char tar, char map[N][N], int check[N][N], int *area) {
if(y < 0 || x < 0 || y >= N || x >= N || map[y][x] != tar || check[y][x]) return;
check[y][x] = 1;
(*area)++;
count_area(y+1, x, tar, map, check, area);
count_area(y-1, x, tar, map, check, area);
count_area(y, x+1, tar, map, check, area);
count_area(y, x-1, tar, map, check, area);
}
int evaluate(char map[N][N]) {
int check[N][N] = {{0}};
int area;
int max_o = 0, max_x = 0;
int i, j;
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
if(check[i][j] == 0) {
area = 0;
if(map[i][j] == 'o') {
count_area(i, j, 'o', map, check, &area);
max_o = MAX(max_o, area);
} else {
count_area(i, j, 'x', map, check, &area);
max_x = MAX(max_x, area);
}
}
}
}
return max_o + max_x;
}
void simulate(char map[N][N]) {
int i, j;
int cnt;
for(j=0;j<N;j++) {
cnt = 0;
for(i=N-1;i>=0;i--) {
if(map[i][j] == '.') {
cnt++;
} else if(map[i][j] == '-') {
cnt = 0;
} else {
map[i+cnt][j] = map[i][j];
if(cnt > 0) map[i][j] = '.';
}
}
}
}
void merge(char base[N][N], char input[N*N], char output[N][N]) {
int i, j, k = 0;
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
if(point_list[k].y == i && point_list[k].x == j) {
output[i][j] = input[k];
k++;
} else {
output[i][j] = base[i][j];
}
}
}
}
void print_map(char map[N][N]) {
int i, j;
for(i=0;i<N;i++,printf("\n")) {
for(j=0;j<N;j++) {
printf("%c", map[i][j]);
}
}
}
int main() {
int i, j;
char map[N][N];
char out[N][N];
char test[N*N];
char pre[N*N];
char next[N*N];
char ans[N*N];
int score;
int high_score = 0;
int back;
int back_char;
char state[] = {'.', '+', '-'};
time_t start, end;
start = time(NULL);
for(i=0;i<N;i++) {
scanf("%s", map[i]);
for(j=0;j<N;j++) {
if(map[i][j] == '.') {
point_list[point_len].y = i;
point_list[point_len].x = j;
point_len++;
}
}
}
for(i=0;i<point_len;i++) ans[i] = pre[i] = test[i] = '.';
merge(map, test, out);
simulate(out);
high_score = evaluate(out);
do {
//for(i=0;i<point_len;i++) {j = xorshift32() % 3;if(j == 0) {test[i] = '+';} else if(j == 1) {test[i] = '-';} else {test[i] = '.';}}
back = -1;
for(i=0;i<point_len;i++) {
for(j=0;j<2;j++) {
if(test[i] == state[j]) continue;
test[i] = state[j];
merge(map, test, out);
simulate(out);
score = evaluate(out);
if(score > high_score) {
//for(k=0;k<point_len;k++) ans[k] = test[k];
if(back >= 0) ans[back] = back_char;
back = i;
back_char = ans[i];
ans[i] = test[i];
high_score = score;
}
}
test[i] = pre[i];
}
for(i=0;i<point_len;i++) test[i] = pre[i] = ans[i];
end = time(NULL);
} while(difftime(end, start) < 10);
//printf("%d\n", high_score);
merge(map, ans, out);
//simulate(out);
//printf("%d\n", evaluate(out));
print_map(out);
return 0;
}
Submission Info
Submission Time
2017-05-29 08:08:42+0900
Task
A - ○×ブロック
User
Lhaplus
Language
C (GCC 5.4.1)
Score
4326
Code Size
3451 Byte
Status
AC
Exec Time
9759 ms
Memory
256 KB
Compile Error
./Main.c: In function ‘main’:
./Main.c:123:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", map[i]);
^
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
304 / 2500
481 / 2500
486 / 2500
436 / 2500
454 / 2500
435 / 2500
494 / 2500
281 / 2500
440 / 2500
515 / 2500
Status
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
9759 ms
256 KB
subtask_01_02.txt
AC
9566 ms
256 KB
subtask_01_03.txt
AC
9524 ms
256 KB
subtask_01_04.txt
AC
9517 ms
256 KB
subtask_01_05.txt
AC
9566 ms
256 KB
subtask_01_06.txt
AC
9551 ms
256 KB
subtask_01_07.txt
AC
9499 ms
256 KB
subtask_01_08.txt
AC
9528 ms
256 KB
subtask_01_09.txt
AC
9572 ms
256 KB
subtask_01_10.txt
AC
9560 ms
256 KB