Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
34428 | 22级廖思学 | 【S】T3 | C++ | 运行超时 | 40 | 2000 MS | 248 KB | 2138 | 2024-11-07 19:18:07 |
#include<bits/stdc++.h> using namespace std; #define int long long int n,nn,a[30],cnt,b[30],c[30],ans; void swap(int &x,int &y){int c=x;x=y;y=c;} int check(int x){ // cout<<x<<endl; int y=nn-x;//cout<<y<<endl; if(y<0)return 0; int ct=0;int flag=1; while(y>0){c[++ct]=y%10;y/=10;} for(int i=1;i*2<=ct;i++)if(c[i]!=c[ct-i+1])flag=0; //cout<<flag<<endl; return flag; } signed main(){ cin>>n;nn=n; while(n>0){a[++cnt]=n%10;n/=10;} for(int i=1;i*2<=cnt;i++){swap(a[i],a[cnt-i+1]);} int mmax=0; for(int i=1;i<=cnt/2;i++){mmax*=10;mmax+=a[i];} if(cnt%2==0){ for(int i=1;i<=mmax;i++){ int ii=i,x=0,ct=0; while(ii>0){b[++ct]=ii%10;ii/=10;} for(int j=ct;j>=1;j--){x*=10;x+=b[j];} for(int j=1;j<=ct;j++){x*=10;x+=b[j];} ans+=check(x); } mmax=1; for(int i=1;i<=(cnt-1)/2;i++)mmax*=10; for(int i=0;i<mmax;i++){ for(int j=0;j<=9;j++){ int ii=i,x=0,ct=0; while(ii>0){b[++ct]=ii%10;ii/=10;} for(int j=ct;j>=1;j--){x*=10;x+=b[j];} x*=10;x+=j; if(i!=0)for(int j=1;j<=ct;j++){x*=10;x+=b[j];} ans+=check(x); } } printf("%lld\n",ans); } else{ for(int i=0;i<=mmax;i++){ for(int j=0;j<=a[(cnt+1)/2];j++){ int ii=i,x=0,ct=0; while(ii>0){b[++ct]=ii%10;ii/=10;} for(int j=ct;j>=1;j--){x*=10;x+=b[j];} x*=10;x+=j; if(i!=0)for(int j=1;j<=ct;j++){x*=10;x+=b[j];} ans+=check(x); } } mmax=1; for(int i=1;i<=(cnt-1)/2;i++)mmax*=10; for(int i=1;i<=mmax;i++){ int ii=i,x=0,ct=0; while(ii>0){b[++ct]=ii%10;ii/=10;} for(int j=ct;j>=1;j--){x*=10;x+=b[j];} for(int j=1;j<=ct;j++){x*=10;x+=b[j];} ans+=check(x); } printf("%lld\n",ans); } return 0; }