提交时间:2023-08-14 11:57:16

运行 ID: 98056

//80pts #include <bits/stdc++.h> using namespace std; #define int long long inline int Read() { int x = 0 , f = 1; char c = getchar(); for( ; c < '0' || c > '9' ; c = getchar() ) f ^= ( c == '-' ); for( ; c >= '0' && c <= '9' ; c = getchar() ) x = ( x << 3 ) + ( x << 1 ) + ( c ^ 48 ); return f ? x : -x; } const int _ = 2e5 + 5; int n; int a[_]; int F( int x ) { int ans = 0; while( x ) { ans += x % 10; x /= 10; } return ans; } void Subtask1() { int ans = 0; for( int k = 1 ; k <= n ; k++ ) { for( int i = 1 ; i <= n ; i++ ) { ans += F( a[ i ] + a[ k ] ); } } cout << ans << '\n'; exit( 0 ); } int sum1[ 10 ] , sum2[ 20 ]; void Subtask2() { for( int i = 1 ; i <= n ; i++ ) { sum1[ a[ i ] ]++; } for( int i = 0 ; i <= 10 ; i++ ) { for( int j = 0 ; j <= 10 ; j++ ) { sum2[ i + j ] += sum1[ i ] * sum1[ j ]; } } int ans = 0; for( int i = 0 ; i <= 20 ; i++ ) { ans += F( i ) * sum2[ i ]; } cout << ans << '\n'; exit( 0 ); } int f[_]; void Subtask3() { int ans = 0; for( int i = 1 ; i <= n ; i++ ) { ans += f[ i ]; } cout << ans * 2 * n << '\n'; exit( 0 ); } signed main() { // freopen( "A.in" , "r" , stdin ); // freopen( "A.ans" , "w" , stdout ); n = Read(); for( int i = 1 ; i <= n ; i++ ) { a[ i ] = Read(); } if( n <= 5000 ) Subtask1(); int b1 = 1; for( int i = 1 ; i <= n ; i++ ) { b1 &= ( a[ i ] < 10 ); } if( b1 ) Subtask2(); int b2 = 1; for( int i = 1 ; i <= n ; i++ ) { int tmp = a[ i ]; while( tmp ) { if( tmp % 10 > 4 ) { b2 = 0; exit( 0 ); } f[ i ] += tmp % 10; tmp /= 10; } } if( b2 ) Subtask3(); return 0; }