結果

問題 No.122 傾向と対策:門松列(その3)
ユーザー codershifthcodershifth
提出日時 2015-10-14 23:37:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 5,000 ms
コード長 2,214 bytes
コンパイル時間 1,297 ms
コンパイル使用メモリ 146,488 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 21:08:20
合計ジャッジ時間 2,199 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;

const int Mod = (int)1e9+7;
class TrendAndCountermeasures_PineDecorationSequence3 {
public:
    array<int,7> high;
    array<int,7> low;

    // min{ Set(small) } < max{ Set(big) }
    // となりかつ Set(small) u Set(big) の要素が全て異なるような組み合わせ
    ll calc(int small, int big) {
            // dp[x][S] := x 以下の数字をつかって条件を満たすような S を選ぶ選び方
            vector<ll> dp(1<<7, 0);

            dp[0] = 1;
            // 取りうる x 全てを見る
            for (int x = 1; x <= 20000; ++x)
            {
                // dp の更新が S が小さいもの(前の 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;

                    REP(i,7)
                    {
                        if ( !(S & (1<<i)))
                            continue;
                        if ( (small & (1<<i)) && big_exist )
                            continue;
                        if (x < low[i] || high[i] < x)
                            continue;
                        (dp[S] += dp[S^(1<<i)]) %= Mod;
                    }
                }
            }
            return dp[(1<<7)-1];
    }
    void solve(void) {
            const int bdf = (1<<1) | (1<<3) | (1<<5);
            const int aceg = ((1<<7)-1) ^ bdf;
            REP(i,7)
                cin>>low[i]>>high[i];
            ll res = calc(bdf, aceg) + calc(aceg, bdf);
            cout<<res % Mod<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new TrendAndCountermeasures_PineDecorationSequence3();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0