This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* Simple
*
* Time Complexity: O(n)
* Implementation 1
*/
#include <bits/stdc++.h>
#include "laugh.h"
const int INF = 0x3f3f3f;
int longest_laugh(std::string s) {
int n = s.length();
std::vector<int> dp(n);
dp[0] = (s[0] == 'a' || s[0] == 'h');
for (int k = 1; k < n; k++) {
if (s[k] == 'a' || s[k] == 'h') {
dp[k] = 1 + (s[k] != s[k - 1]) * dp[k - 1];
} else {
dp[k] = 0;
}
}
int ans = -INF;
for (int i = 0; i < n; i++)
ans = std::max(ans, dp[i]);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |