论0.07s怎么卡
  • 板块灌水区
  • 楼主stylus
  • 当前回复14
  • 已保存回复14
  • 发布时间2024/8/29 15:28
  • 上次更新2024/9/1 19:17:54
查看原帖
论0.07s怎么卡
836448
stylus楼主2024/8/29 15:28

记录
代码:

#include<bits/stdc++.h>
#define int long long
using namespace std;
void read(int &x){
	x=0;bool f=0;char ch=getchar();
	while(ch>'9'||ch<'0'){
		if(ch=='-')f=1;
		ch=getchar();
	}do{x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}while(ch>='0'&&ch<='9');
	x=f?-x:x;
}
int p,dp[1000001],a[1000001],sum;
string s;
signed main(){
	read(p),cin>>s;
	for(int i=0;i<p;i++)a[i]=0;
	for(int i=0;i<s.size();i++){
		for(int j=0;j<p;j++)dp[j]=0;
		int d=s[i]-48;
		for(int j=0;j<p;j++)dp[(d+j*10)%p]+=a[j];
		dp[d%p]++,sum+=dp[0];
		for(int j=0;j<p;j++)a[j]=dp[j];
	}cout<<sum;
	return 0;
}
2024/8/29 15:28
加载中...