提交时间:2023-08-14 11:57:35

运行 ID: 98062

#include<bits/stdc++.h> #define int long long using namespace std; inline int read(){ int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } int n,a[200005],s[200005],f[200005],flagb=1; bool check_b(int x){ while(x){ if(x%10>4)return 0; x/=10; } return 1; } int check_f(int x){ int res=0; while(x){ res+=x%10; x/=10; } return res; } signed main(){ n=read(); for(int i=1;i<=n;i++){ a[i]=read(); if(!check_b(a[i]))flagb=0; } if(flagb){ int sum=0,sums=0,ans=0; for(int i=1;i<=n;i++)f[i]=check_f(a[i]),sum+=f[i]; for(int i=1;i<=n;i++)s[i]=sum+n*f[i],sums+=s[i]; cout<<sums<<endl; // }else if(flaga){ }else{ int sums=0,ans=0; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++)s[i]+=check_f(a[i]+a[j]); sums+=s[i]; } cout<<sums<<endl; } return 0; }