提出 #74883713


ソースコード 拡げる

#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
ll modmul(ll a, ll b, ll m) { return (ll)((__int128)a*b % m); }
ll modpow(ll b, ll e, ll m) {
    ll ans = 1;
    for (; e; b = modmul(b, b, m), e /= 2)
    if (e & 1) ans = modmul(ans, b, m);
    return ans;
}
const int M = 998244353, MAXN = 200000;
ll fac[MAXN+5], finv[MAXN+5];
void init() {
    fac[0] = 1;
    for (int i = 1; i <= MAXN; i++)
    fac[i] = modmul(fac[i-1], i, M);
    finv[MAXN] = modpow(fac[MAXN], M-2, M);
    for (int i = MAXN-1; i >= 0; i--)
    finv[i] = modmul(finv[i+1], i+1, M);
}
ll nCk(int n, int k) {
    if (n < k || k < 0) return 0;
    ll r = modmul(fac[n], finv[n-k], M);
    return modmul(r, finv[k], M);
}
int main() {
    fastio; int N; cin >> N;
    vector<int> v(N+1), v2(v);
    for (int i = 0; i < N; i++) {
        int a, b; cin >> a >> b;
        v[a]++; v[b+1]--;
        if (max(a, N-b) <= min(b, N-a)) v2[max(a, N-b)]++, v2[min(b, N-a)+1]--;
    }
    for (int i = 1; i <= N; i++) {
        v[i] += v[i-1];
        v2[i] += v2[i-1];
    }
    init();
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        int a = v[i], b = v[N-i], ab = v2[i];
        if (a+b-N != ab) continue;
        ans = (ans + nCk(ab, i-(a-ab))) % M;
    }
    cout << ans << "\n";
    return 0;
}

提出情報

提出日時
問題 E - Team Division
ユーザ Lov34ever
言語 C++23 (GCC 15.2.0)
得点 475
コード長 1559 Byte
結果 AC
実行時間 21 ms
メモリ 8108 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 2
AC × 35
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 5 ms 6584 KiB
example_01.txt AC 5 ms 6680 KiB
hand_00.txt AC 18 ms 7960 KiB
hand_01.txt AC 21 ms 8104 KiB
hand_02.txt AC 21 ms 8040 KiB
hand_03.txt AC 19 ms 7980 KiB
hand_04.txt AC 19 ms 7964 KiB
hand_05.txt AC 20 ms 8108 KiB
hand_06.txt AC 17 ms 8040 KiB
hand_07.txt AC 19 ms 8040 KiB
random_00.txt AC 21 ms 8020 KiB
random_01.txt AC 21 ms 7980 KiB
random_02.txt AC 21 ms 8020 KiB
random_03.txt AC 21 ms 7980 KiB
random_04.txt AC 20 ms 8060 KiB
random_05.txt AC 20 ms 7980 KiB
random_06.txt AC 21 ms 7980 KiB
random_07.txt AC 21 ms 7960 KiB
random_08.txt AC 21 ms 8060 KiB
random_09.txt AC 21 ms 8020 KiB
random_10.txt AC 21 ms 8060 KiB
random_11.txt AC 21 ms 7960 KiB
random_12.txt AC 21 ms 8060 KiB
random_13.txt AC 21 ms 7892 KiB
random_14.txt AC 21 ms 8040 KiB
random_15.txt AC 21 ms 8104 KiB
random_16.txt AC 21 ms 8048 KiB
random_17.txt AC 21 ms 8108 KiB
random_18.txt AC 21 ms 7980 KiB
random_19.txt AC 21 ms 8040 KiB
random_20.txt AC 20 ms 7980 KiB
random_21.txt AC 20 ms 7892 KiB
random_22.txt AC 21 ms 8020 KiB
random_23.txt AC 20 ms 7968 KiB
random_24.txt AC 20 ms 7968 KiB