답안 #471545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
471545 2021-09-09T17:18:04 Z rainboy Retro (COCI17_retro) C
40 / 100
97 ms 1092 KB
#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

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 Partially correct 1 ms 204 KB Partially correct
2 Partially correct 0 ms 332 KB Partially correct
3 Partially correct 0 ms 280 KB Partially correct
4 Partially correct 0 ms 332 KB Partially correct
5 Partially correct 1 ms 460 KB Partially correct
6 Partially correct 2 ms 416 KB Partially correct
7 Partially correct 3 ms 468 KB Partially correct
8 Partially correct 2 ms 344 KB Partially correct
9 Partially correct 3 ms 344 KB Partially correct
10 Partially correct 6 ms 472 KB Partially correct
11 Partially correct 88 ms 1092 KB Partially correct
12 Partially correct 82 ms 976 KB Partially correct
13 Partially correct 39 ms 464 KB Partially correct
14 Partially correct 44 ms 472 KB Partially correct
15 Partially correct 97 ms 984 KB Partially correct
16 Partially correct 92 ms 976 KB Partially correct
17 Partially correct 83 ms 864 KB Partially correct
18 Partially correct 76 ms 860 KB Partially correct
19 Partially correct 97 ms 848 KB Partially correct
20 Partially correct 91 ms 964 KB Partially correct