結果
問題 | No.2964 Obstruction Bingo |
ユーザー |
![]() |
提出日時 | 2024-11-16 17:19:09 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,932 bytes |
コンパイル時間 | 6,191 ms |
コンパイル使用メモリ | 318,032 KB |
実行使用メモリ | 816,292 KB |
最終ジャッジ日時 | 2024-11-16 17:20:18 |
合計ジャッジ時間 | 66,849 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | MLE * 3 |
other | MLE * 49 |
ソースコード
#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; } bool chk[501][101][50][50]; pair<mint, mint> dp[501][101][50][50]; 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(l * 2 + 1, vector(l, vector<pair<mint, mint>>(l))); vector ndp(l * 2 + 1, vector(l, vector<pair<mint, mint>>(l))); rrep(_, k) { rep(i, l * 2 + 1)rep(j, l)rep(k, l) ndp[i][j][k] = { 0,0 }; rep2(i, 1, l * 2)rep(j, l)rep(k, l) { rep(a, 26) { int ni = i, nj = j, nk = k; if (a == ((s0[j%l]) - 'a')) { ni++; nj++; } if (a == ((s1[k%l]) - 'a')) { ni--; nk++; } nj %= l; nk %= l; if (0 == ni) ndp[i][j][k].second += p[a]; else if (2 * l == ni) ndp[i][j][k].first += p[a]; else { ndp[i][j][k].first += dp[ni][nj][nk].first * p[a]; ndp[i][j][k].second += dp[ni][nj][nk].second * p[a]; } } } swap(dp, ndp); } auto ans = dp[l][0][0]; cout << ans.first.val() << " " << ans.second.val() << endl; return 0; }