結果

問題 No.663 セルオートマトンの逆操作
ユーザー bal4ubal4u
提出日時 2019-08-14 15:32:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,057 bytes
コンパイル時間 226 ms
コンパイル使用メモリ 30,524 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 18:08:31
合計ジャッジ時間 1,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 0 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:13:24: note: in expansion of macro 'gc'
   13 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// yukicoder: No.663 セルオートマトンの逆操作
// bal4u 2019.8.14

#include <stdio.h>

#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 N;
char e[2002];
int dp[2002][2][2];
int a[4][2] = {{0,0},{0,1},{1,0},{1,1}};

int main()
{
	int i, j, ans;
	
	N = in();
	for (i = 0; i < N; i++) e[i] = gc() & 1, gc();
	ans = 0;
	for (j = 0; j < 4; j++) {
		dp[0][0][0] = dp[0][0][1] = dp[0][1][0] = dp[0][1][1] = 0;
		dp[0][a[j][0]][a[j][1]] = 1;
		if (dp[0][0][1] && e[0] == 0) continue;
		for (i = 1; i <= N; i++) {
			if (e[i-1]) {
				dp[i][1][0] = (dp[i-1][0][1] + dp[i-1][1][1]) % MOD;
				dp[i][0][1] = (dp[i-1][0][0] + dp[i-1][1][0]) % MOD;
				dp[i][1][1] = dp[i-1][0][1];
			} else {
				dp[i][0][0] = (dp[i-1][0][0] + dp[i-1][1][0]) % MOD;
				dp[i][1][1] = dp[i-1][1][1];
			}
		}
		ans = (ans + dp[N][a[j][0]][a[j][1]]) % MOD;
	}
	printf("%d\n", ans);
	return 0;
}
0