Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98262 | CSYZLinZR | 早凉的函数2 | C++ | 解答错误 | 80 | 840 MS | 1820 KB | 1341 | 2023-08-14 13:38:33 |
#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 if (n <= 5e3) { i64 ans = 0; for (i64 i = 1; i <= n; ++i) { for (i64 j = 1; j <= n; ++j) { ans += f(a[i] + a[j]); } } printf("%lld\n",ans); } return 0; }