AtCoder Grand Contest 019

Submission #4032367

Source codeソースコード

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
char s[1<<16];
int a[1<<16],b[1<<16];
int f[1<<16][2];
const int MOD=998244353;
inline int add(int a,int b)
{a+=b;return a>=MOD?a-MOD:a;}
inline int sub(int a,int b)
{a-=b;return a<0?a+MOD:a;}
inline int mul(int a,int b)
{return 1LL*a*b%MOD;}
inline int ksm(int a,int b)
{
    int ans=1;
    for(;b;b>>=1,a=mul(a,a))
        if(b&1)ans=mul(ans,a);
    return ans;
}
int fac[1<<16],ifac[1<<16];
#define C(x,y) mul(fac[x],mul(ifac[x-y],ifac[y]))
int Deal(int n,int m)
{
    f[0][0]=1;
    for(int j=1;j<=m;j++){
        f[0][j&1]=mul(fac[j],fac[j]);
        for(int i=1;i<=n;i++)
            f[i][j&1]=add(mul(f[i-1][j&1],i*j),mul(f[i][j&1^1],j*j));
            //fij=fi-1j*i*j+fij-1*j^2
    }
    int als=0;
    for(int i=0;i<=n;i++)
        als=add(als,mul(f[n-i][m&1],mul(mul(fac[i],fac[i]),mul(C(n,i),C(n+m,i)))));
    return als;
}
int main()
{
    scanf("%s",s+1);
    int s1=0,s2=0,n=strlen(s+1);
    for(int i=1;i<=n;i++)
        a[i]=s[i]-'0';
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
        b[i]=s[i]-'0';
    for(int i=1;i<=n;i++)
        if(a[i]+b[i]==2)++s1;
        else if(a[i])++s2;
    fac[0]=ifac[0]=1;
    for(int i=1;i<=10000;i++)
        fac[i]=mul(fac[i-1],i);
    ifac[n]=ksm(fac[n],MOD-2);
    for(int i=n-1;i;--i)
        ifac[i]=mul(ifac[i+1],i+1);
    printf("%d",Deal(s1,s2));
    return 0;
}

Submission

