이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
enum {UP, LEFT, DOWN, RIGHT};
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int MAXN = 2020;
int H, W, Q;
int A[MAXN], B[MAXN];
int dp[MAXN][MAXN][4];
bool ins(int x, int y){ return 0<=x&&x<H&&0<=y&&y<W; }
int solve(int x, int y, int d)
{
if(dp[x][y][d] != -1) return dp[x][y][d];
int nx = x+dx[d], ny = y+dy[d];
if(!ins(nx, ny)) return dp[x][y][d] = 0;
if(d==UP||d==DOWN)
{
if(A[nx]<B[ny]) return dp[x][y][d] = 1+solve(nx, ny, d);
else return dp[x][y][d] = 1+max(solve(nx, ny, LEFT), solve(nx, ny, RIGHT));
}
else
{
if(B[ny]<A[nx]) return dp[x][y][d] = 1+solve(nx, ny, d);
else return dp[x][y][d] = 1+max(solve(nx, ny, UP), solve(nx, ny, DOWN));
}
}
int main()
{
memset(dp, -1, sizeof dp);
scanf("%d%d%d", &H, &W, &Q);
for(int i=0; i<H; ++i)
scanf("%d", A+i);
for(int i=0; i<W; ++i)
scanf("%d", B+i);
while(Q--)
{
int S, T; scanf("%d%d", &S, &T); --S; --T;
int ans = 0;
for(int d=0; d<4; ++d)
ans = max(ans, solve(S, T, d));
printf("%d\n", ans);
}
}
컴파일 시 표준 에러 (stderr) 메시지
abduction2.cpp: In function 'int main()':
abduction2.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &H, &W, &Q);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
abduction2.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", A+i);
~~~~~^~~~~~~~~~~
abduction2.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", B+i);
~~~~~^~~~~~~~~~~
abduction2.cpp:40:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int S, T; scanf("%d%d", &S, &T); --S; --T;
~~~~~^~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |