Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
34383 masppy 【S】T3 C++ 解答错误 30 51 MS 284 KB 3548 2024-11-07 18:29:04

Tests(3/10):


#include<bits/stdc++.h> #define ll long long #define lson pos<<1 #define rson pos<<1|1 using namespace std; const int maxn=1e6+10; const ll mod=1e9+1; const double inf=1e7+10; ll N,n,k,tot=0,m,ans=0,cnt,mn; int a[maxn],b[maxn],fg[maxn],islp[maxn],ltmp[maxn],rtmp[maxn]; int c[maxn]; int son[maxn][4]; int root=0; void calc(ll tot){ //cout<<1<<endl; for(int i=1;i<=(tot>>1);i++){ if(a[i]!=a[tot-i+1]) return; } ll tmp=1; for(int i=1;i<=(tot+1)>>1;i++){ // cout<<a[i]<<endl; tmp=tmp*(min(10,a[i]+1-(i==1))-max(a[i]-9,(int)(i==1))); // cout<<tmp<<endl; } if(a[1]%2==0) tmp--; // cout<<ans<<" "<<tmp<<endl; ans+=tmp; } void calc1(ll tot,ll dif){ int lenl=(tot-dif+1)>>1,lenr=(tot+1)>>1; int cnt=0,l=1,r=tot; for(int i=1;i<=dif;i++) ltmp[i]=0; while(l<=r){ // cout<<l<<" "<<r<<endl; int tott=0; while(tott<dif){ b[++cnt]=a[r--]; if(r<l) break; tott++; } tott=0; while(tott<dif){ b[++cnt]=a[l++]; if(r<l) break; tott++; } } //cout<<1<<endl; cnt=0; for(int i=1;i<=tot;){ int tott=0; if(!(cnt%2)){ while(tott<dif){ tott++; rtmp[tott]=b[i]-ltmp[tott]; // cout<<rtmp[tott]<<endl; if(rtmp[tott]<0||rtmp[tott]>9) return; i++; } } else{ while(tott<dif){ tott++; ltmp[tott]=b[i]-rtmp[tott]; // cout<<ltmp[tott]<<" "<<i<<endl; if(ltmp[tott]<0||ltmp[tott]>9) return; if(i==dif+1&&(!ltmp[tott])) return; i++; } } cnt++; } // for(int i=1;i<=tot;i++) cout<<a[i]<<" "; //cout<<endl; // for(int i=1;i<=tot;i++) cout<<b[i]<<" "; // cout<<endl; // cout<<ans<<" "<<dif<<endl; ans+=2; } int main(){ // freopen("palindrome.in","r",stdin); // freopen("palindrome.out","w",stdout); // memset(lst) scanf("%lld",&n); if(n<=1000000){ for(int i=1;i<=n;i++){ int tmp=i,tot=0; while(tmp){ c[++tot]=tmp%10; tmp/=10; } islp[i]=1; for(int j=1;j<=tot/2;j++){ if(c[j]!=c[tot-j+1]){ islp[i]=0; break; } } } int ans=0; for(int i=1;i<=n;i++){ if(islp[i]&&islp[n-i]) ans++; } printf("%d",ans); fclose(stdin); fclose(stdout); return 0; } ll tmp=n,tot=0; while(tmp){ c[++tot]=tmp%10; tmp/=10ll; } for(int i=0;i<(1<<(tot-1));i++){ for(int j=1;j<=tot;j++) a[j]=c[j]; bool fg=0; for(int j=0;j<tot-1;j++){ if((1<<j)&i){ a[j+2]--,a[j+1]+=10; if(a[j+1]<0||a[j+1]>18){ fg=1; break; } } } if(a[tot]<0||fg) continue; int tot1=tot; while(!a[tot1]) tot1--; calc(tot1); for(int j=1;j<tot1;j++){ calc1(tot1,j); } } printf("%lld",ans); fclose(stdin); fclose(stdout); return 0; }


测评信息: