이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define inf 2000000007
#define N 1005
using namespace std;
int n, m, ans = -inf, a[N][N], dp[2][4][N][N];
int o[] = {-1, 0, 1, 0};
int p[] = {0, 1, 0, -1};
int f(int dur, int yon, int i, int j){
int &r = dp[dur][yon][i][j];
if(r != -inf)
return r;
if(i < 1 or j < 1 or i > n or j > m)
return -inf + 1;
if(dur == 0){
if(a[i][j] > f(dur, yon, i + o[yon], j + p[yon]) - 1)
r = a[i][j];
else
r = f(dur, yon, i + o[yon], j + p[yon]) - 1;
}
if(dur == 1){
if(-a[i][j] > f(dur, yon, i + o[yon], j + p[yon]) - 1)
r = -a[i][j];
else
r = f(dur, yon, i + o[yon], j + p[yon]) - 1;
}
return r;
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d",&n ,&m);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
scanf("%d",&a[i][j]);
for(int i = 0; i <= n + 1; i++)
for(int j = 0; j <= m + 1; j++)
for(int yon = 0; yon <= 3; yon++)
for(int dur = 0; dur <= 1; dur++)
dp[dur][yon][i][j] = -inf;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
for(int yon = 0; yon <= 3; yon++)
for(int dur = 0; dur <= 1; dur++)
f(dur, yon, i, j);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
for(int l = 0; l <= 3; l++)
for(int k = 0; k <= 3; k++)
if(l != k)
ans = max(ans, dp[0][l][i][j] + dp[1][k][i][j] - 1 );
printf("%d\n",ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
maxcomp.cpp: In function 'int main()':
maxcomp.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n ,&m);
~~~~~^~~~~~~~~~~~~~~~
maxcomp.cpp:42:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i][j]);
~~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |