結果

問題 No.2131 Concon Substrings (COuNt Version)
ユーザー norikamenorikame
提出日時 2022-11-25 22:02:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 800 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 4,481 ms
コンパイル使用メモリ 260,200 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 03:12:11
合計ジャッジ時間 10,127 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 369 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 795 ms
6,944 KB
testcase_08 AC 201 ms
6,944 KB
testcase_09 AC 791 ms
6,944 KB
testcase_10 AC 800 ms
6,944 KB
testcase_11 AC 553 ms
6,940 KB
testcase_12 AC 524 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 237 ms
6,944 KB
testcase_15 AC 190 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 165 ms
6,944 KB
testcase_18 AC 169 ms
6,944 KB
testcase_19 AC 85 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

#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;
}
0