提交时间:2023-08-14 14:17:11
运行 ID: 98283
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 2e5+2; int n,k = 1,ans,a[N],b[N][17]; vector<int> vec[17]; 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) { b[i][p] = b[i][p-1]+ten*(x%10); ans += 2*n*(x%10); if(x%10 > 4) k = 0; } } if(k) { printf("%lld",ans); return 0; } for(int i = 1;i <= n;i++) for(int j = 1;j <= 16;j++) { if(!b[i][j]) b[i][j] = b[i][j-1]; vec[j].push_back(b[i][j]); } for(int i = 1;i <= 16;i++) { vec[i].push_back(0); sort(vec[i].begin(),vec[i].end()); } for(int d = 1,ten = 10;d <= 16;d++,ten *= 10) for(int l = 0,r = n;l <= n;l++) { while(vec[d][r-1]+vec[d][l] >= ten) r--; if(vec[d][r]+vec[d][l] >= ten) ans -= (n-r+1)*9; } printf("%lld",ans); return 0; }