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;
const int inf = 1e8;
int longest_laugh(std::string s)
{
int n = (int) s.size();
vector<vector<int>> dp(n, vector<int>(2, -inf));
if (s[0] == 'a') dp[0][0] = 1;
else if (s[0] == 'h') dp[0][1] = 1;
for (int i = 1; i < (int) s.size(); ++i) {
if (s[i] == 'a') {
dp[i][0] = max(1, dp[i - 1][1] + 1);
} else if (s[i] == 'h') {
dp[i][1] = max(1, dp[i - 1][0] + 1);
}
}
int mx = 0;
for (int i = 0; i < n; ++i) {
mx = max(mx, max(dp[i][0], dp[i][1]));
}
return mx;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |