結果

問題 No.2133 Take it easy!
ユーザー ぷらぷら
提出日時 2022-11-25 23:52:03
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,631 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 204,920 KB
実行使用メモリ 9,160 KB
最終ジャッジ日時 2024-04-10 04:50:43
合計ジャッジ時間 3,256 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long fac[200005], finv[200005], inv[200005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 200005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

long long choose(int n,int k) {
    if(n < 0 || k < 0) return 0;
    if(n == 0) return 1;
    return COM(n+k-1,k-1);
}

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

int c[200200];

int main() {
    COMinit();
    int N,Q;
    cin >> N >> Q;
    vector<int>L(Q),R(Q);
    for(int i = 0; i < Q; i++) {
        cin >> L[i] >> R[i];
        if((R[i]-L[i]+1)%2 == 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    c[0] = 1;
    for(int i = 2; i <= N+1; i += 2) {
        c[i] = (COM(i,i/2)+mod-COM(i,i/2-1))%mod;
    }
    vector<int>cmp;
    for(int i = 0; i < Q; i++) {
        cmp.push_back(L[i]);
        cmp.push_back(R[i]+1);
        for(int j = i+1; j < Q; j++) {
            if(L[i]%2 != L[j]%2) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    sort(cmp.begin(),cmp.end());
    cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
    if(cmp.empty()) {
        if(N%2 == 0) {
            cout << c[N]*fac[N/2]%mod*fac[N/2]%mod << endl;
        }
        else {
            cout << c[N+2]*fac[N/2+1]%mod*fac[N/2]%mod << endl;
        }
        return 0;
    }
    vector<int>sum(cmp.size()+1);
    for(int i = 0; i < Q; i++) {
        int it1 = lower_bound(cmp.begin(),cmp.end(),L[i])-cmp.begin();
        int it2 = lower_bound(cmp.begin(),cmp.end(),R[i]+1)-cmp.begin();
        sum[it1]++;
        sum[it2]--;
    }
    int ans = 1,cnt = 0;
    for(int i = 0; i+1 < cmp.size(); i++) {
        sum[i+1] += sum[i];
        if(sum[i] == 0) {
            cout << "OK" << endl;
            continue;
        }
        cnt += cmp[i+1]-cmp[i];
        ans = 1ll*ans*c[cmp[i+1]-cmp[i]]%mod;
    }
    if(N%2 == 0) {
        ans = 1ll*ans*c[N-cnt]%mod*fac[N/2]%mod*fac[N/2]%mod;
    }
    else {
        ans = 1ll*ans*c[N-cnt+1]%mod*fac[N/2+1]%mod*fac[N/2]%mod;
    }
    cout << ans << endl;
}
0