結果

問題 No.226 0-1パズル
ユーザー bal4ubal4u
提出日時 2019-08-05 16:45:59
言語 C
(gcc 12.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,498 bytes
コンパイル時間 354 ms
コンパイル使用メモリ 30,524 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-04 12:07:51
合計ジャッジ時間 1,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 0 ms
4,376 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 0 ms
4,376 KB
testcase_18 AC 0 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:9:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:15:24: 備考: in expansion of macro ‘gc’
   15 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.226 0-1パズル
// 2019.8.5 bal4u

#include <stdio.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define MOD 1000000007

int H, W;
char rr[105][2], cc[105][2];

int main()
{
	int r, c, ar, ac;
	
	H = in(), W = in();
	for (r = 0; r < H; r++) {
		for (c = 0; c < W; c++) {
			int s = gc();
			if      (s == '0') rr[r][c & 1] |= 1, cc[c][r & 1] |= 1;
			else if (s == '1') rr[r][c & 1] |= 2, cc[c][r & 1] |= 2;
		}
		gc();
	}

	ac = ar = 1;
	for (c = 0; c < W; c++) {
		if (cc[c][0] == 0 && cc[c][1] == 0) ac = ((ll)ac << 1) % MOD;
		else if (cc[c][0] == 3 || cc[c][1] == 3) { ac = 0; break; }
		else if ((cc[c][0] ^ cc[c][1]) == 0) { ac = 0; break; } 
	}
	for (r = 0; r < H; r++) {
		if (rr[r][0] == 0 && rr[r][1] == 0) ar = ((ll)ar << 1) % MOD;
		else if (rr[r][0] == 3 || rr[r][1] == 3) { ar = 0; break; }
		else if ((rr[r][0] ^ rr[r][1]) == 0) { ar = 0; break; }
	}
	if (ar && ac) {
		int i, k = (H >= W)? H: W, fe, fo, f;
		fe = fo = f = 0;
		for (i = 0; i < k; i++) {
			if (rr[i][0] || rr[i][1] || cc[i][0] || cc[i][1]) f = 1;
			if (i & 1) fo |= rr[i][0] | cc[i][0];
			else       fe |= rr[i][1] | cc[i][1];
		}
		if (fo == 0 && fe == 0) { if (f) ar--; }
		else if (fo == 1) ar--;
		else if (fe == 2) ar--;
	}
	ar = (ar + ac) % MOD;
	if (ar < 0) ar += MOD;
	printf("%d\n", ar);
	return 0;
}
0