提交时间:2023-08-14 13:52:54
运行 ID: 98265
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 2e5+2; int n,k = 1,ans,a[N],dig[17][N]; signed main() { scanf("%lld",&n); for(int i = 1;i <= n;i++) { scanf("%lld",&a[i]); for(int x = a[i],p = 1,ten = 1;x;x /= 10,p++,ten *= 10) { dig[p][i] = dig[p-1][i]+ten*(x%10); ans += 2*n*(x%10); if(x%10 > 4) k = 0; } } if(k) { printf("%lld",ans); return 0; } for(int d = 1,ten = 10;d <= 16;d++,ten *= 10) { sort(dig[d]+1,dig[d]+n+1); for(int i = n,p = 1;i >= 1;i--) { for(;p <= n && dig[d][p] < ten-dig[d][i];p++); ans -= 9*(n-p+1); } } printf("%lld",ans); return 0; }