提交时间:2023-08-14 12:26:52
运行 ID: 98188
#include<bits/stdc++.h> using namespace std; #ifdef IAKIOI #define cin fin ifstream cin("in.txt"); #endif #define ll long long constexpr int N = 2e5 + 5; ll a[N], ans; int n, sum[N], cnt[15]; int f(ll x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline bool cka() { for (int i = 1; i <= n; ++i) if (a[i] > 9) return 0; return 1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; sum[i] = f(a[i]); } if (n <= 5000) { for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { ans += f(a[i] + a[j]); } } } else { for (int i = 1; i <= n; ++i) ans += 2 * n * sum[i]; if (cka()) { for (int i = 1; i <= n; ++i) ++cnt[a[i]]; for (int i = 1; i <= n; ++i) { for (int j = 10 - a[i]; j < 10; ++j) { ans -= 9 * cnt[j]; } } } } cout << ans << endl; return 0; }