Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
98150 CSYZShenJY 早凉的函数2 C++ 解答错误 60 993 MS 7292 KB 2122 2023-08-14 12:23:34

Tests(30/32):


#include <iostream> #define int long long using namespace std; const int N = 2e5 + 5; char a[N][20]; int len[N], s[N]; int n; int num[10]; int read(int x, int &f) { char c = getchar(); while (c < '0' || c > '9') { c = getchar(); } int cnt = 0; while (c >= '0' && c <= '9') { a[x][++cnt] = c; if (c > '4') { f = 0; } c = getchar(); } return cnt; } int f_ch(int x, int y) { int ad = 0, ans = 0, i = len[x], j = len[y]; while(1) { int Xa = (a[x][i] - '0'), Xb = (a[y][j] - '0'); ans += (Xa + Xb + ad) % 10; ad = (Xa + Xb + ad) / 10; --i, --j; if (i < 0) { i = 0; } if (j < 0) { j = 0; } if (i + j == 0) { break; } } return ans + ad; } void Solve1() { for (int i = 1; i <= n; ++ i) { for (int j = 1; j <= n; ++ j) { s[i] += f_ch(i, j); } } int sum = 0; for (int i = 1; i <= n; ++i) { sum += s[i]; } cout << sum; } int f_int(int x) { int ans = 0; for (int i = len[x]; i >= 1; -- i) { ans += a[x][i] - '0'; } return ans; } void Solve2() { int sum = 0, ans = 0; for (int i = 1; i <= n; ++ i) { s[i] = f_int(i); sum += s[i]; ans += s[i] * n; } cout << ans + n * sum; } inline void Solve3() { for (int i = 0; i <= 9; ++ i) { num[i] = -1; } int ans = 0; for (int i = 1; i <= n; ++ i) { int Xi = a[i][1] - '0'; if (num[Xi] != -1) { ans += num[Xi]; continue; } num[Xi] = 0; for (int j = 1; j <= n; ++ j) { int Xj = a[j][1] - '0'; if (Xi + Xj < 10) { num[Xi] += Xi + Xj; } else { num[Xi] += (Xi + Xj) % 10 + 1; } } ans += num[Xi]; } cout << ans; } signed main() { cin >> n; int flag1 = 1, flag2 = 1; for (int i = 1; i <= n; ++ i) { len[i] = read(i, flag2); if (len[i] > 1) { flag1 = 0; } } if (n <= 5e3) { Solve1(); } else if (flag2 == 1) { Solve2(); } else if (flag1 == 1) { Solve3(); } }


测评信息: