結果

問題 No.158 奇妙なお使い
ユーザー codershifthcodershifth
提出日時 2015-10-14 23:36:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,214 bytes
コンパイル時間 1,738 ms
コンパイル使用メモリ 146,364 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-28 21:08:17
合計ジャッジ時間 4,262 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 19 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

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