結果

問題 No.122 傾向と対策:門松列(その3)
ユーザー krotonkroton
提出日時 2015-01-09 03:47:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 936 bytes
コンパイル時間 1,431 ms
コンパイル使用メモリ 144,608 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:44:01
合計ジャッジ時間 2,103 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
4,376 KB
testcase_01 AC 15 ms
4,376 KB
testcase_02 AC 14 ms
4,380 KB
testcase_03 AC 15 ms
4,376 KB
testcase_04 AC 15 ms
4,384 KB
testcase_05 AC 14 ms
4,380 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 16 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], dp[1<<8];

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

int solve(int small, int big){
	memset(dp, 0, sizeof(dp));

	dp[0] = 1;
	for(int x=1;x<=20000;x++){
		for(int S=(1<<7)-1;S>0;S--){
			bool small_done = (S & small) == small;
			bool big_exist = (S & big) != 0;

			if(!small_done && big_exist)
				continue;

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

				if(((small >> i) & 1) && big_exist)
					continue;

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

				add(dp[S], dp[S^(1<<i)]);
			}
		}
	}

	return dp[(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