QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569789#9330. Series SumCrysflyTL 1795ms3632kbC++142.7kb2024-09-17 10:46:472024-09-17 10:46:47

Judging History

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

  • [2024-09-17 10:46:47]
  • 评测
  • 测评结果:TL
  • 用时:1795ms
  • 内存:3632kb
  • [2024-09-17 10:46:47]
  • 提交

answer

// what is matter? never mind. 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#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 ll long long
//#define int long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
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;
}

#define mod 998244353
struct modint{
	unsigned 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?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,modint b){return a.x==b.x;}
	friend bool operator !=(modint a,modint b){return a.x!=b.x;}
	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 1000006
#define inf 0x3f3f3f3f

int p,k;
void work()
{
	k=read(),p=read();
	modint res=0;
	For(d,k,p*k){
		modint coe=0;
		For(len,d,p*k) coe+=C(len,d)*sign(len-d);
		res+=qpow(C(d,k),p)*coe;
	}
//	For(len,k,p*k)
//		For(c,0,len-k)
//			res+=sign(c)*C(len,c)*qpow(C(len-c,k),p);
	res*=2;
	cout<<res.x<<"\n";
}

signed main()
{
	int T=read();
	while(T--)work();
	return 0;
}
/*

*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

3
2 3
1 10
9 6

output:

818
204495126
16726290

result:

ok 3 number(s): "818 204495126 16726290"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

3
10 1
1 3
1 2

output:

2
26
6

result:

ok 3 number(s): "2 26 6"

Test #3:

score: 0
Accepted
time: 1795ms
memory: 3548kb

input:

2112
16 51
27 30
32 22
6 69
1 7
6 40
15 63
23 37
11 57
6 92
8 62
5 50
11 76
1 57
99 8
2 90
35 10
13 54
6 33
8 70
14 48
12 63
7 99
85 7
14 60
7 78
22 22
1 53
6 61
2 67
8 68
5 67
7 57
8 79
11 29
15 44
8 62
19 39
9 71
3 65
3 83
6 16
11 86
7 25
124 6
1 21
5 76
17 35
14 29
1 55
67 13
987 1
8 27
4 99
8 19...

output:

958728366
182850046
337462356
238321759
94586
688819126
880558546
673294800
592760052
772846256
555807947
834237048
258386591
443217990
83210442
741605708
687991731
380324156
884202426
190172937
130140451
931313604
659396498
344165836
434542961
111646504
6836992
571531367
631528990
880394933
1976309...

result:

ok 2112 numbers

Test #4:

score: -100
Time Limit Exceeded

input:

6
1 164257
7 10955
1 30358
1 198674
1 206507
1 323519

output:


result: