結果

問題 No.1426 Got a Covered OR
ユーザー trineutrontrineutron
提出日時 2021-03-12 22:26:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,554 bytes
コンパイル時間 2,808 ms
コンパイル使用メモリ 206,424 KB
実行使用メモリ 452,608 KB
最終ジャッジ日時 2024-04-22 13:29:44
合計ジャッジ時間 14,933 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 511 ms
452,480 KB
testcase_01 AC 514 ms
452,608 KB
testcase_02 AC 518 ms
452,608 KB
testcase_03 AC 518 ms
452,480 KB
testcase_04 AC 510 ms
452,608 KB
testcase_05 AC 513 ms
452,480 KB
testcase_06 AC 508 ms
452,480 KB
testcase_07 AC 512 ms
452,480 KB
testcase_08 AC 514 ms
452,480 KB
testcase_09 AC 511 ms
452,480 KB
testcase_10 AC 508 ms
452,608 KB
testcase_11 AC 510 ms
452,480 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>

using namespace std;
using namespace atcoder;

using mint = modint1000000007;

vector memo(100001, vector(30, vector(30, -1)));

vector<mint> fact, inv;

void init(int n)
{
    fact.push_back(1);
    inv.push_back(1);
    for (int i = 0; i < n; i++)
    {
        fact.push_back(fact.back() * (i + 1));
        inv.push_back(1 / fact.back());
    }
}

mint ncr(int n, int r)
{
    if (r < 0 or n - r < 0)
    {
        return 0;
    }
    return fact[n] * inv[r] * inv[n - r];
}

mint calc(int n, int pc0, int pc)
{
    if (memo.at(n).at(pc0).at(pc) != -1)
    {
        return memo.at(n).at(pc0).at(pc);
    }
    if (n == 0)
    {
        return pc0 == pc;
    }
    mint res = 0;
    for (int i = pc0; i <= pc; i++)
    {
        res += calc(n - 1, i, pc) * ((1 << pc0) * ncr(pc - pc0, i - pc0) - (i == pc0));
    }
    memo.at(n).at(pc0).at(pc) = res.val();
    return res;
}

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    vector<int> b(n + 1);
    for (int i = 0; i < n; i++)
    {
        cin >> b.at(i + 1);
    }

    init(30);
    mint ans = 1;
    int last = 0;
    for (int i = 0; i < n; i++)
    {
        if (b.at(i + 1) != -1)
        {
            if ((b.at(last) & b.at(i + 1)) != b.at(last))
            {
                ans = 0;
                break;
            }
            ans *= calc(i + 1 - last, __builtin_popcount(b.at(last)), __builtin_popcount(b.at(i + 1)));
            last = i + 1;
        }
    }
    cout << ans.val() << endl;
    return 0;
}
0