Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- // Debugging macros
- #define TRACE(x)
- #define WATCH(x) TRACE( cout << #x" = " << x << endl)
- #define PRINT(x) TRACE(printf(x))
- #define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
- #define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
- // End of Debugging macros
- // Macros for faster typing
- #define all(v) (v).begin(), (v).end()
- #define rall(v) (v).rbegin(), (v).rend()
- #define sz(v) (int) (v).size()
- #define rep(i,a,b) for(int (i) = (a); (i) < (b); ++(i))
- #define pb push_back
- using ll = long long;
- using vi = vector<int>;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- // End of macros for faster typing
- constexpr int inf = 0x3f3f3f3f;
- constexpr ll MOD = 1000000007LL;
- constexpr double tol = 1e-8;
- inline ll powmod( ll a, ll b, ll mod = MOD) {
- ll res = 1; a %= mod; assert(b >= 0);
- for(;b;b>>=1) {
- if(b&1) res = (res * a) % mod;
- a = (a * a) % mod;
- }
- return res;
- }
- mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
- constexpr int ms = 2e5 + 13;
- vector< int > pref[ms], suff[ms];
- int main() {
- ios::sync_with_stdio(0);cin.tie(NULL);
- // obs, vai sempre ser um prefixo ou um sufixo
- string s, t;
- cin >> s >> t;
- int len_s = sz(s), len_t = sz(t);
- vector< int > tam_pref(len_s);
- vector< int > tam_suff(len_s);
- int cur_idx = 0;
- for(int i = 0; i < len_s; ++i) {
- if( cur_idx == len_t ) tam_pref[i] = len_t;
- else {
- if(s[i] == t[cur_idx]) ++cur_idx;
- tam_pref[i] = cur_idx;
- }
- }
- cur_idx = len_t - 1;
- for(int i = len_s - 1; i >= 0; --i) {
- if( cur_idx == -1 ) tam_suff[i] = len_t;
- else {
- if( s[i] == t[cur_idx]) --cur_idx;
- tam_suff[i] = len_t - cur_idx - 1;
- }
- }
- int ans = 0;
- for(int i = 0; i < len_s; ++i)
- {
- pref[ tam_pref[i] ].push_back(i);
- suff[ tam_suff[i] ].push_back(i);
- if( tam_pref[i] == len_t ) ans = max( ans, len_s - 1 - i);
- if( tam_suff[i] == len_t ) ans = max( ans, i );
- }
- WATCHC( tam_pref );
- WATCHC( tam_suff );
- // agora tem os casos interessantes que tem que quebrar no meio
- for(int i = 0; i < len_s; ++i)
- {
- int good_pref = tam_pref[i];
- if( good_pref == len_t ) continue;
- int need = len_t - good_pref;
- int L = suff[need].back();
- if( L > i )
- {
- int cut = L - i - 1;
- ans = max( cut, ans );
- }
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement