제출 #688424

#제출 시각아이디문제언어결과실행 시간메모리
688424stanislavpolynNecklace (Subtask 1-3) (BOI19_necklace1)C++17
5 / 85
1562 ms332 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...