답안 #635291

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635291 2022-08-25T22:49:59 Z racsosabe Retro (COCI17_retro) C++14
0 / 100
203 ms 98444 KB
#include<bits/stdc++.h>
using namespace::std;

const int N = 300 + 5;
const int inf = 1e9;

int n;
int m;
char s[N][N];
bool vis[N][N][N];
int memo[N][N][N];
int choice[N][N][N];

bool check_bomb(int i, int j){
	return s[i - 1][j] == '*' or (j and s[i - 1][j - 1] == '*') or (j + 1 < m and s[i - 1][j + 1] == '*');
}

int DP(int i, int j, int prefix){
	if(i == 0) return prefix == 0 ? 0 : -inf;
	if(vis[i][j][prefix]) return memo[i][j][prefix];
	int ans = -inf;
	for(int dx = -1; dx <= 1; dx++){
		int cand = -inf;
		if(j + dx >= 0 and j + dx < m){
			if(s[i - 1][j + dx] == '*') cand = prefix ? -inf : 0;
			else if(s[i - 1][j + dx] == '(') cand = 1 + DP(i - 1, j + dx, prefix + 1);
			else if(s[i - 1][j + dx] == ')' and prefix) cand = 1 + DP(i - 1, j + dx, prefix - 1);
			else if(s[i - 1][j + dx] == '.') cand = DP(i - 1, j + dx, prefix);
		}
		ans = max(ans, cand);
	}
	vis[i][j][prefix] = true;
	return memo[i][j][prefix] = ans;
}

int main(){
	scanf("%d %d", &n, &m);
	int sy;
	for(int i = 0; i < n; i++){
		scanf("%s", s[i]);
		for(int j = 0; j < m; j++){
			if(s[i][j] == 'M') sy = j;
		}
	}
	printf("%d\n", DP(n - 1, sy, 0));
	return 0;
}

Compilation message

retro.cpp: In function 'int main()':
retro.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
retro.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%s", s[i]);
      |   ~~~~~^~~~~~~~~~~~
retro.cpp:45:8: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |  printf("%d\n", DP(n - 1, sy, 0));
      |  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB Unexpected end of file - token expected
2 Incorrect 0 ms 468 KB Unexpected end of file - token expected
3 Incorrect 0 ms 468 KB Unexpected end of file - token expected
4 Incorrect 1 ms 596 KB Unexpected end of file - token expected
5 Incorrect 1 ms 596 KB Unexpected end of file - token expected
6 Incorrect 4 ms 5716 KB Unexpected end of file - token expected
7 Incorrect 4 ms 5460 KB Unexpected end of file - token expected
8 Incorrect 4 ms 5300 KB Unexpected end of file - token expected
9 Incorrect 7 ms 9424 KB Unexpected end of file - token expected
10 Incorrect 8 ms 11604 KB Unexpected end of file - token expected
11 Incorrect 148 ms 88220 KB Unexpected end of file - token expected
12 Incorrect 124 ms 81892 KB Unexpected end of file - token expected
13 Incorrect 69 ms 49716 KB Unexpected end of file - token expected
14 Incorrect 69 ms 48164 KB Unexpected end of file - token expected
15 Incorrect 185 ms 94896 KB Unexpected end of file - token expected
16 Incorrect 168 ms 87216 KB Unexpected end of file - token expected
17 Incorrect 147 ms 88268 KB Unexpected end of file - token expected
18 Incorrect 131 ms 82228 KB Unexpected end of file - token expected
19 Incorrect 203 ms 98444 KB Unexpected end of file - token expected
20 Incorrect 171 ms 91608 KB Unexpected end of file - token expected