QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135537#6637. Perfect StringsPlentyOfPenaltyWA 355ms159792kbC++201.5kb2023-08-05 17:35:242023-08-05 17:35:26

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 17:35:26]
  • Judged
  • Verdict: WA
  • Time: 355ms
  • Memory: 159792kb
  • [2023-08-05 17:35:24]
  • Submitted

answer

#include<bits/stdc++.h>
// #define endl '\n'
using namespace std;
using ll=long long;
const int N=1e7+9;
const int mod=998244353;
// const int mod=1e9+7;
const int inv2=(mod+1)>>1;
int T,n,c,fac[N],ifac[N],ffac[N],f[N],g[N];
inline int power(int a,int b){
	int s=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1)s=(ll)s*a%mod;
	return s;
}
int main(){
#ifdef memset0
	freopen("G.in","r",stdin);
#endif
	ios::sync_with_stdio(0),cin.tie(0);
	fac[0]=ifac[0]=ifac[1]=ffac[0]=1;
	for(int i=2;i<N;i++)ifac[i]=(ll)(mod-mod/i)*ifac[mod%i]%mod;
	for(int i=1;i<N;i++){
		fac[i]=(ll)fac[i-1]*i%mod;
		ifac[i]=(ll)ifac[i-1]*ifac[i]%mod;
		ffac[i]=(ll)ffac[i-1]*((i<<1)-1)%mod;
	}
	f[0]=1;
	for(int i=1,x=(mod+1)>>1;i<N;i++){
		f[i]=(ll)x*ifac[i]%mod*ffac[i-1]%mod;
		x=x&1?(x+mod)>>1:x>>1;
		x=x?mod-x:x;
	}
	// for(int i=0;i<=10;i++)cerr<<f[i]<<" \n"[i==10];
	cin>>T;
	while(T--){
		cin>>n>>c;
		if(c==1){
			cout<<1<<endl;
			continue;
		}
		for(int i=0,cc=(ll)c*c%mod,x=1;i<=n;i++,x=(ll)x*cc%mod)g[i]=x;
		int ans=0;
		for(int i=0;i<=n;i++){
			int F=(ll)f[i]*(mod-c)%mod*power(4ll*(mod+1-c)%mod,i)%mod;
			if(i==0)F=((ll)F+c-2+mod)%mod;
			// fprintf(stderr,"i=%d f=%d g=%d\n",i,F,g[n-i]);
			ans=(ans+(ll)F*g[n-i])%mod;
		}
		cout<<(ll)ans*(mod-inv2)%mod<<endl;
	}
}
// 1 499122177 124780544 935854081 38993920 970948609 20471808 982159361 13069056 987353473
// 1 499122177 124780544 935854081 38993920 970948609 20471808 982159361 13069056 987353473

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 130ms
memory: 159724kb

input:

2
3 1
2 2

output:

1
6

result:

ok 2 number(s): "1 6"

Test #2:

score: 0
Accepted
time: 233ms
memory: 159792kb

input:

100000
1 1
4 1
5 5
3 5
1 2
5 3
1 1
3 3
5 2
2 1
4 1
5 5
2 3
4 1
3 3
2 5
3 2
4 3
4 4
3 5
3 1
5 2
2 2
4 2
5 4
1 2
3 1
4 5
2 5
5 3
1 5
5 2
3 2
5 2
4 1
1 3
3 2
4 5
2 1
4 1
2 2
1 1
3 5
4 5
2 3
3 5
2 5
2 4
5 4
2 3
1 1
2 1
4 4
1 5
5 4
1 3
5 4
4 5
1 3
1 1
3 3
2 4
2 4
2 1
5 5
1 3
2 3
4 1
4 3
2 4
2 4
4 2
1 1
1...

output:

1
1
71445
485
2
3543
1
87
252
1
1
71445
15
1
87
45
20
543
2092
485
1
252
6
70
19864
2
1
5725
45
3543
5
252
20
252
1
3
20
5725
1
1
6
1
485
5725
15
485
45
28
19864
15
1
1
2092
5
19864
3
19864
5725
3
1
87
28
28
1
71445
3
15
1
543
28
28
70
1
1
71445
15
2092
3
1
2
15
87
2092
19864
71445
6
252
2092
252
15...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 355ms
memory: 159684kb

input:

100000
94 7867320
84 1294950
35 8570570
72 7050952
23 3907221
95 7482398
58 2363048
44 2234552
50 8809524
37 1061961
19 884367
38 3261675
59 1563189
61 7603994
83 3131714
19 6207284
64 5662457
2 6845951
84 4688192
13 7552675
38 3119650
84 6311084
10 5040332
53 5981961
46 7308176
43 679952
30 2922213...

output:

975327847
788674353
827312213
109495870
773470152
454524439
160184101
957856848
918935311
730955741
490482934
264480575
314194639
753166709
976671691
638663253
333660568
935084857
871014156
870492350
57359719
359886267
963457135
826300578
14986197
847658020
672375217
871715508
529645608
212264882
86...

result:

wrong answer 1st numbers differ - expected: '89775996', found: '975327847'