版本比较
【题解】P13046 [GCJ 2021 Finals] Divisible Divisions
正文
增加 8 行删除 8 行
63 行未改动64656667686970717217 行未改动9091929394959697986 行未改动1051061071081091101111121131141151161171181198 行未改动1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601612 行未改动63 行未改动void clear(){memset(tf,0,sizeof(tf));sum1=0;}//清空long long fp(long long x,int k,int mod){long long s=1;while(k>=1){17 行未改动}void init(){for(int i=1;i<=n;i++)pre[i]=(pre[i-1]*10+s[i]-'0')%d;//计算 pre 数组b=d;int c2=0,c5=0;while(b%2==0){6 行未改动b/=5;}a=d/b;c=max(max(c2,c5),1);//计算 a,b,clong long x,y;exgcd(fp(10,n,b),b,x,y);inv[n]=(x%b+b)%b;for(int i=n-1;i>=0;i--)inv[i]=inv[i+1]*10%b;//预处理 10 的幂在 mod b 意义下的逆元}int main(){int t;scanf("%d",&t);8 行未改动f[0][1]=1;for(int i=1;i<=n;i++){sum1=(sum1+f[i-1][1])%mod;//计算 f[i][1] 的前缀和if(i>=c){int ti=id(i-c);tf[0][ti]=(tf[0][ti]+f[i-c][0])%mod;tf[1][ti]=(tf[1][ti]+f[i-c][1])%mod;}//将满足条件的 f 入桶f[i][0]=sum1;f[i][1]=0;if(pre[i]%a==0){int ti=id(i);f[i][0]=(f[i][0]-tf[1][ti]+mod)%mod;f[i][1]=(tf[0][ti]+tf[1][ti])%mod;}//第一种情况的转移for(int j=i-1,pow=10;j>=max(i-c+1,0);j--,pow=pow*10%d){if(pre[i]==(long long)pre[j]*pow%d){f[i][0]=(f[i][0]-f[j][1]+mod)%mod;f[i][1]=(f[i][1]+f[j][0]+f[j][1])%mod;}}//第二种情况的转移}printf("Case #%d: %lld\n",tt,(f[n][0]+f[n][1])%mod);}return 0;2 行未改动63 行未改动64656667686970717217 行未改动9091929394959697986 行未改动1051061071081091101111121131141151161171181198 行未改动1281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601612 行未改动63 行未改动void clear(){memset(tf,0,sizeof(tf));sum1=0;}//清空long long fp(long long x,int k,int mod){long long s=1;while(k>=1){17 行未改动}void init(){for(int i=1;i<=n;i++)pre[i]=(pre[i-1]*10+s[i]-'0')%d;//计算 pre 数组b=d;int c2=0,c5=0;while(b%2==0){6 行未改动b/=5;}a=d/b;c=max(max(c2,c5),1);//计算 a,b,clong long x,y;exgcd(fp(10,n,b),b,x,y);inv[n]=(x%b+b)%b;for(int i=n-1;i>=0;i--)inv[i]=inv[i+1]*10%b;//预处理 10 的幂在 mod b 意义下的逆元}int main(){int t;scanf("%d",&t);8 行未改动f[0][1]=1;for(int i=1;i<=n;i++){sum1=(sum1+f[i-1][1])%mod;//计算 f[i][1] 的前缀和if(i>=c){int ti=id(i-c);tf[0][ti]=(tf[0][ti]+f[i-c][0])%mod;tf[1][ti]=(tf[1][ti]+f[i-c][1])%mod;}//将满足条件的 f 入桶f[i][0]=sum1;f[i][1]=0;if(pre[i]%a==0){int ti=id(i);f[i][0]=(f[i][0]-tf[1][ti]+mod)%mod;f[i][1]=(tf[0][ti]+tf[1][ti])%mod;}//第一种情况的转移for(int j=i-1,pow=10;j>=max(i-c+1,0);j--,pow=pow*10%d){if(pre[i]==(long long)pre[j]*pow%d){f[i][0]=(f[i][0]-f[j][1]+mod)%mod;f[i][1]=(f[i][1]+f[j][0]+f[j][1])%mod;}}//第二种情况的转移}printf("Case #%d: %lld\n",tt,(f[n][0]+f[n][1])%mod);}return 0;2 行未改动