#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]);
return 0;
}
return 0;
}
Compilation message
retro.c: In function 'main':
retro.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
retro.c:18:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%s", s);
| ^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
Unexpected end of file - token expected |
2 |
Incorrect |
1 ms |
204 KB |
Unexpected end of file - token expected |
3 |
Incorrect |
0 ms |
280 KB |
Unexpected end of file - token expected |
4 |
Incorrect |
1 ms |
332 KB |
Unexpected end of file - token expected |
5 |
Incorrect |
1 ms |
460 KB |
Unexpected end of file - token expected |
6 |
Incorrect |
2 ms |
332 KB |
Unexpected end of file - token expected |
7 |
Incorrect |
6 ms |
460 KB |
Unexpected end of file - token expected |
8 |
Incorrect |
4 ms |
276 KB |
Unexpected end of file - token expected |
9 |
Incorrect |
9 ms |
416 KB |
Unexpected end of file - token expected |
10 |
Incorrect |
5 ms |
460 KB |
Unexpected end of file - token expected |
11 |
Incorrect |
105 ms |
972 KB |
Unexpected end of file - token expected |
12 |
Incorrect |
98 ms |
1020 KB |
Unexpected end of file - token expected |
13 |
Incorrect |
51 ms |
588 KB |
Unexpected end of file - token expected |
14 |
Incorrect |
108 ms |
588 KB |
Unexpected end of file - token expected |
15 |
Incorrect |
120 ms |
1044 KB |
Unexpected end of file - token expected |
16 |
Incorrect |
113 ms |
972 KB |
Unexpected end of file - token expected |
17 |
Incorrect |
99 ms |
920 KB |
Unexpected end of file - token expected |
18 |
Incorrect |
94 ms |
916 KB |
Unexpected end of file - token expected |
19 |
Incorrect |
118 ms |
1104 KB |
Unexpected end of file - token expected |
20 |
Incorrect |
113 ms |
984 KB |
Unexpected end of file - token expected |