#include <bits/stdc++.h>
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()
using namespace std;
mt19937_64 rng(228);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key
template <typename T>
bool umn(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
const int M = 3005 * 3005;
string a, b;
ve<int> ord;
bool ask(string s, bool print = 0) {
fr (i, 0, sz(b) - sz(s)) {
if (b.substr(i, sz(s)) == s) {
if (print) {
cout << i << "\n";
}
return 1;
}
}
return 0;
}
bool possible(int len, bool print = 0) {
fr (i, 0, sz(a) - len) {
fr (shift, 0, len - 1){
string s = a.substr(i + shift, len - shift) + a.substr(i, shift);
if (ask(s)) {
if (print) {
cout << i << " ";
ask(s, 1);
}
return 1;
}
reverse(all(s));
if (ask(s)) {
if (print) {
cout << i << " ";
ask(s, 1);
}
return 1;
}
}
}
return 0;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
ios::sync_with_stdio(0);
cin.tie(0);
#endif
cin >> a >> b;
{
fr (i, 0, sz(b) - 1) {
ord.pb(i);
}
sort(all(ord), [](int i, int j) {
while (i < sz(b) && j < sz(b) && b[i] == b[j]) {
i++;
j++;
}
if (i == sz(b) && j < sz(b)) {
return 1;
}
if (i < sz(b) && j < sz(b) && b[i] < b[j]) {
return 1;
}
return 0;
});
}
int l = 0;
int r = min(sz(a), sz(b));
while (l < r) {
int mid = l + ((r - l + 1) >> 1);
if (possible(mid)) {
l = mid;
} else {
r = mid - 1;
}
}
cout << l << "\n";
possible(l, 1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
332 KB |
Output is correct |
2 |
Partially correct |
9 ms |
332 KB |
Output is partially correct |
3 |
Correct |
28 ms |
212 KB |
Output is correct |
4 |
Partially correct |
37 ms |
212 KB |
Output is partially correct |
5 |
Correct |
25 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
332 KB |
Output is correct |
2 |
Partially correct |
9 ms |
332 KB |
Output is partially correct |
3 |
Correct |
28 ms |
212 KB |
Output is correct |
4 |
Partially correct |
37 ms |
212 KB |
Output is partially correct |
5 |
Correct |
25 ms |
332 KB |
Output is correct |
6 |
Correct |
332 ms |
332 KB |
Output is correct |
7 |
Partially correct |
1328 ms |
328 KB |
Output is partially correct |
8 |
Execution timed out |
1562 ms |
212 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
332 KB |
Output is correct |
2 |
Partially correct |
9 ms |
332 KB |
Output is partially correct |
3 |
Correct |
28 ms |
212 KB |
Output is correct |
4 |
Partially correct |
37 ms |
212 KB |
Output is partially correct |
5 |
Correct |
25 ms |
332 KB |
Output is correct |
6 |
Correct |
332 ms |
332 KB |
Output is correct |
7 |
Partially correct |
1328 ms |
328 KB |
Output is partially correct |
8 |
Execution timed out |
1562 ms |
212 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |