結果

問題 No.384 マス埋めゲーム2
ユーザー taro305taro305
提出日時 2016-07-06 22:35:30
言語 C90
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,326 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 22,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 00:38:14
合計ジャッジ時間 2,830 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
5,248 KB
testcase_01 RE -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 RE -
testcase_11 AC 1 ms
5,376 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:16:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%d %d %d %d", &h, &w, &n, &k);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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