提交时间:2023-08-14 12:26:49

运行 ID: 98185

#include<bits/stdc++.h> using namespace std; #define ll long long template<typename T>inline void read(T &ret){ ret=0;T fh=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')fh=-1;ch=getchar();} while(isdigit(ch))ret=ret*10+(ch^48),ch=getchar(); ret*=fh; } const int N=2e5+5; ll n,a[N],b[N],s[N]; inline void solve1(){ ll sum=0,ans=0; for(int i=1;i<=n;++i) sum+=b[i]; for(int i=1;i<=n;++i) ans+=b[i]*n+sum; printf("%lld\n",ans); } inline void solve2(){ ll cnt[12],sum,ans=0; memset(cnt,0,sizeof(cnt)); for(int i=1;i<=n;++i) ++cnt[a[i]]; for(int i=0;i<=9;++i){ if(!cnt[i])continue; sum=0; for(int j=0;j<=9;++j){ if(i+j<=9)sum+=cnt[j]*(i+j); else sum+=cnt[j]*(i+j-9); } ans+=sum*cnt[i]; } printf("%lld\n",ans); } inline void solve3(){ ll ans=0; for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) for(ll k=a[i]+a[j];k;k/=10) ans+=k%10; printf("%lld\n",ans); } int main(){ read(n); bool A=1,B=1; for(int i=1;i<=n;++i){ read(a[i]); if(a[i]>9)A=0; for(ll x=a[i];x;x/=10){ b[i]+=x%10; if(x%10>4)B=0; } } if(B)solve1(); else if(A)solve2(); else solve3(); return 0; }