Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
98090 | yangkangrui | 早凉的函数2 | C++ | 解答错误 | 60 | 1995 MS | 1836 KB | 2644 | 2023-08-14 12:00:11 |
#include <cstdio> #include <iostream> using namespace std; typedef long long ll; #define TYPE ll #define FOR(x,y,z) for (TYPE x = (y); x <= (z); x += 1) #define ROF(x,y,z) for (TYPE x = (z); x >= (y); x -= 1) #define FORR(x,y) FOR(x, 1, y) #define ROFF(x,y) ROF(x, y, 1) #define FORS(x,y) FOR(x, 0, (y) - 1) #define ROFS(x,y) ROF(x, (y) - 1, 0) // {{{ OI TYPE read() { TYPE x=0,f=1;char h=getchar(); while(!(h>='0'&&h<='9')){if(h=='-')f=-f;h=getchar();} while(h>='0'&&h<='9'){x=x*10+int(h-'0');h=getchar();} return x*f; } struct OI { OI operator >> (TYPE& x) const { x = read(); return *this; } } oi; // }}} const int N = 2e5 + 500; ll n, a[N]; int f(ll x) { int res = 0; while (x) { res += (x % 10); x /= 10; } return res; } namespace ch1 { bool check = true; void sol() { // cout << "ch1" << endl; ll ans = 0; FORR(k, n) FORR(i, n) ans += f(a[i] + a[k]); cout << ans << endl; return; } }; namespace ch24 { // B bool check = true; bool checkf(ll x) { while (x) { if (x % 10 > 4) return false; x /= 10; } return true; } void sol() { // cout << "ch24" << endl; ll ans = 0; FORR(i, n) { ans += f(a[i]); } ans *= (2 * n); cout << ans << endl; return; } }; namespace ch3 { bool check = true; bool checkf(ll x) { return x >= 0 && x <= 9; } int ca[20]; void init() { FOR(i, 0, 9) FOR(j, 0, 9) ca[i + j] = f(i + j); } int fn(ll x) { if (x > 18) return f(x); return ca[x]; } void sol() { ll ans = 0; FORR(k, n) FORR(i, n) ans += fn(a[i] + a[k]); cout << ans << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("d.in", "r", stdin); oi >> n; if (n > 5e3) ch1::check = false; FORR(i, n) { oi >> a[i]; if (ch24::check && ch24::checkf(a[i]) == false) { ch24::check = false; } if (ch3::check && ch3::checkf(a[i]) == false) { ch3::check = false; } } if (ch1::check) { ch1::sol(); return 0; } if (ch24::check) { ch24::sol(); return 0; } if (ch3::check) { ch3::sol(); return 0; } return 0; }