Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98186 | fkccf | 早凉的函数2 | C++ | 运行超时 | 40 | 1000 MS | 15040 KB | 1613 | 2023-08-14 12:26:49 |
#include<cstdio> #include<array> #include<algorithm> const int N=2e5+1; namespace B{ using V=std::array<int,16>;using R=const V&;V a[N];int v[N]; #undef ma #define ma(x) c[x]+=b[x] static inline V add(R a,R b){V c=a;ma(0);ma(1);ma(2);ma(3);ma(4);ma(5);ma(6);ma(7);ma(8);ma(9);ma(10);ma(11);ma(12);ma(13);ma(14);return c;} static inline int f(R v){return v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6]+v[7]+v[8]+v[9]+v[10]+v[11]+v[12]+v[13]+v[14]+v[15];}}; namespace D{ using V=std::array<int,16>;using R=const V&;V a[N]; #undef ma static inline void _ma(int b,int&c,int&d){c+=b;if(c>9)c-=10,d++;} #define ma(x) _ma(b[x],c[x],c[x+1]) static inline V add(R a,R b){V c=a;ma(0);ma(1);ma(2);ma(3);ma(4);ma(5);ma(6);ma(7);ma(8);ma(9);ma(10);ma(11);ma(12);ma(13);ma(14);return c;} static inline int f(R v){return v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6]+v[7]+v[8]+v[9]+v[10]+v[11]+v[12]+v[13]+v[14]+v[15];}} long long m[N];int main(){int n;scanf("%d",&n);long long r=0; bool Af=1,Bf=1;for(int i=1;i<=n;i++){scanf("%lld",m+i);if(m[i]>9)Af=false;}if(Af){ for(int i=1;i<=n;i++){r+=(m[i]<<1)-((m[i]<<1)>9?9:0);for(int j=i+1;j<=n;j++)r+=(m[i]+m[j]-(m[i]+m[j]>9?9:0))<<1;}goto O;} for(int i=1;i<=n;i++){long long x=m[i];int t=0;for(;x;x/=10){B::a[i][t++]=x%10;if(x%10>4){Bf=0;goto E;}}}E:; if(Bf){for(int i=1;i<=n;i++)B::v[i]=B::f(B::a[i]);for(int i=1;i<=n;i++)r+=(B::v[i]*n)<<1;goto O;} for(int i=1;i<=n;i++){long long x=m[i];int t=0;for(;x;x/=10)D::a[i][t++]=x%10;} for(int i=1;i<=n;i++){auto&e=D::a[i];r+=D::f(D::add(e,e));for(int j=i+1;j<=n;j++)r+=D::f(D::add(e,D::a[j]))<<1;} O:printf("%lld\n",r);return 0;}