1 条题解
-
0
显而易见,我们甚至不能把所有的情况枚举出来。
不过,我们很容易想到(这次真的很容易)可以把每一个数的贡献分成两部分:一个是作为 的前面的 ,还有后面的 。
对于第一部分。当前处理第 个数,就会作为后面 个的 计算的第一部分。因此,我们需要知道剩下的 个数的位数。然后乘 得到真实的贡献,再去乘数量即可。
对于第二部分。那就更简单了,当前就是作为前 个数的第二部分。
代码
#include <bits/stdc++.h> #define int long long using namespace std; int T = 1; const int N = 2e5 + 10, W = 10 + 1; const int MOD = 998244353; int n, ans; int arr[N]; int w[W]; int FastExp(int a, int b) { int res = 1; while (b) { if (b & 1) { res = (res * a) % MOD; } a = (a * a) % MOD; b >>= 1; } return res; } void Solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> arr[i]; w[to_string(arr[i]).size()]++; } for (int i = 1; i <= n; i++) { w[to_string(arr[i]).size()]--; for (int j = 1; j <= 10; j++) { if (w[j] == 0) continue; ans = (ans + ((w[j] * (FastExp(10, j) % MOD)) % MOD * arr[i]) % MOD) % MOD; } ans = (ans + ((i - 1) * arr[i]) % MOD) % MOD; } cout << ans; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); while (T--) { Solve(); } return 0; }
信息
- ID
- 3294
- 时间
- 2000ms
- 内存
- 1024MiB
- 难度
- 普及+/提高-
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者