結果

問題 No.122 傾向と対策:門松列(その3)
ユーザー krotonkroton
提出日時 2015-01-09 03:17:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,035 bytes
コンパイル時間 1,156 ms
コンパイル使用メモリ 145,028 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 22:52:50
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,380 KB
testcase_01 AC 23 ms
4,380 KB
testcase_02 AC 25 ms
4,376 KB
testcase_03 AC 24 ms
4,376 KB
testcase_04 AC 24 ms
4,380 KB
testcase_05 AC 25 ms
4,380 KB
testcase_06 AC 24 ms
4,380 KB
testcase_07 AC 23 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int bdf  = (1 << 1) | (1 << 3) | (1 << 5);
const int aceg = ((1 << 7) - 1) ^ bdf;
const int MOD  = 1e9 + 7;

int low[10], high[10];
int dp[2][1<<8];

void add(int &a, int b){
	a += b;
	if(a >= MOD)
		a -= MOD;
}

int solve(int small, int big){
	int crr = 0, nxt = 1;
	memset(dp[crr], 0, sizeof(dp[crr]));

	dp[crr][0] = 1;
	for(int x=1;x<=20000;x++){
		for(int S=0;S<1<<7;S++)
			dp[nxt][S] = dp[crr][S];

		for(int S=0;S<1<<7;S++){
			bool small_done = (S & small) == small;
			if(!small_done && (S & big) != 0)
				continue;

			for(int i=0;i<7;i++){
				if((S >> i) & 1)
					continue;

				if(!small_done && ((big >> i) & 1))
					continue;

				if(x < low[i] || high[i] < x)
					continue;

				add(dp[nxt][S | (1 << i)], dp[crr][S]);
			}
		}

		swap(crr, nxt);
	}

	return dp[crr][(1 << 7) - 1];
}

int main(){
	for(int i=0;i<8;i++)
		cin >> low[i] >> high[i];

	int res = solve(bdf, aceg) + solve(aceg, bdf);
	if(res >= MOD)
		res -= MOD;

	cout << res << endl;
	return 0;
}
0