QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#882566 | #1816. Multiple Parentheses | Invincible | AC ✓ | 353ms | 203404kb | C++14 | 2.4kb | 2025-02-05 09:25:48 | 2025-02-05 09:25:49 |
Judging History
answer
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <ctime>
#include <random>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#define pii pair<int, int>
#define fi first
#define se second
#define MP make_pair
#define ep emplace
#define eb emplace_back
//#define int long long
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
typedef double db;
typedef long double ldb;
typedef long long ll;
//typedef __int128 lll;
typedef unsigned long long ull;
typedef unsigned int ui;
using namespace std;
using namespace __gnu_pbds;
bool Mbe;
//char buf[1<<20],*p1,*p2;
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf,1,1<<20,stdin), p1 == p2) ? 0 : *p1++)
int read() {
int s = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') f ^= (c == '-'), c = getchar();
while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
return f ? s : -s;
}
template<typename T>void chkmax(T&x,const T&y){if(x<y)x=y;}
template<typename T>void chkmin(T&x,const T&y){if(x>y)x=y;}
const int N=30000005;
int n,m,k,mod=998244353,fac[N],ifac[N],ans,cat[N];
int fplus(int x,int y){return x+y>=mod?x+y-mod:x+y;}
void Fplus(int&x,int y){x=fplus(x,y);}
int fminus(int x,int y){return x-y<0?x+mod-y:x-y;}
void Fminus(int&x,int y){x=fminus(x,y);}
int fpow(int x,int k=mod-2){
int res=1;
for(;k;k>>=1){
if(k&1)res=(ll)res*x%mod;
x=(ll)x*x%mod;
}
return res;
}
int C(int x,int y){return x<y?0:(ll)fac[x]*ifac[y]%mod*ifac[x-y]%mod;}
int F(int x,int y){
if(!y)return 1;
return fminus(C(y+y+x-1,y),C(y+y+x-1,x+y));
}
bool Med;
signed main() {
// freopen("1.in","r",stdin);
// freopen("bracket.in","r",stdin);
// freopen("bracket.out","w",stdout);
fprintf(stderr,"%.3lfMb\n",(&Mbe-&Med)/1024./1024.);
n=read(),m=read(),k=read();
fac[0]=1;
rep(i,1,30000000)fac[i]=(ll)fac[i-1]*i%mod;
ifac[20000000]=fpow(fac[20000000]);
per(i,20000000,1)ifac[i-1]=(ll)ifac[i]*i%mod;
int base=1,pw=(ll)C(k+k,k)*fpow(k+1)%mod;
rep(i,0,min(m/k,n)){
if(i&1)Fminus(ans,(ll)F(n-i,m-i*k)*C(n,i)%mod*base%mod);
else Fplus(ans,(ll)F(n-i,m-i*k)*C(n,i)%mod*base%mod);
base=(ll)base*pw%mod;
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 328ms
memory: 201484kb
input:
2 2 1
output:
4
result:
ok answer is '4'
Test #2:
score: 0
Accepted
time: 331ms
memory: 201072kb
input:
1 1 1
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 325ms
memory: 202352kb
input:
24 120 30
output:
379268651
result:
ok answer is '379268651'
Test #4:
score: 0
Accepted
time: 331ms
memory: 202052kb
input:
1451 1598 1130
output:
884873572
result:
ok answer is '884873572'
Test #5:
score: 0
Accepted
time: 327ms
memory: 202552kb
input:
1324 1742 1033
output:
856733047
result:
ok answer is '856733047'
Test #6:
score: 0
Accepted
time: 329ms
memory: 202348kb
input:
1378 1614 1335
output:
869903701
result:
ok answer is '869903701'
Test #7:
score: 0
Accepted
time: 332ms
memory: 201124kb
input:
1071 1907 1281
output:
327700529
result:
ok answer is '327700529'
Test #8:
score: 0
Accepted
time: 334ms
memory: 202756kb
input:
1204 1337 1277
output:
475981175
result:
ok answer is '475981175'
Test #9:
score: 0
Accepted
time: 331ms
memory: 203404kb
input:
146 246 100
output:
404402509
result:
ok answer is '404402509'
Test #10:
score: 0
Accepted
time: 331ms
memory: 203328kb
input:
226 183 144
output:
351921989
result:
ok answer is '351921989'
Test #11:
score: 0
Accepted
time: 331ms
memory: 201476kb
input:
234 287 158
output:
658959115
result:
ok answer is '658959115'
Test #12:
score: 0
Accepted
time: 330ms
memory: 201032kb
input:
242 156 122
output:
325586111
result:
ok answer is '325586111'
Test #13:
score: 0
Accepted
time: 330ms
memory: 202340kb
input:
168 271 135
output:
181613866
result:
ok answer is '181613866'
Test #14:
score: 0
Accepted
time: 330ms
memory: 201592kb
input:
22 25 1
output:
684860973
result:
ok answer is '684860973'
Test #15:
score: 0
Accepted
time: 331ms
memory: 202284kb
input:
45 22 15
output:
217501624
result:
ok answer is '217501624'
Test #16:
score: 0
Accepted
time: 330ms
memory: 203184kb
input:
47 29 16
output:
690840771
result:
ok answer is '690840771'
Test #17:
score: 0
Accepted
time: 330ms
memory: 203016kb
input:
2 25 25
output:
660660974
result:
ok answer is '660660974'
Test #18:
score: 0
Accepted
time: 329ms
memory: 202856kb
input:
32 34 11
output:
133387056
result:
ok answer is '133387056'
Test #19:
score: 0
Accepted
time: 330ms
memory: 202340kb
input:
88196 118335 104471
output:
7192211
result:
ok answer is '7192211'
Test #20:
score: 0
Accepted
time: 330ms
memory: 203252kb
input:
142215 57117 51272
output:
627598793
result:
ok answer is '627598793'
Test #21:
score: 0
Accepted
time: 331ms
memory: 201916kb
input:
102255 60360 51525
output:
447649003
result:
ok answer is '447649003'
Test #22:
score: 0
Accepted
time: 330ms
memory: 203208kb
input:
132449 83413 54230
output:
215816803
result:
ok answer is '215816803'
Test #23:
score: 0
Accepted
time: 333ms
memory: 202704kb
input:
68499 95762 77190
output:
393029560
result:
ok answer is '393029560'
Test #24:
score: 0
Accepted
time: 353ms
memory: 201720kb
input:
751951 751951 1
output:
804170883
result:
ok answer is '804170883'
Test #25:
score: 0
Accepted
time: 332ms
memory: 200980kb
input:
804420 1962 410
output:
869056555
result:
ok answer is '869056555'
Test #26:
score: 0
Accepted
time: 328ms
memory: 202720kb
input:
828607 63739 13
output:
926542030
result:
ok answer is '926542030'
Test #27:
score: 0
Accepted
time: 329ms
memory: 201052kb
input:
472167 20529 23
output:
142703540
result:
ok answer is '142703540'
Test #28:
score: 0
Accepted
time: 341ms
memory: 203224kb
input:
363438 363438 1
output:
764563597
result:
ok answer is '764563597'
Test #29:
score: 0
Accepted
time: 332ms
memory: 203380kb
input:
1000000 1000000 628333
output:
283487375
result:
ok answer is '283487375'
Test #30:
score: 0
Accepted
time: 329ms
memory: 202804kb
input:
1000000 1000000 900084
output:
651386967
result:
ok answer is '651386967'
Test #31:
score: 0
Accepted
time: 329ms
memory: 202520kb
input:
1000000 1000000 27328
output:
621963453
result:
ok answer is '621963453'
Test #32:
score: 0
Accepted
time: 330ms
memory: 202792kb
input:
1000000 1000000 538409
output:
997879100
result:
ok answer is '997879100'
Test #33:
score: 0
Accepted
time: 330ms
memory: 202564kb
input:
1000000 1000000 928121
output:
964724707
result:
ok answer is '964724707'
Test #34:
score: 0
Accepted
time: 334ms
memory: 203188kb
input:
685624 665877 563708
output:
257429683
result:
ok answer is '257429683'
Test #35:
score: 0
Accepted
time: 331ms
memory: 202700kb
input:
692290 942095 553970
output:
82511143
result:
ok answer is '82511143'
Test #36:
score: 0
Accepted
time: 330ms
memory: 202484kb
input:
579579 765702 631728
output:
954001361
result:
ok answer is '954001361'
Test #37:
score: 0
Accepted
time: 329ms
memory: 201000kb
input:
756854 634736 567170
output:
393747028
result:
ok answer is '393747028'
Test #38:
score: 0
Accepted
time: 331ms
memory: 203344kb
input:
649175 997874 511181
output:
242172216
result:
ok answer is '242172216'
Test #39:
score: 0
Accepted
time: 332ms
memory: 202740kb
input:
786431 1000000 999999
output:
627359027
result:
ok answer is '627359027'