# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
592383 | starchan | Laugh Analysis (IOI16_laugh) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "laugh.h"
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
string life;
struct fieldtype
{
int pref, suff, len, sub;
};
fieldtype value(int l, int r)
{
fieldtype val;
int m = (l+r)/2;
if(l==r)
{
if(life[m] == 'a' || life[m] == 'h')
{
val.pref = 1;
val.suff = 1;
val.len = 1;
val.sub = 1;
}
else
{
val.pref = 0;
val.suff = 0;
val.len = 1;
val.sub = 0;
}
return val;
}
fieldtype d1 = value(l, m);
fieldtype d2 = value(m+1, r);
val.pref = max(d1.pref, ((d1.pref==d1.len) && (life[m]!=life[m+1]))*(d1.len+d2.pref));
val.suff = max(d2.suff, ((d2.suff==d2.len) && (life[m]!=life[m+1]))*(d2.len+d1.suff));
val.len = d1.len+d2.len;
val.sub = max({d1.sub, d2.sub, (life[m]!=life[m+1])*(d1.suff+d2.pref)});
return val;
}
int longest_laugh(string s)
{
life = s;
return value(0, life.length()-1).sub;
}