# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471545 | rainboy | Retro (COCI17_retro) | C11 | 97 ms | 1092 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 <stdio.h>
#define N 300
#define M 300
int max(int a, int b) { return a > b ? a : b; }
int main() {
static char s[M + 1];
static int dp[M][N], dq[M][N];
int n, m, i, j, d, d_;
scanf("%d%d", &n, &m);
for (j = 0; j < m; j++)
for (d = 0; d < n; d++)
dp[j][d] = d == 0 ? 0 : -1;
for (i = 0; i < n; i++) {
scanf("%s", s);
for (j = 0; j < m; j++)
for (d = 0; d < n; d++) {
if (s[j] == '*')
dq[j][d] = d == 0 ? 0 : -1;
else {
d_ = s[j] == '.' || s[j] == 'M' ? d : (s[j] == '(' ? d + 1 : d - 1);
dq[j][d] = -1;
if (d_ >= 0 && d_ < n) {
dq[j][d] = dp[j][d_];
if (j > 0 && dp[j - 1][d_] != -1)
dq[j][d] = max(dq[j][d], dp[j - 1][d_]);
if (j + 1 < m && dp[j + 1][d_] != -1)
dq[j][d] = max(dq[j][d], dp[j + 1][d_]);
}
if (dq[j][d] != -1 && s[j] != '.' && s[j] != 'M')
dq[j][d]++;
}
}
for (j = 0; j < m; j++)
for (d = 0; d < n; d++)
dp[j][d] = dq[j][d];
}
for (j = 0; j < m; j++)
if (s[j] == 'M') {
printf("%d\n", dp[j][0]);
for (i = 0; i < dp[j][0] / 2; i++)
printf("()");
printf("\n");
return 0;
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |