# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
163807 | Ort | Retro (COCI17_retro) | C++11 | 544 ms | 57080 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define MAX 305
#define HMAX 155
#define inf 1000000
using namespace std;
int n, m, sy, sx;
int dx[3] = {-1, 0, 1};
int dy[3] = {1, 1, 1};
int dp[MAX][MAX][HMAX];
char mat[MAX][MAX];
bool inside(int y, int x) {return y>=0 && x>0 && y<=n && x<=m;}
void input();
int main() {
input();
memset(dp, -1, sizeof(dp));
for(int i=0;i<n;i++)
for(int j=1;j<=m;j++)
dp[i][j][0] = 0;
for(int i=0;i<n;i++)
for(int j=1;j<=m;j++)
for(int k=0;k<n;k++) {
if(dp[i][j][k]==-1) continue;
for(int l=0;l<3;l++) {
int y = i+dy[l];
int x = j+dx[l];
if(!inside(y,x)) continue;
if(mat[y][x]==')') dp[y][x][k+1] = max(dp[y][x][k+1], dp[i][j][k]+1);
if(mat[y][x]=='(' && k>0) dp[y][x][k-1] = max(dp[y][x][k-1], dp[i][j][k]+1);
if(mat[y][x]=='.' || mat[y][x]=='M') dp[y][x][k] = max(dp[y][x][k], dp[i][j][k]);
}
}
cout << dp[sy][sx][0] << "()";
return 0;
}
void input() {
cin >> n >> m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) {
cin >> mat[i][j];
if(mat[i][j]=='M') sy = i, sx = j;
}
for(int i=1;i<=m;i++) mat[0][i] = '*';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |