Submission #61639513


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
const int N=1e7+10;
const int M=2e5+10;
const int Mod=998244353;
typedef long long ll;

int qpow(int x,ll y) {
    int z=1;
    for(;y;y>>=1) {
        if(y&1) z=1ll*z*x%Mod;
        x=1ll*x*x%Mod;
    }
    return z;
}

int n,q,x,y;
int fac[N],inv[N],p4[N];
int fx[N],fy[N];

int C(int x,int y) {
    if(x<y || y<0) return 0;
    return 1ll*fac[x]*inv[y]%Mod*inv[x-y]%Mod;
}

void init() {
    fac[0]=1;
    for(int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%Mod;
    inv[n]=qpow(fac[n],Mod-2);
    for(int i=n-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
    p4[0]=1;
    for(int i=1;i<=n;i++) p4[i]=4ll*p4[i-1]%Mod;
    fx[n]=fy[n]=1;
    for(int i=n-1;i>1;i--) {
        fx[i]=((ll)fx[i+1]*2%Mod+Mod-C(n-(i+1),x-(i+1))+Mod-C(n-(i+1),x-1))%Mod;
        fy[i]=((ll)fy[i+1]*2%Mod+Mod-C(n-(i+1),y-(i+1))+Mod-C(n-(i+1),y-1))%Mod;
    }
    fx[1]=C(n-1,x-1),fy[1]=C(n-1,y-1);
}

int calc(int x,int y,int k,int xx,int yy) {
    return 1ll*C(n-k,x-xx)*C(n-k,y-yy)%Mod;
}

int main() {
    scanf("%d%d%d%d",&n,&x,&y,&q);
    init();
    while(q--) {
        int k;
        scanf("%d",&k);
        int ans=((1ll*(C(n-k,x-1)+C(n-k,x-k))*fy[k]%Mod+1ll*(C(n-k,y-1)+C(n-k,y-k))*fx[k]%Mod)*2ll%Mod+Mod-calc(x,y,k,1,1)+Mod-calc(x,y,k,1,k)+Mod-calc(x,y,k,k,1)+Mod-calc(x,y,k,k,k))%Mod;
        ans=1ll*p4[k-1]*ans%Mod;
        ans=1ll*ans*qpow(4,Mod-2)%Mod;
        if(k==1) ans=1ll*fx[k]*fy[k]%Mod;
        printf("%d\n",ans);
    }
    return 0;
}

Submission Info

Submission Time
Task B - L Partition
User fansizhe
Language C++ 20 (gcc 12.2)
Score 800
Code Size 1532 Byte
Status AC
Exec Time 365 ms
Memory 199188 KiB

Compile Error

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

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 44
Set Name Test Cases
Sample 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 02_small_11.txt, 02_small_12.txt, 02_small_13.txt, 02_small_14.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 05_rand_3_01.txt, 05_rand_3_02.txt, 05_rand_3_03.txt, 05_rand_3_04.txt, 05_rand_3_05.txt, 06_XY_special_01.txt, 06_XY_special_02.txt, 06_XY_special_03.txt, 06_XY_special_04.txt, 06_XY_special_05.txt, 06_XY_special_06.txt, 06_XY_special_07.txt, 06_XY_special_08.txt, 06_XY_special_09.txt, 06_XY_special_10.txt, 06_XY_special_11.txt, 06_XY_special_12.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 1 ms 3640 KiB
01_sample_02.txt AC 1 ms 3632 KiB
01_sample_03.txt AC 1 ms 3700 KiB
02_small_01.txt AC 1 ms 3696 KiB
02_small_02.txt AC 1 ms 3784 KiB
02_small_03.txt AC 1 ms 3900 KiB
02_small_04.txt AC 1 ms 3640 KiB
02_small_05.txt AC 1 ms 3668 KiB
02_small_06.txt AC 1 ms 3656 KiB
02_small_07.txt AC 1 ms 3668 KiB
02_small_08.txt AC 1 ms 3648 KiB
02_small_09.txt AC 1 ms 3892 KiB
02_small_10.txt AC 1 ms 3616 KiB
02_small_11.txt AC 1 ms 3776 KiB
02_small_12.txt AC 1 ms 3704 KiB
02_small_13.txt AC 1 ms 3772 KiB
02_small_14.txt AC 1 ms 3708 KiB
03_rand_1_01.txt AC 60 ms 7668 KiB
03_rand_1_02.txt AC 60 ms 7808 KiB
03_rand_1_03.txt AC 59 ms 7584 KiB
03_rand_1_04.txt AC 60 ms 7532 KiB
03_rand_1_05.txt AC 60 ms 7660 KiB
04_rand_2_01.txt AC 196 ms 93828 KiB
04_rand_2_02.txt AC 252 ms 129008 KiB
04_rand_2_03.txt AC 263 ms 136884 KiB
04_rand_2_04.txt AC 105 ms 35908 KiB
04_rand_2_05.txt AC 281 ms 147816 KiB
05_rand_3_01.txt AC 358 ms 197716 KiB
05_rand_3_02.txt AC 361 ms 198488 KiB
05_rand_3_03.txt AC 361 ms 198420 KiB
05_rand_3_04.txt AC 361 ms 198832 KiB
05_rand_3_05.txt AC 359 ms 197832 KiB
06_XY_special_01.txt AC 359 ms 198948 KiB
06_XY_special_02.txt AC 360 ms 198968 KiB
06_XY_special_03.txt AC 360 ms 198984 KiB
06_XY_special_04.txt AC 359 ms 199188 KiB
06_XY_special_05.txt AC 364 ms 198940 KiB
06_XY_special_06.txt AC 359 ms 198948 KiB
06_XY_special_07.txt AC 359 ms 199128 KiB
06_XY_special_08.txt AC 360 ms 199000 KiB
06_XY_special_09.txt AC 358 ms 199064 KiB
06_XY_special_10.txt AC 360 ms 198952 KiB
06_XY_special_11.txt AC 365 ms 198952 KiB
06_XY_special_12.txt AC 358 ms 198940 KiB