結果
問題 | No.2964 Obstruction Bingo |
ユーザー | umimel |
提出日時 | 2024-11-16 17:25:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 499 ms / 2,468 ms |
コード長 | 4,108 bytes |
コンパイル時間 | 2,466 ms |
コンパイル使用メモリ | 178,792 KB |
実行使用メモリ | 209,664 KB |
最終ジャッジ日時 | 2024-11-16 17:25:49 |
合計ジャッジ時間 | 17,106 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 5 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 38 ms
20,224 KB |
testcase_06 | AC | 251 ms
101,760 KB |
testcase_07 | AC | 29 ms
14,720 KB |
testcase_08 | AC | 196 ms
89,344 KB |
testcase_09 | AC | 73 ms
33,408 KB |
testcase_10 | AC | 221 ms
99,200 KB |
testcase_11 | AC | 71 ms
36,224 KB |
testcase_12 | AC | 340 ms
153,216 KB |
testcase_13 | AC | 119 ms
51,328 KB |
testcase_14 | AC | 154 ms
67,584 KB |
testcase_15 | AC | 28 ms
14,464 KB |
testcase_16 | AC | 77 ms
36,480 KB |
testcase_17 | AC | 51 ms
25,216 KB |
testcase_18 | AC | 102 ms
46,208 KB |
testcase_19 | AC | 67 ms
34,432 KB |
testcase_20 | AC | 221 ms
100,352 KB |
testcase_21 | AC | 266 ms
121,600 KB |
testcase_22 | AC | 38 ms
20,736 KB |
testcase_23 | AC | 15 ms
9,856 KB |
testcase_24 | AC | 7 ms
5,888 KB |
testcase_25 | AC | 471 ms
209,536 KB |
testcase_26 | AC | 471 ms
209,536 KB |
testcase_27 | AC | 490 ms
209,536 KB |
testcase_28 | AC | 474 ms
209,536 KB |
testcase_29 | AC | 465 ms
209,664 KB |
testcase_30 | AC | 475 ms
209,536 KB |
testcase_31 | AC | 466 ms
209,536 KB |
testcase_32 | AC | 495 ms
209,536 KB |
testcase_33 | AC | 468 ms
209,536 KB |
testcase_34 | AC | 465 ms
209,664 KB |
testcase_35 | AC | 499 ms
209,536 KB |
testcase_36 | AC | 468 ms
209,664 KB |
testcase_37 | AC | 494 ms
209,536 KB |
testcase_38 | AC | 469 ms
209,536 KB |
testcase_39 | AC | 466 ms
209,536 KB |
testcase_40 | AC | 493 ms
209,536 KB |
testcase_41 | AC | 469 ms
209,664 KB |
testcase_42 | AC | 493 ms
209,536 KB |
testcase_43 | AC | 463 ms
209,536 KB |
testcase_44 | AC | 469 ms
209,664 KB |
testcase_45 | AC | 122 ms
56,576 KB |
testcase_46 | AC | 27 ms
17,280 KB |
testcase_47 | AC | 26 ms
17,280 KB |
testcase_48 | AC | 166 ms
72,064 KB |
testcase_49 | AC | 153 ms
68,096 KB |
testcase_50 | AC | 260 ms
119,168 KB |
testcase_51 | AC | 436 ms
201,728 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 2; template<long long mod> class modint{ long long x; public: modint(long long x=0) : x((x%mod+mod)%mod) {} modint operator-() const { return modint(-x); } bool operator==(const modint& a){ if(x == a) return true; else return false; } bool operator==(long long a){ if(x == a) return true; else return false; } bool operator!=(const modint& a){ if(x != a) return true; else return false; } bool operator!=(long long a){ if(x != a) return true; else return false; } modint& operator+=(const modint& a) { if ((x += a.x) >= mod) x -= mod; return *this; } modint& operator-=(const modint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } modint& operator*=(const modint& a) { (x *= a.x) %= mod; return *this; } modint operator+(const modint& a) const { modint res(*this); return res+=a; } modint operator-(const modint& a) const { modint res(*this); return res-=a; } modint operator*(const modint& a) const { modint res(*this); return res*=a; } modint pow(long long t) const { if (!t) return 1; modint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod modint inv() const { return pow(mod-2); } modint& operator/=(const modint& a) { return (*this) *= a.inv(); } modint operator/(const modint& a) const { modint res(*this); return res/=a; } friend std::istream& operator>>(std::istream& is, modint& m) noexcept { is >> m.x; m.x %= mod; if (m.x < 0) m.x += mod; return is; } friend ostream& operator<<(ostream& os, const modint& m){ os << m.x; return os; } }; using mint = modint<MOD998244353>; void solve(){ int L, K; cin >> L >> K; string s, t; cin >> s >> t; vector<int> a(26); mint sum = 0; for(int i=0; i<26; i++){ cin >> a[i]; sum += mint(a[i]); } vector<mint> p(26, 0); for(int i=0; i<26; i++) p[i] = mint(a[i])/sum; vector<vector<vector<mint>>> dp(K+1, vector<vector<mint>>(K+1, vector<mint>(2*L+1, 0))); dp[0][0][L] = 1; for(int i=0; i<K; i++){ for(int j=0; j<=i; j++){ for(int k=1; k<2*L; k++){ int PN = j; int PM = PN + (L - k); if(PM < 0 || i < PM) continue; // (PN, PM) if(s[PN%L] == t[PM%L]){ dp[i+1][PN][k] += dp[i][PN][k]*(mint(1) - p[s[PN%L]-'a']); }else{ dp[i+1][PN][k] += dp[i][PN][k]*(mint(1) - p[s[PN%L]-'a'] - p[t[PM%L]-'a']); } // (PN+1, PM) if(s[PN%L] != t[PM%L]){ dp[i+1][PN+1][k+1] += dp[i][PN][k]*p[s[PN%L]-'a']; } // (PN, PM+1) if(s[PN%L] != t[PM%L]){ dp[i+1][PN][k-1] += dp[i][PN][k]*p[t[PM%L]-'a']; } // (PN+1, PM+1) if(s[PN%L] == t[PM%L]){ dp[i+1][PN+1][k] += dp[i][PN][k]*p[t[PM%L]-'a']; } } } } mint X = 0, Y = 0; for(int i=1; i<=K; i++){ for(int j=0; j<=K; j++){ X += dp[i][j][2*L]; Y += dp[i][j][0]; } } cout << X << ' ' << Y << '\n'; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }