提交时间:2023-08-14 12:28:22

运行 ID: 98213

#include<bits/stdc++.h> using namespace std; #define N 200001 #define ll long long int n; ll a[N],b[N]; ll ans; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%lld",a+i); ll nw=1; for(int k=0;k<=15;++k){ nw*=10; for(int j=1;j<=n;++j){ b[j]=a[j]%nw; ans+=2*n*((a[j]/(nw/10))%10); } sort(b+1,b+n+1); int i=1,j=n; for(;i<=n;++i){ while(j&&b[i]+b[j]>=nw)--j; ans-=9*(n-j); } } printf("%lld\n",ans); return 0; }