結果
| 問題 |
No.2437 Fragile Multiples of 11
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-16 22:01:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,078 bytes |
| コンパイル時間 | 1,662 ms |
| コンパイル使用メモリ | 199,320 KB |
| 最終ジャッジ日時 | 2025-02-16 08:50:18 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 998244353;
void ch(int &a, int b) {
a = a + b;
if (a >= mod) a -= mod;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
string X;
cin >> N >> X;
for (auto &i : X) i -= '0';
vector dp0(N, vector(11, 0)), dp1(N, vector(11, 0));
for (int i = 1; i < X[0]; i++) {
dp1[0][i] = 1;
}
dp0[0][X[0]] = 1;
for (int i = 1; i < N; i++) {
for (int j = 0; j < 11; j++) {
for (int k = 0; k < 10; k++) {
if ((j * 2 - k) % 11 != 0) {
ch(dp1[i][(j * 10 + k) % 11], dp1[i - 1][j]);
}
}
for (int k = 0; k < X[i]; k++) {
if ((j * 2 - k) % 11 != 0) {
ch(dp1[i][(j * 10 + k) % 11], dp0[i - 1][j]);
}
}
if ((j * 2 - X[i]) % 11 != 0) {
ch(dp0[i][(j * 10 + X[i]) % 11], dp0[i - 1][j]);
}
}
for (int k = 1; k < 10; k++) {
ch(dp1[i][k], 1);
}
}
int ans = 0;
ch(ans, dp0[N - 1][0]);
ch(ans, dp1[N - 1][0]);
cout << ans << '\n';
}