Submission #61235769


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;

int fac[20000005], ifac[20000005], inv[20000005];
int power(int x, int t) {
    int ret = 1;
    while(t > 0) {
        if(t & 1) ret = 1LL * ret * x % MOD;
        x = 1LL * x * x % MOD;
        t >>= 1;
    }
    return ret;
}
void init(int n) {
    fac[0] = 1;
    for(int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % MOD;
    ifac[n] = power(fac[n], MOD - 2);
    for(int i = n; i >= 1; i--) ifac[i - 1] = 1LL * ifac[i] * i % MOD;
    for(int i = 1; i <= n; i++) inv[i] = 1LL * ifac[i] * fac[i - 1] % MOD;
}
int comb(int a, int b) {
    if(a < b) return 0;
    return 1LL * fac[a] * ifac[b] % MOD * ifac[a - b] % MOD;
}
int F[10000005], G[10000005], H[10000005];
void calc(int a, int b) {
    memset(F, 0, sizeof(F));
    if(b < 0) return;
    F[b] = comb(a, b);
    for(int i = b - 1; i >= 0; i--)
        F[i] = 1LL * F[i + 1] * (i + 1) % MOD * (i + 1) % MOD * inv[a - i] % MOD * inv[b - i] % MOD;
}
void calc1(int a, int b, int ret[]) {
    if(a < b) return;
    calc(a, b);
    for(int i = 0; i <= b; i++) ret[i] = F[i];
    calc(a + 1, b - 1);
    for(int i = 0; i <= b; i++) ret[i] = (ret[i] - F[i] + MOD) % MOD;
}
int coef[20000005];

int main() {
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);
    init(n);
    
    calc1(a, b, G);
    calc1(a - 1, b, H);
    for(int i = 0; i <= b; i++) {
        if(G[i] != H[i]) coef[2 * i - 1] = (G[i] - H[i] + MOD) % MOD;
        if(H[i] != 0) coef[2 * i] = H[i];
    }
    
    int ans = 0;
    for(int i = 0; i <= b * 2; i++)
        ans = (ans + 1LL * coef[i] * comb(n - a - b + i + 1, a + b)) % MOD;
    printf("%d\n", ans);
    return 0;
}

Submission Info

Submission Time
Task C - No Streak
User tour1st
Language C++ 20 (gcc 12.2)
Score 1000
Code Size 1735 Byte
Status AC
Exec Time 1058 ms
Memory 417400 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   45 |     scanf("%d%d%d", &n, &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 3
AC × 43
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 01_n_small_05.txt, 01_n_small_06.txt, 01_n_small_07.txt, 01_n_small_08.txt, 01_n_small_09.txt, 01_n_small_10.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 03_no_draw_00.txt, 03_no_draw_01.txt, 03_no_draw_02.txt, 04_b_eq_1_00.txt, 04_b_eq_1_01.txt, 04_b_eq_1_02.txt, 05_fft_killer_00.txt, 05_fft_killer_01.txt, 05_fft_killer_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 18 ms 42956 KiB
00_sample_01.txt AC 24 ms 42964 KiB
00_sample_02.txt AC 377 ms 291176 KiB
01_n_small_00.txt AC 19 ms 42704 KiB
01_n_small_01.txt AC 23 ms 42736 KiB
01_n_small_02.txt AC 22 ms 42760 KiB
01_n_small_03.txt AC 23 ms 42852 KiB
01_n_small_04.txt AC 23 ms 42900 KiB
01_n_small_05.txt AC 24 ms 42716 KiB
01_n_small_06.txt AC 23 ms 42712 KiB
01_n_small_07.txt AC 24 ms 42660 KiB
01_n_small_08.txt AC 24 ms 42960 KiB
01_n_small_09.txt AC 19 ms 42844 KiB
01_n_small_10.txt AC 19 ms 42956 KiB
02_random_00.txt AC 545 ms 278372 KiB
02_random_01.txt AC 476 ms 308940 KiB
02_random_02.txt AC 176 ms 123356 KiB
02_random_03.txt AC 620 ms 335364 KiB
02_random_04.txt AC 705 ms 328352 KiB
02_random_05.txt AC 584 ms 329340 KiB
02_random_06.txt AC 35 ms 49328 KiB
02_random_07.txt AC 484 ms 310540 KiB
02_random_08.txt AC 98 ms 104112 KiB
02_random_09.txt AC 423 ms 299316 KiB
02_random_10.txt AC 36 ms 49308 KiB
02_random_11.txt AC 484 ms 310480 KiB
02_random_12.txt AC 504 ms 290128 KiB
02_random_13.txt AC 452 ms 304684 KiB
02_random_14.txt AC 278 ms 178592 KiB
02_random_15.txt AC 737 ms 357684 KiB
02_random_16.txt AC 227 ms 150352 KiB
02_random_17.txt AC 343 ms 285000 KiB
02_random_18.txt AC 120 ms 114104 KiB
02_random_19.txt AC 327 ms 282132 KiB
03_no_draw_00.txt AC 361 ms 195640 KiB
03_no_draw_01.txt AC 1058 ms 417400 KiB
03_no_draw_02.txt AC 776 ms 394212 KiB
04_b_eq_1_00.txt AC 142 ms 142892 KiB
04_b_eq_1_01.txt AC 299 ms 277132 KiB
04_b_eq_1_02.txt AC 218 ms 207624 KiB
05_fft_killer_00.txt AC 1029 ms 411576 KiB
05_fft_killer_01.txt AC 1014 ms 409056 KiB
05_fft_killer_02.txt AC 929 ms 393348 KiB