結果
問題 | No.122 傾向と対策:門松列(その3) |
ユーザー | 古寺いろは |
提出日時 | 2015-04-08 02:11:51 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 40 ms / 5,000 ms |
コード長 | 2,560 bytes |
コンパイル時間 | 1,269 ms |
コンパイル使用メモリ | 161,672 KB |
実行使用メモリ | 11,220 KB |
最終ジャッジ日時 | 2024-07-04 10:59:23 |
合計ジャッジ時間 | 2,030 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
9,416 KB |
testcase_01 | AC | 18 ms
9,292 KB |
testcase_02 | AC | 40 ms
11,220 KB |
testcase_03 | AC | 28 ms
10,320 KB |
testcase_04 | AC | 19 ms
9,548 KB |
testcase_05 | AC | 38 ms
11,084 KB |
testcase_06 | AC | 16 ms
9,168 KB |
testcase_07 | AC | 15 ms
9,036 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; #define MAX 20010 long long mod = (long long)1e9 + 7; long long lowdp1[1 << 4][MAX]; long long highdp1[1 << 4][MAX]; long long lowsum1[MAX]; long long lowsum2[MAX]; long long lowdp2[1 << 3][MAX]; long long highdp2[1 << 3][MAX]; int main(){ vector<int> low(7); vector<int> high(7); for (int i = 0; i < 7; i++) { cin >> low[i] >> high[i]; low[i] += 3; high[i] += 3; } lowdp1[0][0] = lowdp2[0][0] = 1; highdp1[0][MAX - 1] = highdp2[0][MAX - 1] = 1; for (int j = 1; j < MAX; j++) { for (int i = 0; i < (1 << 4) - 1; i++) { if (lowdp1[i][j - 1] == 0) continue; lowdp1[i][j] += lowdp1[i][j - 1]; lowdp1[i][j] %= mod; for (int k = 0; k < 4; k++) { if ((i >> k) % 2 == 1) continue; int t = k * 2; if (low[t] > j || high[t] < j) continue; lowdp1[i | (1 << k)][j] += lowdp1[i][j - 1]; lowdp1[i | (1 << k)][j] %= mod; } } lowsum1[j] = lowsum1[j - 1] + lowdp1[(1 << 4) - 1][j]; lowsum1[j] %= mod; } for (int j = 1; j < MAX; j++) { for (int i = 0; i < (1 << 3) - 1; i++) { if (lowdp2[i][j - 1] == 0) continue; lowdp2[i][j] += lowdp2[i][j - 1]; lowdp2[i][j] %= mod; for (int k = 0; k < 3; k++) { if ((i >> k) % 2 == 1) continue; int t = k * 2 + 1; if (low[t] > j || high[t] < j) continue; lowdp2[i | (1 << k)][j] += lowdp2[i][j - 1]; lowdp2[i | (1 << k)][j] %= mod; } } lowsum2[j] = lowsum2[j - 1] + lowdp2[(1 << 3) - 1][j]; lowsum2[j] %= mod; } for (int j = MAX - 2; j >= 0; j--) { for (int i = 0; i < (1 << 4) - 1; i++) { if (highdp1[i][j + 1] == 0) continue; highdp1[i][j] += highdp1[i][j + 1]; highdp1[i][j] %= mod; for (int k = 0; k < 4; k++) { if ((i >> k) % 2 == 1) continue; int t = k * 2; if (low[t] > j || high[t] < j) continue; highdp1[i | (1 << k)][j] += highdp1[i][j + 1]; highdp1[i | (1 << k)][j] %= mod; } } } for (int j = MAX - 2; j >= 0; j--) { for (int i = 0; i < (1 << 3) - 1; i++) { if (highdp2[i][j + 1] == 0) continue; highdp2[i][j] += highdp2[i][j + 1]; highdp2[i][j] %= mod; for (int k = 0; k < 3; k++) { if ((i >> k) % 2 == 1) continue; int t = k * 2 + 1; if (low[t] > j || high[t] < j) continue; highdp2[i | (1 << k)][j] += highdp2[i][j + 1]; highdp2[i | (1 << k)][j] %= mod; } } } long long ans = 0; for (int i = 1; i < MAX; i++) { ans += lowsum1[i - 1] * highdp2[(1 << 3) - 1][i]; ans += lowsum2[i - 1] * highdp1[(1 << 4) - 1][i]; ans %= mod; } cout << ans << endl; }