QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#585191#9116. DRD StringyhdddRE 1ms5924kbC++201.1kb2024-09-23 19:39:532024-09-23 19:39:54

Judging History

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

  • [2024-09-23 19:39:54]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5924kb
  • [2024-09-23 19:39:53]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,m,ans;
int dp[maxn],pw[maxn];
void work(){
	n=read();m=read();
	pw[0]=1;for(int i=1;i<=n;i++)pw[i]=pw[i-1]*m%mod;
	for(int i=1,sum=0;i<=n;i++){
		sum=sum*m%mod;
		if(i%2==0)(sum+=dp[i/2])%=mod;
		dp[i]=(pw[i]+mod-sum)%mod;
		// cout<<i<<" "<<dp[i]<<"\n";
	}
	for(int i=1;2*i<n;i++)(ans+=dp[i]*pw[n-2*i])%=mod;
	printf("%lld\n",ans);
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5804kb

input:

6 2

output:

40

result:

ok "40"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5900kb

input:

3017 7801

output:

515391664

result:

ok "515391664"

Test #3:

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

input:

3 1

output:

1

result:

ok "1"

Test #4:

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

input:

4 7

output:

343

result:

ok "343"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5848kb

input:

5 4

output:

304

result:

ok "304"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5924kb

input:

8 8

output:

2355200

result:

ok "2355200"

Test #7:

score: 0
Accepted
time: 1ms
memory: 5804kb

input:

7 6

output:

54216

result:

ok "54216"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5888kb

input:

1330 3031

output:

139921223

result:

ok "139921223"

Test #9:

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

input:

4946 3837

output:

64102067

result:

ok "64102067"

Test #10:

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

input:

4236 3305

output:

78581604

result:

ok "78581604"

Test #11:

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

input:

399 3245

output:

714500544

result:

ok "714500544"

Test #12:

score: 0
Accepted
time: 1ms
memory: 5776kb

input:

4881 2346

output:

28365995

result:

ok "28365995"

Test #13:

score: 0
Accepted
time: 1ms
memory: 5912kb

input:

4647 3069

output:

798067847

result:

ok "798067847"

Test #14:

score: 0
Accepted
time: 1ms
memory: 5892kb

input:

3414 4280

output:

669878613

result:

ok "669878613"

Test #15:

score: -100
Runtime Error

input:

1000000 1000000

output:


result: