提交时间:2023-08-14 15:23:37
运行 ID: 98337
#include<bits/stdc++.h> using namespace std; #define ll long long const int N=2e5+5; ll n,a[N],b[N],ans,sum; int main(){ scanf("%lld",&n); for(int i=1;i<=n;++i){ scanf("%lld",&a[i]); for(ll j=a[i];j;j/=10) ans+=j%10; } ans*=n<<1; for(ll i=10;i<=1e15;i*=10){ sort(a+1,a+n+1,[&](ll X,ll Y){return X%i<Y%i;}); for(int j=1;j<=n;++j)b[j]=a[j]%i; for(int j=1;j<=n;++j) sum+=n+1-(lower_bound(b+1,b+n+1,i-b[j])-b); } printf("%lld\n",ans-sum*9); return 0; }