結果

問題 No.384 マス埋めゲーム2
ユーザー taro305taro305
提出日時 2016-07-06 22:35:30
言語 C90
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,326 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 25,252 KB
実行使用メモリ 569,192 KB
最終ジャッジ日時 2023-08-03 00:55:26
合計ジャッジ時間 2,979 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 RE -
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 0 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 0 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 RE -
testcase_11 AC 1 ms
4,380 KB
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int **s;
int h, w, n, k;
int s_count;
int p_count = 1;

int check(int a, int b);
void set();
void count();

int main(void){
	int i, j;

	scanf("%d %d %d %d", &h, &w, &n, &k);
	s_count = h * w;
	s = malloc(sizeof(int *) * h);
	for(i = 0; i < h; i++){
		s[i] = malloc(sizeof(int *) * w);
	}
	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			s[i][j] = 0;
		}
	}

	for(i = 0; i < h; i++){
		for(j = 0; j < w; j++){
			if(s[i][j] == 0){
				set(i, j, check(i, j));
			}
		}
	}

	for(i = 0; i < h; i++){
		free(s[i]);
	}
	free(s);
	return 0;
}

int check(int a, int b){
	int sum = 0;
	int i, j;

	for(i = 0; i < h; i++){
		if(s[i][b] == 0)
			sum += 1;
	}

	if(sum == s_count){
		sum = 0;
		for(i = 0; i < w; i++){
			if(s[a][i] == 0)
				sum += 1;
		}

		if(sum == s_count)	return 0;
		else				return 1;
	}
	else	return 2;
}

void set(int a, int b, int c){
	int i;
	switch(c){
		case 0:
			if(p_count == k)	printf("YES\n");
			else				printf("NO\n");
			break;

		case 1:
			for(i = 0; i < w; i++){
				if(s[a][i] == 0){
					s[a][i] = 1;
					s_count--;
				}
			}
			count();
			break;

		case 2:
			for(i = 0; i < h; i++){
				if(s[i][b] == 0){
					s[i][b] = 1;
					s_count--;
				}
			}
			count();
			break;
	}
}

void count(){
	p_count++;
	if(p_count == n + 1)
		p_count = 1;
}
0