提交时间:2023-08-15 21:12:09
运行 ID: 98529
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 2e5 + 5; int n; ll a[MX], f[MX], b[MX]; ll lans = 0, sum, x; ll ten[16] = {0, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000}; inline int read() { ll f=1, x=0; char c=getchar(); while(c<'0' || c>'9'){if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9') x=(x<<3)+(x<<1)+c-48, c=getchar(); x*=f; return x; } int main() { cin>>n; for(int i=1; i<=n; ++i) { x = read(); a[i] = x; while(x) f[i]+=x%10, x/=10; lans += (2*n)*f[i]; } for(x=10; x<=1e15; x*=10) { stable_sort(a+1, a+n+1, [](ll u,ll v) {return u%x<v%x;}); for(int i=1; i<=n; ++i) b[i] = a[i]%x; for(int i=1; i<=n; ++i) sum += b+n+1-lower_bound(b+1, b+n+1, x-b[i]); } lans -= sum*9; cout<<lans<<"\n"; return 0; }