提交时间:2023-08-14 12:18:09

运行 ID: 98103

#include <bits/stdc++.h> using namespace std; int n, ans, sum, flag; int s[200005], c[200005]; long long a[200005]; int f(long long x) { int res = 0; while(x) { int t = x % 10; if (t > 4) flag = 1; res += t; x /= 10; } return res; } int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; c[i] = f(a[i]), sum += c[i]; } if (!flag) { for (int i = 1; i <= n; i++) { s[i] = n * c[i] + sum; ans += s[i]; } cout << ans; } else { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++){ s[i] += f(a[i] + a[j]); } ans += s[i]; } cout << ans; } return 0; }