結果

問題 No.2231 Surprising Flash!
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-10-06 12:35:05
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,749 bytes
コンパイル時間 5,447 ms
コンパイル使用メモリ 270,796 KB
実行使用メモリ 36,564 KB
最終ジャッジ日時 2024-07-26 15:22:36
合計ジャッジ時間 13,971 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define writejoin(s, a) rep(_i, 0, (a).size()) cout << (a)[_i] << (_i + 1 < (int)(a).size() ? s : "\n");
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using mint = modint998244353;
using vm = vector<mint>;

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    string s1, s2;
    cin >> s1 >> s2;

    vm a1(n), a2(n), a3(n);
    rep(i, 0, n) {
      int c = s1[i] == '?' ? 0 : s1[i] - 'a' + 1;
      a1[i] = c;
      a2[i] = c * c;
      a3[i] = c * c * c;
    }
    vm b0(m, 1), b1(m), b2(m);
    rep(i, 0, m) {
      int c = s2[m - 1 - i] - 'a' + 1;
      b0[i] = 1;
      b1[i] = c;
      b2[i] = c * c;
    }

    auto c1 = convolution(a1, b2);
    auto c2 = convolution(a2, b1);
    auto c3 = convolution(a3, b0);
    vm c0(n + m - 1);
    rep(i, 0, n + m - 1) c0[i] = c1[i] - 2 * c2[i] + c3[i];
    int ans = -1;
    rep(k, 0, n - m + 1) {
      if (c0[m - 1 + k] == 0) ans = k;
    }
    if (ans == -1) {
      cout << -1 << "\n";
    } else {
      rep(i, 0, m) s1[i + ans] = s2[i];
      rep(i, 0, n) cout << (s1[i] == '?' ? 'a' : s1[i]);
      cout << "\n";
    }
  }
}
0