# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
635291 | racsosabe | Retro (COCI17_retro) | C++14 | 203 ms | 98444 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 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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |