結果
| 問題 |
No.2131 Concon Substrings (COuNt Version)
|
| コンテスト | |
| ユーザー |
norikame
|
| 提出日時 | 2022-11-25 22:02:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 543 ms / 2,000 ms |
| コード長 | 1,160 bytes |
| コンパイル時間 | 3,400 ms |
| コンパイル使用メモリ | 256,732 KB |
| 最終ジャッジ日時 | 2025-02-09 00:13:38 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
//
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()
const ll mod = 998244353LL;
const string tar = "con";
int main() {
int n, m;
cin >> n;
m = (n+2) / 3;
vector<vector<ll>> dp(m+1, vector<ll>(3)), ndp;
dp[0][2] = 1;
rep(i, n) {
ndp.assign(m+1, vector<ll>(3));
rep(j, 26) {
char tc = (char)('a'+j);
size_t cid = tar.find(tc);
rep(i2, m+1) rep(j2, 3) {
int i1 = i2, j1 = j2;
if (cid != string::npos) {
if (cid>=1U && j2+1==(int)(cid)) ++j1;
else if (cid==0U && j2==2) ++i1, j1 = 0;
}
if (i1 > m) continue;
ndp[i1][j1] = (ndp[i1][j1] + dp[i2][j2]) % mod;
}
}
swap(ndp, dp);
}
ll res = 0;
rep3(i, 1, m+1) rep(j, 3) {
if (j < 2) res = (res + dp[i][j] * (i-1) % mod) % mod;
else res = (res + dp[i][j] * i % mod) % mod;
}
cout << res << endl;
return 0;
}
norikame