提交时间:2023-08-14 15:17:58

运行 ID: 98333

#include "bits/stdc++.h" #define ll long long using namespace std; long long n,a[2001000][20],ans,t1,t2; ll sol(long long x) { ll tot=0; while(x!=0) { tot+=x%10; x/=10; } return tot; } int main() { freopen("aa.in","r",stdin); freopen("ans.out","w",stdout); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i][0]; if(a[i][0]>9) t1=1; ll b=a[i][0],cnt=0; while(b) { a[i][++cnt]=b%10,b/=10; if(a[i][cnt]>4) t2=1; } } if(t1==0&&t2==0) { long long x=0; for(int i=1;i<=n;i++) x+=a[i][0]; for(int i=1;i<=n;i++) { ans+=x+n*a[i][0]; } cout<<ans; } else { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { long long x=a[i][0]+a[j][0]; ans+=sol(x); } } cout<<ans; } }