# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
879719 | leastmerryfish | Round words (IZhO13_rowords) | C++17 | 88 ms | 125588 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>
using namespace std;
const int mx = 4004;
int dp[mx][mx], dir[mx][mx], n, m;
string a, b;
int solve() {
int x, ans = 0;
for (int i = 0; i <= n * 2; i++)
for (int j = 0; j <= m; j++) {
if (i == 0 && j == 0) dp[i][j] = 0, dir[i][j] = -1;
else {
dp[i][j] = dir[i][j] = -1;
if (j > 0 && dp[i][j] < (x = dp[i][j - 1]))
dp[i][j] = x, dir[i][j] = 0;
if (i > 0 && j > 0 && a[(i - 1) % n] == b[j - 1] && dp[i][j] < (x = dp[i - 1][j - 1] + 1))
dp[i][j] = x, dir[i][j] = 1;
if (i > 0 && dp[i][j] < (x = dp[i - 1][j]))
dp[i][j] = x, dir[i][j] = 2;
}
}
for (int k=0; k<n; k++) {
int i = n + k, j = m;
x = 0;
while (dir[i][j] != -1) {
if (dir[i][j] == 0) j--;
else if (dir[i][j] == 1) i--, j--, x++;
else i--;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |