提交时间:2023-08-14 12:26:53
运行 ID: 98189
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 5; #define ll long long ll a[N], s[N]; int n; int main() { // freopen("function.in", "r", stdin); // freopen("function.out", "w", stdout); ios::sync_with_stdio(0); cin>>n; if(n <= 5e3) { end : ll ans = 0; for(int i = 1;i <= n;i ++) { cin>>a[i]; for(int j = 1;j < i;j ++) { ll tmp = a[i] + a[j]; while(tmp) { ans += tmp % 10; tmp /= 10; } } } // for(int i = 1;i <= n;i ++) // { // for(int j = 1;j <= n;j ++) // { // ll tmp = a[i] + a[j]; // while(tmp) // { // ans += tmp % 10; // tmp /= 10; // } // } // } ans <<= 1; for(int i = 1;i <= n;i ++) { ll tmp = a[i] << 1; while(tmp) { ans += tmp % 10; tmp /= 10; } } cout<<ans<<endl; return 0; } bool A = 1, B = 1; ll SUM = 0; for(int i = 1;i <= n;i ++) { cin>>a[i]; if(a[i] > 9) A = 0; ll tmp = a[i]; while(tmp) { ll now = tmp % 10; if(now > 4) B = 0; s[i] += now; tmp /= 10; } SUM += s[i]; } if(B) { ll ans = SUM * (n << 1); // for(int i = 1;i <= n;i ++) // ans += SUM + s[i] * n; cout<<ans<<endl; return 0; } goto end; }