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 "laugh.h"
#include <bits/stdc++.h>
using namespace std;
int longest_laugh(string S)
{
int N = S.size();
S = '-' + S;
vector<int> dp(N + 1 , 0);
for (int i = 1;i <= N;i ++) {
if (S[i] == 'a' || S[i] == 'h') {
dp[i] = 1;
} else {
dp[i] = 0;
}
if (S[i] == 'a' && S[i - 1] == 'h') {
dp[i] += dp[i - 1];
} else if (S[i] == 'h' && S[i - 1] == 'a') {
dp[i] += dp[i - 1];
}
}
int eded = *max_element(dp.begin() , dp.end());
return (eded == 1 ? 0 : eded);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |