結果
| 問題 | No.122 傾向と対策:門松列(その3) | 
| コンテスト | |
| ユーザー |  Yang33 | 
| 提出日時 | 2018-04-27 00:08:20 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 5,000 ms | 
| コード長 | 4,843 bytes | 
| コンパイル時間 | 1,937 ms | 
| コンパイル使用メモリ | 176,064 KB | 
| 実行使用メモリ | 6,656 KB | 
| 最終ジャッジ日時 | 2024-06-27 21:28:14 | 
| 合計ジャッジ時間 | 2,414 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 8 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;
#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x<<", "
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* -----  2018/04/26  Problem: yukicoder 122  / Link: http://yukicoder.me/problems/no/122  ----- */
/* ------問題------
-----問題ここまで----- */
/* -----解説等-----
----解説ここまで---- */
LL N;
LL ans = 0LL;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int in[7][2];
	VI ord({ 0,4,1,5,2,6,3 });
	for (int i : ord) {
		cin >> in[i][0] >> in[i][1];
	}
	VVL Fset(20004, VL(2, 0));// a,c,e,g / b,d,f
	VVL Gset(20004, VL(2, 0));
	FOR(i, 1, 20000 + 1) {
		FOR(j, 0, 4) { // a,c,e,g
			int a = j % 4, c = (j + 1) % 4, e = (j + 2) % 4, g = (j + 3) % 4;
			if (in[a][0] <= i && i <= in[a][1]) { // base
				{ // F(i):=1つの数をiにして、i未満の選択をする組合せ
					LL s1 = max(0, min(i - 1 + 1, in[c][1] + 1) - in[c][0]);
					LL s2 = max(0, min(i - 1 + 1, in[e][1] + 1) - in[e][0]);
					LL s3 = max(0, min(i - 1 + 1, in[g][1] + 1) - in[g][0]);
					LL s12 = max(0, min({ i - 1 + 1,in[c][1] + 1,in[e][1] + 1 }) - max(in[c][0], in[e][0]));
					LL s23 = max(0, min({ i - 1 + 1,in[e][1] + 1,in[g][1] + 1 }) - max(in[e][0], in[g][0]));
					LL s31 = max(0, min({ i - 1 + 1,in[g][1] + 1,in[c][1] + 1 }) - max(in[g][0], in[c][0]));
					LL s123 = max(0, min({ i - 1 + 1, in[c][1] + 1,in[e][1] + 1,in[g][1] + 1 }) - max({ in[c][0],in[e][0],in[g][0] }));
					if (s1 > 0 && s2 > 0 && s3 > 0) {
						Fset[i][0] += s1*s2*s3;
						Fset[i][0] -= s12*s3;
						Fset[i][0] -= s23*s1;
						Fset[i][0] -= s31*s2;
						Fset[i][0] += 2 * s123;
					}
				}
				{ // G(i):=1つの数をiにして、iより大きい選択をする組合せ
					LL s1 = max(0, in[c][1] - max(i + 1 - 1, in[c][0] - 1));
					LL s2 = max(0, in[e][1] - max(i + 1 - 1, in[e][0] - 1));
					LL s3 = max(0, in[g][1] - max(i + 1 - 1, in[g][0] - 1));
					LL s12 = max(0, min(in[c][1], in[e][1]) - max({ i + 1 - 1, in[c][0] - 1,in[e][0] - 1 }));
					LL s23 = max(0, min(in[e][1], in[g][1]) - max({ i + 1 - 1, in[e][0] - 1,in[g][0] - 1 }));
					LL s31 = max(0, min(in[g][1], in[c][1]) - max({ i + 1 - 1, in[g][0] - 1,in[c][0] - 1 }));
					LL s123 = max(0, min({ in[c][1],in[e][1],in[g][1] }) - max({ i + 1 - 1,in[c][0]-1,in[e][0]-1,in[g][0]-1}));
					if (s1 > 0 && s2 > 0 && s3 > 0) {
						Gset[i][0] += s1*s2*s3;
						Gset[i][0] -= s12*s3;
						Gset[i][0] -= s23*s1;
						Gset[i][0] -= s31*s2;
						Gset[i][0] += 2 * s123;
					}
				}
			}
		}
		FOR(j, 0, 3) { // b,d,e
			int b = j % 3 + 4, d = (j + 1) % 3+ 4, f = (j + 2) % 3 + 4;
			if (in[b][0] <= i && i <= in[b][1]) { // base
				{ // F(i):=1つの数をiにして、i未満の選択をする組合せ
					LL s1 = max(0, min(i - 1 + 1, in[d][1] + 1) - in[d][0]);
					LL s2 = max(0, min(i - 1 + 1, in[f][1] + 1) - in[f][0]);
					LL s12 = max(0, min({ i - 1 + 1,in[d][1] + 1,in[f][1] + 1 }) - max(in[d][0], in[f][0]));
					if (s1 > 0 && s2 > 0) {
						Fset[i][1] += s1*s2;
						Fset[i][1] -= s12;
					}
				}
				{ // G(i):=1つの数をiにして、iより大きい選択をする組合せ
					LL s1 = max(0, in[d][1] - max(i + 1 - 1, in[d][0] - 1));
					LL s2 = max(0, in[f][1] - max(i + 1 - 1, in[f][0] - 1));
					LL s12 = max(0, min(in[d][1], in[f][1]) - max({ i + 1 - 1, in[d][0] - 1,in[f][0] - 1 }));
					if (s1 > 0 && s2 > 0) {
						Gset[i][1] += s1*s2;
						Gset[i][1] -= s12;
					}
				}
			}
		}
		// mod
		FOR(j, 0, 2) {
			Fset[i][j] %= MOD;
			(Fset[i][j] += MOD) %= MOD;
			Gset[i][j] %= MOD;
			(Gset[i][j] += MOD) %= MOD;
		}
		/*	debug(i) << endl;
			debug(Fset[i][0]); debug(Gset[i][1]) << endl;
			debug(Fset[i][1]); debug(Gset[i][0]) << endl;*/
	}
	// cumsum
	VVL Fsum(20004, VL(2, 0));
	FOR(i, 1, 20000 + 1) {
		FOR(j, 0, 2) {
			(Fsum[i][j] += Fsum[i - 1][j] + Fset[i][j]) %= MOD;
		}
	}
	FOR(i, 1, 20000 + 1) {
		FOR(j, 0, 2) {
			ans += Fsum[i][!j] * Gset[i + 1][j];
		}
		ans %= MOD;
		(ans += MOD) %= MOD;
	}
	cout << ans << "\n";
	return 0;
}
            
            
            
        