結果

問題 No.122 傾向と対策:門松列(その3)
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2017-04-18 16:42:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 5,000 ms
コード長 1,412 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 170,672 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 13:15:45
合計ジャッジ時間 2,632 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)


int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
int MIN[7], MAX[7];
//-----------------------------------------------------------------------------------
int dp[8][20101];
int count(vector<int> v) {
    rep(i, 0, 8) rep(j, 0, 20101) dp[i][j] = 0;

    dp[0][0] = 1;
    rep(i, 1, 8) {
        int vi = v[i - 1];
        int sm = 0;
        rep(j, 0, MIN[vi]) sm = add(sm, dp[i - 1][j]);
        rep(j, MIN[vi], MAX[vi] + 1) {
            dp[i][j] = sm, sm = add(sm, dp[i - 1][j]);
        }
    }

    int res = 0;
    rep(j, 0, 20101) res = add(res, dp[7][j]);
    return res;
}
//-----------------------------------------------------------------------------------
int main() {
    rep(i, 0, 7) scanf("%d%d", &MIN[i], &MAX[i]);

    int ans = 0;

    vector<int> a({ 0,2,4,6 }), b({ 1,3,5 });
    do do {
            vector<int> v;
            copy(a.begin(), a.end(), back_inserter(v));
            copy(b.begin(), b.end(), back_inserter(v));
            ans = add(ans, count(v));
            v.clear();
            copy(b.begin(), b.end(), back_inserter(v));
            copy(a.begin(), a.end(), back_inserter(v));
            ans = add(ans, count(v));
    } while (next_permutation(b.begin(), b.end()));
      while (next_permutation(a.begin(), a.end()));

    cout << ans << endl;
}
0