제출 #1209484

#제출 시각아이디문제언어결과실행 시간메모리
1209484Theo830Necklace (Subtask 1-3) (BOI19_necklace1)C++20
9 / 85
1397 ms1114112 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
int main(void){
    string a,b;
    cin>>a>>b;
    ll ans = 0;
    ll x,y;
    ll l = 1,r = min(a.size(),b.size());
    while(l <= r){
        ll mid = (l+r)/2;
        ll len = mid;
        map<string,ll>mp;
        f(i,0,a.size()-len+1){
            string k = a.substr(i,len);
            f(j,0,len){
                char c = k.back();
                k.pop_back();
                k = c + k;
                mp[k] = i;
            }
            reverse(all(k));
            f(j,0,len){
                char c = k.back();
                k.pop_back();
                k = c + k;
                mp[k] = i;
            }
        }
        bool ok = 0;
        f(j,0,b.size()-len+1){
            string s = b.substr(j,len);
            if(mp.count(s)){
                ans = len;
                x = mp[s];
                y = j;
                ok = 1;
                break;
            }
        }
        if(ok){
            l = mid + 1;
        }
        else{
            r = mid - 1;
        }
    }
    cout<<ans<<"\n";
    cout<<x<<" "<<y<<"\n";
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...