提交时间:2023-08-15 21:02:47
运行 ID: 98526
#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 void chai(ll a, int i) { int ret = 0; while(a) ret+=a%10, a/=10; f[i] = ret; } inline int read() { int 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++) { a[i] = read(); chai(a[i], i); 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; }