提交时间:2023-08-14 12:24:35

运行 ID: 98170

#include<bits/stdc++.h> #define ll long long using namespace std; ll read(){ ll x;char c; while((c=getchar())<'0'||c>'9'); x=c-48; while((c=getchar())>='0'&&c<='9')x=x*10-48+c; return x; } void write(ll x){ if(x>9)write(x/10); putchar(x%10+48); } const int maxn=200020; const ll maxnumber=1000000000000000ll; ll a[maxn],tmp; ll b[10][maxn],bi[10]; int main(){ int n=read(),t; ll lans=0,x; for(int i=1;i<=n;i++){ a[i]=x=read(); while(x!=0){ lans+=x%10; x/=10; } } lans*=2*n; for(ll i=1;i<maxnumber;i*=10){ x=i*10; for(int j=0;j<10;j++)bi[j]=0; for(int j=1;j<=n;j++){ t=a[j]/i%10; b[t][++bi[t]]=a[j]; } t=0; for(int j=0;j<10;j++) for(int k=1;k<=bi[j];k++) a[++t]=b[j][k]; t=n; for(int j=1;j<=n;j++){ while(t!=0&&a[j]%x+a[t]%x>=x)t--; lans-=9*(n-t); } } printf("%lld\n",lans); return 0; }