結果

問題 No.1426 Got a Covered OR
ユーザー 👑 箱星箱星
提出日時 2020-12-11 23:10:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 2,911 bytes
コンパイル時間 5,621 ms
コンパイル使用メモリ 217,052 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 01:47:08
合計ジャッジ時間 6,838 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 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 7 ms
4,348 KB
testcase_13 AC 9 ms
4,348 KB
testcase_14 AC 7 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 5 ms
4,348 KB
testcase_18 AC 27 ms
4,348 KB
testcase_19 AC 28 ms
4,348 KB
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 16 ms
4,348 KB
testcase_22 AC 13 ms
4,348 KB
testcase_23 AC 50 ms
4,348 KB
testcase_24 AC 18 ms
4,348 KB
testcase_25 AC 38 ms
4,348 KB
testcase_26 AC 38 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cassert>
#include "testlib.h"
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> bool chmax(T& m, const T q) { if (m < q) { m = q; return true; } else return false; }
template<typename T> bool chmin(T& m, const T q) { if (q < m) { m = q; return true; } else return false; }

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(int argc, char* argv[]) {
    registerValidation(argc, argv);
    int i;
    pow2[0] = 1;
    for (i = 0; i < 34; i++) {
        pow2[i + 1] = pow2[i] * 2;
    }
    int n = inf.readInt(1, 100000, "n");
    inf.readEoln();
    vector<ll> b(n, 0);
    for (i = 0; i < n; i++) {
        b[i] = inf.readInt(-1, (1 << 30) - 1, "b_i");
        assert(b[i] != 0);
        if (i != n - 1) {
            inf.readSpace();
        }
    }
    inf.readEoln();
    inf.readEof();
    assert(b[n - 1] != -1);
    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