結果

問題 No.122 傾向と対策:門松列(その3)
ユーザー koyumeishikoyumeishi
提出日時 2016-04-04 23:31:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 5,000 ms
コード長 3,605 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 118,320 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-19 07:14:25
合計ジャッジ時間 1,924 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,552 KB
testcase_01 AC 15 ms
7,552 KB
testcase_02 AC 19 ms
7,680 KB
testcase_03 AC 17 ms
7,552 KB
testcase_04 AC 17 ms
7,552 KB
testcase_05 AC 21 ms
7,552 KB
testcase_06 AC 15 ms
7,552 KB
testcase_07 AC 13 ms
7,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <functional>
#include <set>
#include <ctime>
#include <random>
#include <chrono>
#include <cassert>
using namespace std;

namespace my_io{
	template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;}
	template<class T> istream& operator ,  (istream& is, T& val){ return is >> val;}
	template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;}
	template<class T> ostream& operator ,  (ostream& os, const T& val){ return os << " " << val;}
	template<class T> ostream& operator >> (ostream& os, const T& val){ return os << " " << val;}

	template<class H> void println(const H& head){ cout << head << endl; }
	template<class H, class ... T> void println(const H& head, const T& ... tail){ cout << head << " "; println(tail...); }
}
using namespace my_io;

const long long MOD = 1000000007;

int main(){
	vector<vector<int>> v(7, vector<int>(2));
	cin >> v;

	int low  = 1;
	int high = 20000;

	vector<int> A = {0,2,4,6};
	vector<int> B = {1,3,5};

	long long ans = 0;

	{//A < B
		vector<vector<long long>> dp_A(1<<4, vector<long long>(20005,0));
		vector<vector<char>>   dp_A_ok(1<<4, vector<char>(20005,0));

		vector<vector<long long>> dp_B(1<<3, vector<long long>(20005,0));
		vector<vector<char>>   dp_B_ok(1<<3, vector<char>(20005,0));

		for(int a=low; a<=high; a++){
			for(int k=0; k<(1<<4)-1; k++){
				dp_A[k][a] += dp_A[k][a-1];
				dp_A[k][a] %= MOD;

				for(int x=0; x<4; x++){
					if((k>>x)&1) continue;
					if(a < v[A[x]][0] || v[A[x]][1] < a) continue;

					dp_A[k|(1<<x)][a] += dp_A[k][a-1] + (k==0?1:0);
					dp_A[k|(1<<x)][a] %= MOD;
					dp_A_ok[k|(1<<x)][a] = 1;
				}

			}
		}

		for(int a=high; a>=low; a--){
			for(int k=0; k<(1<<3); k++){
				dp_B[k][a] += dp_B[k][a+1];
				dp_B[k][a] %= MOD;

				for(int x=0; x<3; x++){
					if((k>>x)&1) continue;
					if(a < v[B[x]][0] || v[B[x]][1] < a) continue;
					dp_B[k|(1<<x)][a] += dp_B[k][a+1] + (k==0?1:0);
					dp_B[k|(1<<x)][a] %= MOD;
					dp_B_ok[k|(1<<x)][a] = 1;
				}

			}
		}

		for(int a=low; a<=high; a++){
			if(dp_A_ok[0b1111][a] == 0) continue;
			ans += dp_A[0b1111][a] * dp_B[0b111][a+1] % MOD;
			ans %= MOD;
		}
	}

	{//A > B
		vector<vector<long long>> dp_A(1<<4, vector<long long>(20005,0));
		vector<vector<char>>   dp_A_ok(1<<4, vector<char>(20005,0));

		vector<vector<long long>> dp_B(1<<3, vector<long long>(20005,0));
		vector<vector<char>>   dp_B_ok(1<<3, vector<char>(20005,0));

		for(int a=high; a>=low; a--){
			for(int k=0; k<(1<<4); k++){
				dp_A[k][a] += dp_A[k][a+1];
				dp_A[k][a] %= MOD;

				for(int x=0; x<4; x++){
					if((k>>x)&1) continue;
					if(a < v[A[x]][0] || v[A[x]][1] < a) continue;
					dp_A[k|(1<<x)][a] += dp_A[k][a+1] + (k==0?1:0);
					dp_A[k|(1<<x)][a] %= MOD;
					dp_A_ok[k|(1<<x)][a] = 1;
				}

			}
		}

		for(int a=low; a<=high; a++){
			for(int k=0; k<(1<<3)-1; k++){
				dp_B[k][a] += dp_B[k][a-1];
				dp_B[k][a] %= MOD;

				for(int x=0; x<3; x++){
					if((k>>x)&1) continue;
					if(a < v[B[x]][0] || v[B[x]][1] < a) continue;
					dp_B[k|(1<<x)][a] += dp_B[k][a-1] + (k==0?1:0);
					dp_B[k|(1<<x)][a] %= MOD;
					dp_B_ok[k|(1<<x)][a] = 1;
				}

			}
		}

		for(int a=low; a<=high; a++){
			if(dp_B_ok[0b111][a] == 0) continue;
			ans += dp_B[0b111][a] * dp_A[0b1111][a+1] % MOD;
			ans %= MOD;
		}
	}

	println(ans);

	return 0;
}
0