提交时间:2023-08-14 14:40:57

运行 ID: 98300

#include<bits/stdc++.h> #define int long long using namespace std; inline int read() { int f=1,x=0; char c=getchar(); while(c>'9'||c<'0') { if(c=='-') f*=-1; c=getchar(); } while(c>='0'&&c<='9') { x=x*10+c-'0'; c=getchar(); } return x*f; } const int N=2e5+7; int ans,a[N],b[N]; int n; signed main() { n=read(); for(int i=1;i<=n;i++) { a[i]=read(); int now=a[i]; while(now) { ans+=now%10; now/=10; } } ans*=2*n; for(int x=10;x<=1e15;x*=10) { for(int i=1;i<=n;i++) { b[i]=a[i]%x; } sort(b+1,b+n+1); for(int i=1;i<=n;i++) ans-=(b+n+1-lower_bound(b+1,b+n+1,x-b[i]))*9; } printf("%lld\n",ans); return 0; }