結果

問題 No.1426 Got a Covered OR
ユーザー 👑 箱星箱星
提出日時 2020-12-19 18:30:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 2,233 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 74,448 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 09:25:50
合計ジャッジ時間 2,881 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 5 ms
4,348 KB
testcase_13 AC 5 ms
4,348 KB
testcase_14 AC 5 ms
4,348 KB
testcase_15 AC 5 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 19 ms
4,348 KB
testcase_19 AC 20 ms
4,348 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 12 ms
4,348 KB
testcase_22 AC 7 ms
4,348 KB
testcase_23 AC 37 ms
4,348 KB
testcase_24 AC 10 ms
4,348 KB
testcase_25 AC 26 ms
4,348 KB
testcase_26 AC 27 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); i++)

const ll MOD = 1000000007;
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll modinv(ll i, ll mod) {
    return modpow(i, mod - 2, mod);
}

ll fact(ll n, ll mod) {
    ll ans = 1;
    rep(i, n) {
        ans = ans * (i + 1) % mod;
    }
    return ans;
}

ll comb(ll n, ll a, ll mod) {
    ll ans = 1, denom = 1;
    rep(i, a) {
        ans = ans * (n - i) % mod;
        denom = denom * (i + 1) % mod;
    }
    ans = ans * modinv(denom, mod) % mod;
    return ans;
}

ll pow2[35];

ll calc(ll a, ll b, ll c) {
    ll ret = 0;
    for (int i = 0; i <= b; i++) {
        ll v = comb(b, i, MOD) * modpow(pow2[b + c - i] - 1, a, MOD) % MOD;
        if (i % 2 == 0) {
            ret += v;
            ret %= MOD;
        }
        else {
            ret += MOD - v;
            ret %= MOD;
        }
    }
    return ret;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i;
    pow2[0] = 1;
    for (i = 0; i < 34; i++) {
        pow2[i + 1] = pow2[i] * 2;
    }
    int n;
    cin >> n;
    vector<ll> b(n, 0);
    for (i = 0; i < n; i++) {
        cin >> b[i];
    }
    ll prev = 0;
    ll streak = 0;
    ll ans = 1;
    for (i = 0; i < n; i++) {
        if (b[i] == -1)
        {
            streak++;
        }
        else {
            ll c01 = 0;
            ll c11 = 0;
            for (int j = 0; j < 32; j++) {
                ll x = (prev >> j) % 2;
                ll y = (b[i] >> j) % 2;
                if (x == 0 && y == 1)
                {
                    c01++;
                }
                else if (x == 1 && y == 1)
                {
                    c11++;
                }
                else if (x == 1 && y == 0)
                {
                    cout << 0 << "\n";
                    return 0;
                }
            }
            ans *= calc(streak + 1, c01, c11);
            ans %= MOD;
            prev = b[i];
            streak = 0;
        }
    }
    cout << ans << "\n";
    return 0;
}
0