QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#49110 | #1810. Generate the Sequences | Crysfly | AC ✓ | 36ms | 7652kb | C++11 | 2.4kb | 2022-09-19 15:07:28 | 2022-09-19 15:07:31 |
Judging History
answer
// what is matter? never mind.
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
//#define int long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
// modint
#define mod 998244353
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,int b){return a.x==b;}
friend bool operator !=(modint a,int b){return a.x!=b;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 500005
#define inf 0x3f3f3f3f
int n,m;
modint coef[maxn],f[maxn];
signed main()
{
n=read()+1,m=read();
coef[0]=1;
For(i,1,n)coef[i]=coef[i-1]*((m-2)-i+1);
f[1]=1;
For(i,2,n){
f[i]=f[i-1];
Rep(j,i-1,1){
int t=i-j-1;
f[i]+=f[j]*coef[t]*C(n-j-1,t);
}
}
cout<<f[n].x;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7444kb
input:
2 3
output:
5
result:
ok answer is '5'
Test #2:
score: 0
Accepted
time: 7ms
memory: 7420kb
input:
1024 52689658
output:
654836147
result:
ok answer is '654836147'
Test #3:
score: 0
Accepted
time: 4ms
memory: 7544kb
input:
1 2
output:
2
result:
ok answer is '2'
Test #4:
score: 0
Accepted
time: 4ms
memory: 7560kb
input:
1 3
output:
2
result:
ok answer is '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 7392kb
input:
1 100000000
output:
2
result:
ok answer is '2'
Test #6:
score: 0
Accepted
time: 4ms
memory: 7456kb
input:
2 2
output:
4
result:
ok answer is '4'
Test #7:
score: 0
Accepted
time: 2ms
memory: 7556kb
input:
2 4
output:
6
result:
ok answer is '6'
Test #8:
score: 0
Accepted
time: 5ms
memory: 7452kb
input:
2 5
output:
7
result:
ok answer is '7'
Test #9:
score: 0
Accepted
time: 4ms
memory: 7616kb
input:
2 100000000
output:
100000002
result:
ok answer is '100000002'
Test #10:
score: 0
Accepted
time: 1ms
memory: 7384kb
input:
3 2
output:
8
result:
ok answer is '8'
Test #11:
score: 0
Accepted
time: 1ms
memory: 7620kb
input:
3 3
output:
14
result:
ok answer is '14'
Test #12:
score: 0
Accepted
time: 3ms
memory: 7612kb
input:
3 4
output:
22
result:
ok answer is '22'
Test #13:
score: 0
Accepted
time: 1ms
memory: 7528kb
input:
3 5
output:
32
result:
ok answer is '32'
Test #14:
score: 0
Accepted
time: 3ms
memory: 7616kb
input:
3 100000000
output:
446563791
result:
ok answer is '446563791'
Test #15:
score: 0
Accepted
time: 35ms
memory: 7432kb
input:
3000 2
output:
21292722
result:
ok answer is '21292722'
Test #16:
score: 0
Accepted
time: 32ms
memory: 7652kb
input:
3000 3
output:
172222927
result:
ok answer is '172222927'
Test #17:
score: 0
Accepted
time: 36ms
memory: 7456kb
input:
3000 100000000
output:
736503947
result:
ok answer is '736503947'
Test #18:
score: 0
Accepted
time: 23ms
memory: 7572kb
input:
2522 61077387
output:
857454425
result:
ok answer is '857454425'
Test #19:
score: 0
Accepted
time: 4ms
memory: 7464kb
input:
426 7215704
output:
799491736
result:
ok answer is '799491736'
Test #20:
score: 0
Accepted
time: 1ms
memory: 7396kb
input:
772 72289915
output:
848141383
result:
ok answer is '848141383'
Test #21:
score: 0
Accepted
time: 11ms
memory: 7436kb
input:
1447 83321470
output:
160422285
result:
ok answer is '160422285'
Test #22:
score: 0
Accepted
time: 26ms
memory: 7420kb
input:
2497 64405193
output:
355300540
result:
ok answer is '355300540'
Test #23:
score: 0
Accepted
time: 2ms
memory: 7468kb
input:
775 9385367
output:
470172346
result:
ok answer is '470172346'
Test #24:
score: 0
Accepted
time: 3ms
memory: 7540kb
input:
982 72596758
output:
7144187
result:
ok answer is '7144187'
Test #25:
score: 0
Accepted
time: 4ms
memory: 7456kb
input:
417 26177178
output:
776374896
result:
ok answer is '776374896'
Test #26:
score: 0
Accepted
time: 17ms
memory: 7476kb
input:
1932 19858856
output:
285834553
result:
ok answer is '285834553'
Test #27:
score: 0
Accepted
time: 30ms
memory: 7420kb
input:
2728 23009122
output:
433516287
result:
ok answer is '433516287'
Test #28:
score: 0
Accepted
time: 16ms
memory: 7432kb
input:
1857 22578508
output:
243488639
result:
ok answer is '243488639'
Test #29:
score: 0
Accepted
time: 34ms
memory: 7576kb
input:
2918 69623276
output:
546299707
result:
ok answer is '546299707'
Test #30:
score: 0
Accepted
time: 9ms
memory: 7480kb
input:
1679 21332149
output:
217000656
result:
ok answer is '217000656'
Test #31:
score: 0
Accepted
time: 6ms
memory: 7468kb
input:
1340 6251797
output:
267221018
result:
ok answer is '267221018'
Test #32:
score: 0
Accepted
time: 7ms
memory: 7472kb
input:
868 64770398
output:
652067665
result:
ok answer is '652067665'