結果
問題 | No.1964 sum = length |
ユーザー |
![]() |
提出日時 | 2022-06-04 16:13:13 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 70 ms / 2,000 ms |
コード長 | 2,457 bytes |
コンパイル時間 | 10,917 ms |
コンパイル使用メモリ | 278,972 KB |
最終ジャッジ日時 | 2025-01-29 18:08:40 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#pragma GCC target("avx2")#pragma GCC optimize("O3")#pragma GCC optimize("unroll-loops")#include<bits/stdc++.h>using namespace std;using ll = long long;const int INF = 1e9;const ll inf = 1LL<<62;template<int MOD> struct ModInt {static const int Mod = MOD; unsigned x; ModInt() : x(0) { }ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }int get() const { return (int)x; }ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }ModInt operator+(ModInt that) const { return ModInt(*this) += that; }ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }return ModInt(u); }bool operator==(ModInt that) const { return x == that.x; }bool operator!=(ModInt that) const { return x != that.x; }ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }};template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }typedef ModInt<998244353> mint;void solve() {int n; cin >> n;vector<mint> c(2*n);int x = 1;while (1) {int p = x - ((int)to_string(x).size() - 1);if (p > 2*n - 1) break;c[p] += mint(1);x++;}vector<vector<mint>> dp(n+1, vector<mint>(2*n));dp[0][0] = mint(1);for (int i=0; i<n; i++) {for (int j=0; j<2*n; j++) {for (int k=0; k<2*n; k++) {if (j+k >= 2*n) continue;dp[i+1][j+k] += dp[i][j]*c[k];}}}cout << dp[n][2*n-1] << '\n';}int main() {ios::sync_with_stdio(false);std::cin.tie(nullptr);// int t; cin >> t;/*while (t--)*/ solve();}