提交时间:2023-08-15 07:59:25

运行 ID: 98437

#include<bits/stdc++.h> #define int long long using namespace std; const int N=2e5+5; int n,a[N]; int sum[N][20]; vector<int>nbr[N]; int f(int cur,int x){ int ansi=0,cnt=0,now=1; while(x){ cnt++; ansi+=(x%10); sum[cur][cnt]=sum[cur][cnt-1]+(x%10)*now; now*=10; x/=10; } return ansi; } signed main(){ ios::sync_with_stdio(false); cin>>n; int ansi=0; for(int i=1;i<=n;i++){ cin>>a[i]; ansi+=f(i,a[i]); for(int j=1;j<=15;j++){ if(!sum[i][j]) sum[i][j]=sum[i][j-1]; nbr[j].push_back(sum[i][j]); } } for(int i=1;i<=15;i++){ nbr[i].push_back(0); sort(nbr[i].begin(),nbr[i].end()); } int tmp=0,k=1; for(int i=1;i<=15;i++){ int now=n; k*=10; for(int j=0;j<nbr[i].size();j++){ while(nbr[i][j]+nbr[i][now]>=k) now--; } tmp+=n-now; } cout<<ansi*2*n-tmp*9; return 0; }