提交时间:2023-08-14 13:33:49
运行 ID: 98260
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; typedef long long i64; const i64 SIZE = 5e5+5; i64 n, m; i64 a[SIZE]; i64 f(i64 x) { int ret = 0; while (x) { ret += x % 10; x /= 10; } return ret; } namespace o3 { using :: n; using :: m; using :: a; int main() { sort(a + 1, a + 1 + n); i64 sum = 0, ans = 0; for (i64 i = 1; i <= n; ++i) sum += a[i]; for (i64 i = 1; i <= n; ++i) { i64 k = lower_bound(a + 1, a + 1 + n, 10 - a[i]) - a; ans += n - k + 1; ans += a[i] * n + sum - 10 * (n - k + 1); } cout << ans << endl; return 0; } } int main() { #ifdef fio freopen("test.in","r",stdin); #endif cin >> n; bool fgb = true, fga = true; for (int i = 1; i <= n; ++i) { scanf("%lld",a+i); if (a[i] > 9) fga = false; i64 cp = a[i]; while (cp) { if (cp % 10 > 4) fgb = false; cp /= 10; } } if (n == 1) { printf("%lld\n",f(a[1] + a[1])); } else if (fgb) { i64 sum = 0; for (i64 i = 1; i <= n; ++i) { sum += f(a[i]); } printf("%lld\n",2 * n * sum); } else if (fga) { return o3::main(); } else { puts("1"); } return 0; }