結果

問題 No.1426 Got a Covered OR
ユーザー merom686merom686
提出日時 2021-03-13 02:01:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,228 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 99,672 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 16:04:59
合計ジャッジ時間 1,950 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
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 AC 10 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}
ll modinv(ll n) {
    return powmod(n, P - 2);
}

vector<int> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = (ll)f0[i - 1] * i % P;
    }
    f1.resize(n + 1);
    f1[n] = modinv(f0[n]);
    for (int i = n; i > 0; i--) {
        f1[i - 1] = (ll)f1[i] * i % P;
    }
}
ll fact(int k) {
    return f0[k];
}
ll comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return (ll)f0[n] * f1[k] % P * f1[n - k] % P;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    int t = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] < 0) continue;
        if (t & ~b[i]) {
            cout << 0 << endl;
            exit(0);
        }
        t = b[i];
    }

    //int p[30][2];
    //for (int j = 0; j < 30; j++) {
    //    p[j][0] = 0;
    //    p[j][1] = n;
    //}
    //for (int i = 0; i < n; i++) {
    //    if (b[i] < 0) continue;
    //    for (int j = 0; j < 30; j++) {
    //        int t = b[i] >> j & 1;
    //        if (t == 0) p[j][0] = i + 1;
    //        else if (p[j][1] == n) p[j][1] = i;
    //    }
    //}

    init(30);

    int x[30];
    x[0] = 1;
    for (int j = 1; j < 30; j++) {
        x[j] = x[j - 1] * 2 % P;
    }

    ll r = 1;
    int i0 = -1, b0 = 0;
    for (int i = 0; i < n; i++) {
        if (b[i] < 0) continue;

        int k = __builtin_popcount(~b0 & b[i]);
        int l = __builtin_popcount(b0 & b[i]) + k;

        ll t = 0, sgn = 1;
        for (int j = 0; j <= k; j++) {
            t += powmod((ll)x[l - j] - 1, i - i0) * comb(k, j) * sgn % P;
            sgn *= -1;
        }
        t %= P;
        r = r * t % P;

        i0 = i;
        b0 = b[i];
    }

    if (r < 0) r += P;
    cout << r << endl;

    return 0;
}
0