Submission #771486

# Submission time Handle Problem Language Result Execution time Memory
771486 2023-07-03T04:35:24 Z Blistering_Barnacles Necklace (Subtask 1-3) (BOI19_necklace1) C++11
85 / 85
350 ms 225536 KB
//Billions of bilious blue blistering barnacles in a thundering typhoon!
#ifndef LOCAL
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#pragma GCC target("avx2,fma")
#endif
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0) , cin.tie(0)
#define F first
#define S second
#define pb push_back
#define vll vector< ll >
#define vi vector< int >
#define pll pair< ll , ll >
#define pi pair< int , int >
#define all(s) s.begin() , s.end()
#define sz(s) s.size()
#define str string
#define md ((s + e) / 2)
#define mid ((l + r) / 2)
#define msdp(dp) memset(dp , -1 , sizeof dp)
#define mscl(dp) memset(dp , 0 , sizeof dp)
#define C continue
#define R return
#define B break
#define lx node * 2
#define rx node * 2 + 1
#define br(dosomething) {dosomething; break;}
#define co(dosomething) {dosomething ; continue;}
using namespace std;
typedef long long ll;
ll q, a[555555] , b[555555] , dp[555555] , k, l, m, n, o, p;
map < ll , ll > mp ;
vll adj[555555];
const ll mod = 1e9+7;
ll Lss[3005][3005] , Lsp[3005][3005] , Lps[3005][3005] ;
str s , t ; 
void solve(){
    cin >> s >> t ; 
    n = sz(s) , m = sz(t) ; 
    reverse(all(t)) ; 
    str op = t ; 
    s = ' ' + s , t = ' ' + t ; 
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            Lss[i][j] = (s[i] == t[j] ? 1 + Lss[i - 1][j - 1] : 0) ;
        }
    }
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            if(!Lss[i][j])C ; 
            Lsp[i][j - Lss[i][j] + 1] = max(Lsp[i][j - Lss[i][j] + 1] , Lss[i][j]) ; 
        }
    }
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            if(!Lss[i][j])C ;
            Lps[i - Lss[i][j] + 1][j] = max(Lps[i - Lss[i][j] + 1][j] , Lss[i][j]) ; 
        }
    }
    pair < ll , pll > ans = {0 , {0 , 0}} ; 
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            Lsp[i][j] = max(Lsp[i][j] , Lsp[i][j - 1] - 1) ; 
            Lps[i][j] = max(Lps[i][j] , Lps[i - 1][j] - 1) ;
        }
    }
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            ans = max(ans , {Lsp[i][j] + Lps[i + 1][j - 1] , {i - Lsp[i][j] , m - j - Lsp[i][j] + 1}}) ;
        }
    }
    reverse(all(op)) ; 
    t = op ; 
    t = ' ' + t ; 
    mscl(Lss) , mscl(Lsp) , mscl(Lps) ; 
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            Lss[i][j] = (s[i] == t[j] ? 1 + Lss[i - 1][j - 1] : 0) ;
        }
    }
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            if(!Lss[i][j])C ; 
            Lsp[i][j - Lss[i][j] + 1] = max(Lsp[i][j - Lss[i][j] + 1] , Lss[i][j]) ; 
        }
    }
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            if(!Lss[i][j])C ;
            Lps[i - Lss[i][j] + 1][j] = max(Lps[i - Lss[i][j] + 1][j] , Lss[i][j]) ; 
        }
    }
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            Lsp[i][j] = max(Lsp[i][j] , Lsp[i][j - 1] - 1) ; 
            Lps[i][j] = max(Lps[i][j] , Lps[i - 1][j] - 1) ;
        }
    }
    for(ll i = 1 ; i <= n ; i++){
        for(ll j = 1 ; j <= m ; j++){
            ans = max(ans , {Lsp[i][j] + Lps[i + 1][j - 1] , {i - Lsp[i][j] , j - Lps[i + 1][j - 1] - 1}}) ;
        }
    }
    cout << ans.F << endl << ans.S.F << " "  << ans.S.S << endl ; 
}
int main(){
    fast ;
    q = 1 ;
    //cin >> q ;
    while(q--){
        solve() ;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 81 ms 225356 KB Output is correct
2 Correct 75 ms 225336 KB Output is correct
3 Correct 81 ms 225376 KB Output is correct
4 Correct 77 ms 225296 KB Output is correct
5 Correct 78 ms 225356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 225356 KB Output is correct
2 Correct 75 ms 225336 KB Output is correct
3 Correct 81 ms 225376 KB Output is correct
4 Correct 77 ms 225296 KB Output is correct
5 Correct 78 ms 225356 KB Output is correct
6 Correct 81 ms 225304 KB Output is correct
7 Correct 84 ms 225340 KB Output is correct
8 Correct 80 ms 225336 KB Output is correct
9 Correct 80 ms 225324 KB Output is correct
10 Correct 79 ms 225364 KB Output is correct
11 Correct 79 ms 225324 KB Output is correct
12 Correct 79 ms 225328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 225356 KB Output is correct
2 Correct 75 ms 225336 KB Output is correct
3 Correct 81 ms 225376 KB Output is correct
4 Correct 77 ms 225296 KB Output is correct
5 Correct 78 ms 225356 KB Output is correct
6 Correct 81 ms 225304 KB Output is correct
7 Correct 84 ms 225340 KB Output is correct
8 Correct 80 ms 225336 KB Output is correct
9 Correct 80 ms 225324 KB Output is correct
10 Correct 79 ms 225364 KB Output is correct
11 Correct 79 ms 225324 KB Output is correct
12 Correct 79 ms 225328 KB Output is correct
13 Correct 271 ms 225380 KB Output is correct
14 Correct 250 ms 225364 KB Output is correct
15 Correct 282 ms 225380 KB Output is correct
16 Correct 258 ms 225360 KB Output is correct
17 Correct 350 ms 225432 KB Output is correct
18 Correct 248 ms 225356 KB Output is correct
19 Correct 255 ms 225516 KB Output is correct
20 Correct 306 ms 225320 KB Output is correct
21 Correct 280 ms 225536 KB Output is correct