Task問題 E - Shuffle and Swap
User nameユーザ名 luogu_bot2
Created time投稿日時
Language言語 C++ (GCC 5.4.1)
Status状態 AC
Score得点 1700
Source lengthソースコード長 1441 Byte
File nameファイル名
Exec time実行時間 80 ms
Memory usageメモリ使用量 512 KB

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:42:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s+1);
^
./Main.cpp:46:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s+1);
^

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt
Partial 1200 / 1200 sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt,subtask_1_19.txt,subtask_1_20.txt,subtask_1_21.txt,subtask_1_22.txt,subtask_1_23.txt,subtask_1_24.txt,subtask_1_25.txt,subtask_1_26.txt,subtask_1_27.txt,subtask_1_28.txt,subtask_1_29.txt,subtask_1_30.txt,subtask_1_31.txt,subtask_1_32.txt,subtask_1_33.txt,subtask_1_34.txt,subtask_1_35.txt,subtask_1_36.txt,subtask_1_37.txt,subtask_1_38.txt,subtask_1_39.txt,subtask_1_40.txt,subtask_1_41.txt,subtask_1_42.txt
All 500 / 500 sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt,subtask_1_12.txt,subtask_1_13.txt,subtask_1_14.txt,subtask_1_15.txt,subtask_1_16.txt,subtask_1_17.txt,subtask_1_18.txt,subtask_1_19.txt,subtask_1_20.txt,subtask_1_21.txt,subtask_1_22.txt,subtask_1_23.txt,subtask_1_24.txt,subtask_1_25.txt,subtask_1_26.txt,subtask_1_27.txt,subtask_1_28.txt,subtask_1_29.txt,subtask_1_30.txt,subtask_1_31.txt,subtask_1_32.txt,subtask_1_33.txt,subtask_1_34.txt,subtask_1_35.txt,subtask_1_36.txt,subtask_1_37.txt,subtask_1_38.txt,subtask_1_39.txt,subtask_1_40.txt,subtask_1_41.txt,subtask_1_42.txt,subtask_2_01.txt,subtask_2_02.txt,subtask_2_03.txt,subtask_2_04.txt,subtask_2_05.txt,subtask_2_06.txt,subtask_2_07.txt,subtask_2_08.txt,subtask_2_09.txt,subtask_2_10.txt,subtask_2_11.txt,subtask_2_12.txt,subtask_2_13.txt,subtask_2_14.txt,subtask_2_15.txt,subtask_2_16.txt,subtask_2_17.txt,subtask_2_18.txt,subtask_2_19.txt,subtask_2_20.txt,subtask_2_21.txt,subtask_2_22.txt,subtask_2_23.txt,subtask_2_24.txt,subtask_2_25.txt,subtask_2_26.txt,subtask_2_27.txt,subtask_2_28.txt,subtask_2_29.txt,subtask_2_30.txt,subtask_2_31.txt,subtask_2_32.txt,subtask_2_33.txt,subtask_2_34.txt,subtask_2_35.txt,subtask_2_36.txt,subtask_2_37.txt,subtask_2_38.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sample_04.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 1 ms 256 KB
subtask_1_03.txt AC 1 ms 256 KB
subtask_1_04.txt AC 1 ms 256 KB
subtask_1_05.txt AC 1 ms 256 KB
subtask_1_06.txt AC 1 ms 256 KB
subtask_1_07.txt AC 1 ms 256 KB
subtask_1_08.txt AC 1 ms 256 KB
subtask_1_09.txt AC 1 ms 256 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 1 ms 256 KB
subtask_1_12.txt AC 1 ms 256 KB
subtask_1_13.txt AC 1 ms 256 KB
subtask_1_14.txt AC 1 ms 256 KB
subtask_1_15.txt AC 1 ms 256 KB
subtask_1_16.txt AC 1 ms 256 KB
subtask_1_17.txt AC 1 ms 256 KB
subtask_1_18.txt AC 1 ms 256 KB
subtask_1_19.txt AC 1 ms 256 KB
subtask_1_20.txt AC 1 ms 256 KB
subtask_1_21.txt AC 1 ms 256 KB
subtask_1_22.txt AC 1 ms 256 KB
subtask_1_23.txt AC 1 ms 256 KB
subtask_1_24.txt AC 1 ms 256 KB
subtask_1_25.txt AC 1 ms 256 KB
subtask_1_26.txt AC 1 ms 256 KB
subtask_1_27.txt AC 1 ms 256 KB
subtask_1_28.txt AC 1 ms 256 KB
subtask_1_29.txt AC 1 ms 256 KB
subtask_1_30.txt AC 1 ms 256 KB
subtask_1_31.txt AC 1 ms 256 KB
subtask_1_32.txt AC 1 ms 256 KB
subtask_1_33.txt AC 1 ms 256 KB
subtask_1_34.txt AC 1 ms 256 KB
subtask_1_35.txt AC 1 ms 256 KB
subtask_1_36.txt AC 1 ms 256 KB
subtask_1_37.txt AC 1 ms 256 KB
subtask_1_38.txt AC 1 ms 256 KB
subtask_1_39.txt AC 1 ms 256 KB
subtask_1_40.txt AC 1 ms 256 KB
subtask_1_41.txt AC 1 ms 256 KB
subtask_1_42.txt AC 1 ms 256 KB
subtask_2_01.txt AC 1 ms 384 KB
subtask_2_02.txt AC 1 ms 384 KB
subtask_2_03.txt AC 2 ms 384 KB
subtask_2_04.txt AC 60 ms 384 KB
subtask_2_05.txt AC 54 ms 384 KB
subtask_2_06.txt AC 2 ms 384 KB
subtask_2_07.txt AC 2 ms 512 KB
subtask_2_08.txt AC 2 ms 512 KB
subtask_2_09.txt AC 4 ms 512 KB
subtask_2_10.txt AC 71 ms 512 KB
subtask_2_11.txt AC 71 ms 512 KB
subtask_2_12.txt AC 71 ms 512 KB
subtask_2_13.txt AC 80 ms 512 KB
subtask_2_14.txt AC 80 ms 512 KB
subtask_2_15.txt AC 80 ms 512 KB
subtask_2_16.txt AC 71 ms 384 KB
subtask_2_17.txt AC 71 ms 384 KB
subtask_2_18.txt AC 71 ms 384 KB
subtask_2_19.txt AC 2 ms 384 KB
subtask_2_20.txt AC 1 ms 384 KB
subtask_2_21.txt AC 1 ms 384 KB
subtask_2_22.txt AC 30 ms 512 KB
subtask_2_23.txt AC 30 ms 512 KB
subtask_2_24.txt AC 30 ms 512 KB
subtask_2_25.txt AC 30 ms 512 KB
subtask_2_26.txt AC 42 ms 512 KB
subtask_2_27.txt AC 42 ms 512 KB
subtask_2_28.txt AC 3 ms 384 KB
subtask_2_29.txt AC 9 ms 384 KB
subtask_2_30.txt AC 35 ms 384 KB
subtask_2_31.txt AC 77 ms 512 KB
subtask_2_32.txt AC 78 ms 512 KB
subtask_2_33.txt AC 77 ms 384 KB
subtask_2_34.txt AC 77 ms 512 KB
subtask_2_35.txt AC 48 ms 512 KB
subtask_2_36.txt AC 48 ms 512 KB
subtask_2_37.txt AC 48 ms 512 KB
subtask_2_38.txt AC 48 ms 512 KB