結果
問題 | No.2231 Surprising Flash! |
ユーザー | ikefumy |
提出日時 | 2023-02-24 23:42:17 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,676 bytes |
コンパイル時間 | 2,321 ms |
コンパイル使用メモリ | 208,156 KB |
実行使用メモリ | 14,660 KB |
最終ジャッジ日時 | 2024-09-13 08:19:28 |
合計ジャッジ時間 | 4,671 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 3 ms
6,940 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | AC | 3 ms
6,940 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | WA | - |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 19 ms
12,740 KB |
testcase_12 | AC | 24 ms
14,432 KB |
testcase_13 | WA | - |
testcase_14 | AC | 16 ms
11,624 KB |
testcase_15 | AC | 20 ms
12,748 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 15 ms
11,732 KB |
testcase_25 | AC | 17 ms
11,732 KB |
testcase_26 | AC | 16 ms
11,732 KB |
testcase_27 | AC | 16 ms
11,728 KB |
testcase_28 | WA | - |
testcase_29 | AC | 17 ms
12,832 KB |
testcase_30 | AC | 17 ms
12,744 KB |
testcase_31 | AC | 16 ms
12,744 KB |
testcase_32 | AC | 16 ms
12,684 KB |
testcase_33 | AC | 17 ms
12,736 KB |
testcase_34 | AC | 19 ms
12,588 KB |
testcase_35 | AC | 21 ms
12,616 KB |
testcase_36 | AC | 20 ms
12,800 KB |
testcase_37 | AC | 20 ms
12,740 KB |
testcase_38 | AC | 19 ms
12,796 KB |
testcase_39 | AC | 8 ms
6,944 KB |
testcase_40 | AC | 6 ms
6,940 KB |
testcase_41 | WA | - |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,944 KB |
testcase_44 | WA | - |
ソースコード
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define db double #define pii pair<int,int> #define pll pair<ll,ll> #define ti3 tuple<int,int,int> #define int128 __int128_t #define pii128 pair<int128,int128> const int inf = 1 << 30; const ll linf = 1e18; const ll mod = 1e9 + 7; const db EPS = 1e-10; const db pi = acos(-1); template<class T> bool chmin(T& x, T y){ if(x > y) { x = y; return true; } else return false; } template<class T> bool chmax(T& x, T y){ if(x < y) { x = y; return true; } else return false; } // overload macro #define CAT( A, B ) A ## B #define SELECT( NAME, NUM ) CAT( NAME, NUM ) #define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT #define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 ) #define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__) // rep(overload) #define rep( ... ) VA_SELECT(rep, __VA_ARGS__) #define rep2(i, n) for (decay_t<decltype(n)> i = 0; i < n; i++) #define rep3(i, a, b) for (decay_t<decltype(a)> i = a; i < b; i++) #define rep4(i, a, b, c) for (decay_t<decltype(a)> i = a; i < b; i += c) // rrep(overload) #define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__) #define rrep2(i, n) for (decay_t<decltype(n)> i = n - 1; i >= 0; i--) #define rrep3(i, a, b) for (decay_t<decltype(a)> i = b - 1; i >= a; i--) #define rrep4(i, a, b, c) for (decay_t<decltype(a)> i = b - 1; i >= a; i -= c) // for_earh #define fore(e, v) for (auto&& e : v) // vector #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() vector<int> Z_algorithm(string S, string T = "") { if (T == "") T = S; S += '$'; S += T; vector<int> Z(S.size()); Z[0] = S.size(); int i = 1, j = 0; while(i < (int)S.size()) { while(i + j < (int)S.size() && S[j] == S[i + j]) j++; Z[i] = j; if (j == 0) { i++; continue; } int k = 1; while (k < j && k + Z[k] < j) { Z[i + k] = Z[k]; k++; } i += k; j -= k; } vector<int> res(T.size()); copy(Z.end() - T.size(), Z.end(), res.begin()); return res; } vector<int> Z_algorithm_ques(string S, string T = "") { if (T == "") T = S; S += '$'; S += T; vector<int> Z(S.size()); Z[0] = S.size(); int i = 1, j = 0; while(i < (int)S.size()) { while(i + j < (int)S.size() && (S[j] == S[i + j] || S[j] == '?' || S[i + j] == '?')) j++; Z[i] = j; if (j == 0) { i++; continue; } int k = 1; while (k < j && k + Z[k] < j) { Z[i + k] = Z[k]; k++; } i += k; j -= k; } vector<int> res(T.size()); copy(Z.end() - T.size(), Z.end(), res.begin()); return res; } void solve() { int N, M; string S, T; cin >> N >> M >> S >> T; auto v1 = Z_algorithm(T, S); auto v2 = Z_algorithm_ques(T, S); rep (i, N) { if (v1[i] == M) { rep (i, N) if (S[i] == '?') S[i] = 'a'; cout << S << "\n"; return; } } rrep (i, N) { if (v2[i] >= M) { string ans = S.substr(0, i); ans += T; ans += S.substr(i + T.size()); rep (i, N) if (ans[i] == '?') ans[i] = 'a'; cout << ans << "\n"; return; } } cout << -1 << "\n"; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t; cin >> t; while (t--) solve(); return 0; }