提交时间:2023-08-14 12:20:53

运行 ID: 98128

#include<bits/stdc++.h> #define int unsigned long long using namespace std; const int Maxn=2e5+5; int a[Maxn],s[Maxn],sum[Maxn],rec[Maxn]; int n,ans; bool A=1; inline int F(int num) { int res=0; while(num) res+=num%10,num/=10; return res; } inline int Add(int num1,int num2) { int arr1[20]={0},arr2[20]={0}; int p1=0,p2=0,res=0; while(num1) arr1[++p1]=num1%10,num1/=10; while(num2) arr2[++p2]=num2%10,num2/=10; for(int i=1;i<=min(p1,p2);i++) { if(arr1[i]+arr2[i]>9) arr1[i+1]++,res+=arr1[i]+arr2[i]-9; else res+=arr1[i]+arr2[i]; } return res; } signed main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; if(a[i]>9) A=0; } if(n<=5000) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) s[i]+=F(a[i]+a[j]); ans+=s[i]; } cout<<ans<<'\n'; } else { for(int i=1;i<=n;i++) rec[i]=rec[i-1]+F(a[i]); for(int i=1;i<=n;i++) { s[i]=rec[n]+n*F(a[i]); ans+=s[i]; } cout<<ans<<'\n'; } return 0; } /* 10 111 222 333 444 432 321 124 314 114 231 */