結果
問題 | No.2231 Surprising Flash! |
ユーザー | Kude |
提出日時 | 2023-02-24 23:23:39 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,568 bytes |
コンパイル時間 | 4,589 ms |
コンパイル使用メモリ | 275,192 KB |
実行使用メモリ | 131,208 KB |
最終ジャッジ日時 | 2024-09-13 08:17:08 |
合計ジャッジ時間 | 30,062 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 27 ms
6,940 KB |
testcase_03 | AC | 181 ms
6,940 KB |
testcase_04 | AC | 16 ms
6,940 KB |
testcase_05 | AC | 40 ms
6,944 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 14 ms
6,944 KB |
testcase_09 | AC | 1 ms
6,944 KB |
testcase_10 | AC | 12 ms
6,944 KB |
testcase_11 | AC | 774 ms
100,012 KB |
testcase_12 | AC | 819 ms
129,188 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 768 ms
99,888 KB |
testcase_16 | AC | 785 ms
7,656 KB |
testcase_17 | AC | 812 ms
12,376 KB |
testcase_18 | AC | 786 ms
83,852 KB |
testcase_19 | AC | 790 ms
83,760 KB |
testcase_20 | AC | 796 ms
83,732 KB |
testcase_21 | AC | 793 ms
83,920 KB |
testcase_22 | AC | 798 ms
83,792 KB |
testcase_23 | AC | 813 ms
83,732 KB |
testcase_24 | AC | 814 ms
83,644 KB |
testcase_25 | AC | 795 ms
83,792 KB |
testcase_26 | AC | 791 ms
83,744 KB |
testcase_27 | AC | 790 ms
83,788 KB |
testcase_28 | AC | 787 ms
83,672 KB |
testcase_29 | AC | 824 ms
98,272 KB |
testcase_30 | AC | 831 ms
98,412 KB |
testcase_31 | AC | 820 ms
98,368 KB |
testcase_32 | AC | 828 ms
98,276 KB |
testcase_33 | AC | 830 ms
98,432 KB |
testcase_34 | AC | 772 ms
100,084 KB |
testcase_35 | AC | 771 ms
99,936 KB |
testcase_36 | AC | 764 ms
99,988 KB |
testcase_37 | AC | 769 ms
100,024 KB |
testcase_38 | AC | 767 ms
99,984 KB |
testcase_39 | AC | 356 ms
11,812 KB |
testcase_40 | AC | 253 ms
11,640 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,944 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | WA | - |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; template <class S, S (*op)(S, S)> struct DisjointSparseTable { const int n; const vector<unsigned char> msb; const vector<vector<S>> d; DisjointSparseTable(vector<S> a) : n(a.size()), msb(build_msb_table(n)), d(build_table(move(a))) {} vector<unsigned char> build_msb_table(int n) { if (n <= 1) return {}; unsigned char k_max = 32 - __builtin_clz(n - 1); vector<unsigned char> res(1 << k_max); unsigned char* p = res.data(); for (unsigned char k = 0; k < k_max; k++) { memset(p + (1U << k), k, 1U << k); } return res; } vector<vector<S>> build_table(vector<S> a) { const int n = a.size(); vector<vector<S>> res(1); if (n >= 2) { const int i_max = n - 1, k_max = 32 - __builtin_clz(i_max); res.resize(k_max); for (int k = 1; k < k_max; k++) { vector<S> t(i_max >> k & 1 ? n : i_max & ~0U << k); for (int c = 1 << k; c < n; c += 1 << (k + 1)) { int l = c - (1 << k); int r = min(n, c + (1 << k)); t[c - 1] = a[c - 1]; for (int i = c - 2; i >= l; i--) t[i] = op(a[i], t[i + 1]); t[c] = a[c]; for (int i = c + 1; i < r; i++) t[i] = op(t[i - 1], a[i]); } res[k] = move(t); } } res[0] = move(a); return res; } S query(int l, int r) { return query_closed(l, r - 1); } S query_closed(int l, int r) { assert(0 <= l && l <= r && r < n); if (l == r) return d[0][l]; auto k = msb[l ^ r]; return op(d[k][l], d[k][r]); } }; int op(int x, int y) { return min(x, y); } } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while(tt--) { int n, m; cin >> n >> m; string s, t; cin >> s >> t; reverse(all(t)); VL a(n), b(m); rep(i, n) a[i] = s[i] == '?' ? 0 : s[i] - 'a' + 1; rep(j, m) b[j] = t[j] - 'a' + 1; VL a2(n), b2(m); rep(i, n) a2[i] = a[i] * a[i]; rep(j, m) b2[j] = b[j] * b[j]; VL f1 = convolution_ll(a2, b); VL f2 = convolution_ll(a, b2); VL s3(n + 1); rep(i, n) s3[i + 1] = s3[i] + a[i] * a[i] * a[i]; vector<char> d(n); rep(i, n - m + 1) { int p = m - 1 + i; ll x = s3[i + m] - s3[i] - 2 * f1[p] + f2[p]; d[i] = x == 0; } reverse(all(t)); rep(i, n) if (s[i] == '?') s[i] = 'a'; string st = s + '$' + t; int nm = n + m + 1; assert(st.size() == nm); VI sa = suffix_array(st); VI sa_inv(nm); for (int i = 0; i < nm; i++) sa_inv[sa[i]] = i; DisjointSparseTable<int, op> dst(lcp_array(st, sa)); auto lcp = [&](int i, int j) { if (i == j) return n - i; int pi = sa_inv[i], pj = sa_inv[j]; if (pi > pj) swap(pi, pj); return dst.query(pi, pj); }; VI idx; rep(i, n) if (d[i]) idx.emplace_back(i); if (idx.empty()) { cout << -1 << '\n'; continue; } auto cmp_sub = [&](int i, int j) { assert(i < j); // s[n+1, n+m+1) + s[i+m, j+m) // s[i, j) + s[n+1, n+m+1) int pos1[2]{n + 1, i + m}; int len1[2]{m, j - i}; int pos2[2]{i, n + 1}; int len2[2]{j - i, m}; int p1 = 0, p2 = 0; int l1 = 0, l2 = 0; while(p1 != 2) { int l = lcp(pos1[p1] + l1, pos2[p2] + l2); if (l1 + l < len1[p1] && l2 + l < len2[p2]) { int q1 = pos1[p1] + l1 + l; int q2 = pos2[p2] + l2 + l; return st[q1] < st[q2] ? -1 : 1; } l1 += l; l2 += l; if (l1 >= len1[p1]) p1++, l1 = 0; if (l2 >= len2[p2]) p2++, l2 = 0; } return 0; }; int i0 = *min_element(all(idx), [&](int i, int j) { bool flip = i > j; if (flip) swap(i, j); int res = cmp_sub(i, j); if (flip) res = -res; return res < 0; }); rep(j, m) s[i0 + j] = t[j]; cout << s << '\n'; } }