結果

問題 No.2964 Obstruction Bingo
ユーザー kwm_t
提出日時 2024-11-16 16:50:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,901 bytes
コンパイル時間 6,035 ms
コンパイル使用メモリ 321,956 KB
実行使用メモリ 1,556,864 KB
最終ジャッジ日時 2024-11-16 16:51:24
合計ジャッジ時間 65,479 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 TLE * 3 MLE * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
using mint = modint998244353;
const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r) - 1;i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int l, k; cin >> l >> k;
	string s0, s1; cin >> s0 >> s1;
	vector<mint>p(26);
	{
		vector<int>a(26);
		mint sum = 0;
		rep(i, 26)cin >> a[i], sum += a[i];
		rep(i, 26)p[i] = a[i] / sum;
	}
	vector dp(k + 1, vector(k + 1, vector<pair<mint, mint>>(k + 1, {0,0})));
	vector chk(k + 1, vector(k + 1, vector<bool>(k + 1, 0)));
	auto dfs = [&](auto &&self, int t, int p0, int p1)->pair<mint, mint> {
		if (chk[t][p0][p1]) {
			return dp[t][p0][p1];
		}
		if (l == abs(p0 - p1)) {
			if (p0 > p1)return { 1,0 };
			else if (p0 < p1)return { 0,1 };
			else return { 0,0 };
		}
		if (t == k) {
			return { 0,0 };
		}
		mint v0 = 0, v1 = 0;
		rep(i, 26) {
			int nt = t + 1;
			int np0 = p0 + (i == ((s0[p0%l]) - 'a'));
			int np1 = p1 + (i == ((s1[p1%l]) - 'a'));
			auto get = self(self, nt, np0, np1);
			v0 += get.first * p[i];
			v1 += get.second * p[i];
		}
		chk[t][p0][p1] = true;
		return dp[t][p0][p1] = { v0,v1 };
	};
	auto ans = dfs(dfs, 0, 0, 0);
	cout << ans.first.val() << " " << ans.second.val() << endl;
	return 0;
}
0