提交时间:2023-08-14 18:09:43
运行 ID: 98409
#include<bits/stdc++.h> using namespace std; #define ll long long ll a[200005],b[200005]; int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); ll ans=0; for(int i=1;i<=n;i++){ ll x=a[i]; while(x)ans+=x%10,x/=10; } ans*=n+n; ll p=1; for(int i=1;i<=15;i++){ p*=10; for(int i=1;i<=n;i++) b[i]=a[i]%p; sort(b+1,b+n+1); for(int i=1;i<=n;i++){ ll x=p-b[i]; int l=1,r=n,ap=n+1; while(l<=r){ int mid=(l+r)>>1; if(b[mid]>=x)r=mid-1,ap=mid; else l=mid+1; } ans-=9*(n-ap+1); } } printf("%lld",ans); return 0; }