fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. constexpr int MOD = 998244353;
  7. int main() {
  8. string S; cin >> S;
  9. int N = S.size();
  10. vector<ll> W(N, 1), V(N);
  11. for (int i = 0; i < N; ++i) V[i] = S[i] - '0';
  12. for (int i = N-2; i >= 0; --i) W[i] = 10 * W[i+1] % MOD;
  13. ll ans = 0;
  14. for (int a = 0; a < N; ++a) {
  15. for (int b = a+1; b < N; ++b) {
  16. for (int c = b+1; c < N; ++c) {
  17. if (a == 0 && S[c] == '0') continue;
  18. swap(V[c],V[b]);
  19. swap(V[a],V[b]);
  20. for (int i = 0; i < N; ++i) ans += W[i] * V[i];
  21. ans %= MOD;
  22. swap(V[a],V[b]);
  23. swap(V[c],V[b]);
  24. }
  25. }
  26. }
  27. cout << (ans%MOD+MOD)%MOD << endl;
  28. }
  29.  
Success #stdin #stdout 1.66s 4544KB
stdin
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
stdout
147467388