結果
問題 |
No.2231 Surprising Flash!
|
ユーザー |
|
提出日時 | 2023-05-11 18:59:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,706 bytes |
コンパイル時間 | 2,399 ms |
コンパイル使用メモリ | 115,428 KB |
最終ジャッジ日時 | 2025-02-12 21:23:32 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 32 WA * 12 |
ソースコード
#include <iostream> #include <atcoder/modint> #include <atcoder/convolution> using mint = atcoder::modint998244353; namespace atcoder { std::istream& operator>>(std::istream& in, mint& a) { long long e; in >> e; a = e; return in; } std::ostream& operator<<(std::ostream& out, const mint& a) { out << a.val(); return out; } } // namespace atcoder void solve() { int n, m; std::cin >> n >> m; std::string s, t; std::cin >> s >> t; std::reverse(s.begin(), s.end()); std::vector<mint> f0(n), f1(n), f2(n); std::vector<mint> g0(m), g1(m), g2(m); for (int i = 0; i < n; ++i) { f0[i] = (s[i] == '?') ? 0 : 1; f1[i] = f0[i] * s[i]; f2[i] = f1[i] * s[i]; } for (int j = 0; j < m; ++j) { g0[j] = 1; g1[j] = g0[j] * t[j]; g2[j] = g1[j] * t[j]; } std::vector<mint> h(n + m - 1); std::vector<mint> f2g0 = atcoder::convolution(f2, g0); std::vector<mint> f1g1 = atcoder::convolution(f1, g1); std::vector<mint> f0g2 = atcoder::convolution(f0, g2); for (int i = 0; i < n + m - 1; ++i) { h[i] += f2g0[i] - 2 * f1g1[i] + f0g2[i]; } for (int i = m - 1; i < n; ++i) { if (h[i] == 0) { for (int j = 0; j < m; ++j) { s[i - j] = t[j]; } std::replace(s.begin(), s.end(), '?', 'a'); std::reverse(s.begin(), s.end()); std::cout << s << '\n'; return; } } std::cout << -1 << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; std::cin >> t; while (t-- > 0) { solve(); } }