QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#390266#4472. 珍珠bachbeo2007100 ✓59ms15268kbC++234.0kb2024-04-15 11:04:022024-04-15 11:04:03

Judging History

你现在查看的是最新测评结果

  • [2024-04-15 11:04:03]
  • 评测
  • 测评结果:100
  • 用时:59ms
  • 内存:15268kb
  • [2024-04-15 11:04:02]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=200005;
const int B=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=25;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
const int iroot=power(3,mod-2);
const int base=101;

void fft(vector<int> &a,bool invert){
    int n=(int)a.size();
    for(int i=1,j=0;i<n;i++){
        int bit=n>>1;
        while(j&bit){j^=bit;bit>>=1;}
        j^=bit;
        if(i<j) swap(a[i],a[j]);
    }
    for(int len=2;len<=n;len<<=1){
        int wn=power((invert?iroot:root),(mod-1)/len);
        for(int i=0;i<n;i+=len){
            int w=1;
            for(int j=0;j<len/2;j++){
                int u=a[i+j],v=a[i+j+len/2]*w%mod;
                a[i+j]=(u+v)%mod;
                a[i+j+len/2]=(u-v+mod)%mod;
                w=w*wn%mod;
            }
        }
    }
    if(invert){
        int dd=power(n,mod-2);
        for(int i=0;i<n;i++) a[i]=a[i]*dd%mod;
    }
    return;
}

vector<int> mul(vector<int> a,vector<int> b){
    int n=(int)a.size()+(int)b.size(),sz=1;
    while(sz<n) sz<<=1;
    a.resize(sz);b.resize(sz);
    fft(a,false);fft(b,false);
    for(int i=0;i<sz;i++) a[i]=a[i]*b[i]%mod;
    fft(a,true);
    return a;
}

int fac[maxn],dfac[maxn],inv[maxn];
int C(int n,int k){
    if(k>n || k<0 || n<0) return 0;
    return fac[n]*dfac[k]%mod*dfac[n-k]%mod;
}
void combi(int n){
    fac[0]=inv[0]=1;
    for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
    dfac[n]=power(fac[n],mod-2);
    for(int i=n;i>=1;i--){
        dfac[i-1]=dfac[i]*i%mod;
        inv[i]=dfac[i]*fac[i-1]%mod;
    }
}

int F0[maxn];

void solve(){
    int D,N,M;cin >> D >> N >> M;
    if(N-2*M<0){
        cout << 0 << '\n';
        return;
    }
    else if(N-2*M>=D){
        cout << power(D,N) << '\n';
        return;
    }
    combi(D);
    F0[0]=1;
    for(int i=1;i<=D;i++) F0[i]=((N&1)?-1:1)*C(i-1,N-2*M);

    vector<int> a(D+1,0),b(D+1,0);
    for(int i=0;i<=D;i++){
        a[i]=(power(2*i-D,N)*dfac[D-i]%mod+mod)%mod;
        b[i]=power(2,D-i)*F0[i]%mod*dfac[D-i]%mod;
    }
    a=mul(a,b);
    int res=0;
    for(int i=D;i<=2*D;i++){
        int val=a[i]*(((i-D)&1)?-1:1)*dfac[i-D]%mod;
        res=(res+val+mod)%mod;
    }
    /*
    for(int i=0;i<=D;i++) for(int j=D-i;j<=D;j++){
        int val=power(2*i-D,N)*power(2,D-j)%mod*(((i+j-D)&1)?-1:1)*F0[j]%mod;
        val=val*dfac[D-i]%mod*dfac[D-j]%mod*dfac[i+j-D]%mod;
        res=(res+val+mod)%mod;
    }
    */
    res=res*fac[D]%mod*power((mod+1)/2,D)%mod;
    cout << res << '\n';
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

詳細信息

Test #1:

score: 4
Accepted
time: 1ms
memory: 7984kb

input:

2 7 3

output:

128

result:

ok 1 number(s): "128"

Test #2:

score: 4
Accepted
time: 0ms
memory: 3884kb

input:

2 20 9

output:

1048576

result:

ok 1 number(s): "1048576"

Test #3:

score: 4
Accepted
time: 1ms
memory: 7760kb

input:

99 97 30

output:

893559494

result:

ok 1 number(s): "893559494"

Test #4:

score: 4
Accepted
time: 1ms
memory: 7792kb

input:

100 97 29

output:

870441375

result:

ok 1 number(s): "870441375"

Test #5:

score: 4
Accepted
time: 1ms
memory: 7832kb

input:

97 100 16

output:

114531619

result:

ok 1 number(s): "114531619"

Test #6:

score: 4
Accepted
time: 1ms
memory: 7728kb

input:

98 98 38

output:

910698957

result:

ok 1 number(s): "910698957"

Test #7:

score: 4
Accepted
time: 1ms
memory: 7924kb

input:

100 99 30

output:

267167918

result:

ok 1 number(s): "267167918"

Test #8:

score: 4
Accepted
time: 2ms
memory: 8008kb

input:

4000 3998 602

output:

267823033

result:

ok 1 number(s): "267823033"

Test #9:

score: 4
Accepted
time: 2ms
memory: 7884kb

input:

3999 3998 478

output:

7661427

result:

ok 1 number(s): "7661427"

Test #10:

score: 4
Accepted
time: 2ms
memory: 7904kb

input:

4000 3999 18

output:

46680613

result:

ok 1 number(s): "46680613"

Test #11:

score: 4
Accepted
time: 0ms
memory: 7904kb

input:

4000 3998 683

output:

689956672

result:

ok 1 number(s): "689956672"

Test #12:

score: 4
Accepted
time: 2ms
memory: 7948kb

input:

3998 3998 1743

output:

625630497

result:

ok 1 number(s): "625630497"

Test #13:

score: 4
Accepted
time: 1ms
memory: 7748kb

input:

300 999999997 499999880

output:

311178114

result:

ok 1 number(s): "311178114"

Test #14:

score: 4
Accepted
time: 1ms
memory: 8008kb

input:

297 999999999 499999955

output:

111728734

result:

ok 1 number(s): "111728734"

Test #15:

score: 4
Accepted
time: 1ms
memory: 8020kb

input:

298 999999998 499999978

output:

873407954

result:

ok 1 number(s): "873407954"

Test #16:

score: 4
Accepted
time: 0ms
memory: 3652kb

input:

100000 999999998 0

output:

403169128

result:

ok 1 number(s): "403169128"

Test #17:

score: 4
Accepted
time: 54ms
memory: 14776kb

input:

99999 100000 1

output:

520922757

result:

ok 1 number(s): "520922757"

Test #18:

score: 4
Accepted
time: 50ms
memory: 14844kb

input:

99998 99998 2

output:

776350879

result:

ok 1 number(s): "776350879"

Test #19:

score: 4
Accepted
time: 55ms
memory: 14608kb

input:

99998 999999998 499972261

output:

805937760

result:

ok 1 number(s): "805937760"

Test #20:

score: 4
Accepted
time: 52ms
memory: 14640kb

input:

99997 999999999 499975678

output:

265933807

result:

ok 1 number(s): "265933807"

Test #21:

score: 4
Accepted
time: 59ms
memory: 15040kb

input:

100000 1000000000 499958129

output:

59384653

result:

ok 1 number(s): "59384653"

Test #22:

score: 4
Accepted
time: 52ms
memory: 14816kb

input:

99998 999999999 499978565

output:

897679746

result:

ok 1 number(s): "897679746"

Test #23:

score: 4
Accepted
time: 53ms
memory: 15012kb

input:

100000 999999999 499970692

output:

169325977

result:

ok 1 number(s): "169325977"

Test #24:

score: 4
Accepted
time: 51ms
memory: 14632kb

input:

99997 1000000000 499976402

output:

562099965

result:

ok 1 number(s): "562099965"

Test #25:

score: 4
Accepted
time: 59ms
memory: 15268kb

input:

99997 1000000000 499978285

output:

681053406

result:

ok 1 number(s): "681053406"

Extra Test:

score: 0
Extra Test Passed