이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 2000
#define M 2000
#define INF 0x3f3f3f3f
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
int aa[N][M], aa_[N][M], n, m;
int solve_(int d) {
int i, j, j_, mn, mx;
mn = INF, mx = -INF;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
mn = min(mn, aa_[i][j]), mx = max(mx, aa_[i][j]);
for (i = 0, j_ = m; i < n; i++) {
for (j = 0; j < j_; j++)
if (aa_[i][j] - mn > d) {
j_ = j;
break;
}
for (j = j_; j < m; j++)
if (mx - aa_[i][j] > d)
return 0;
}
return 1;
}
int solve(int d) {
int i, j, jl, jr, u, v, tmp;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
aa_[i][j] = aa[i][j];
for (u = 0; u < 2; u++) {
for (v = 0; v < 2; v++) {
if (solve_(d))
return 1;
for (i = 0; i < n; i++)
for (jl = 0, jr = m - 1; jl < jr; jl++, jr--)
tmp = aa_[i][jl], aa_[i][jl] = aa_[i][jr], aa_[i][jr] = tmp;
}
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
aa_[i][j] = -aa_[i][j];
}
return 0;
}
int main() {
int i, j, lower, upper;
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
scanf("%d", &aa[i][j]);
lower = -1, upper = INF;
while (upper - lower > 1) {
int d = (lower + upper) / 2;
if (solve(d))
upper = d;
else
lower = d;
}
printf("%d\n", upper);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
joioi.c: In function 'main':
joioi.c:56:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d%d", &n, &m);
| ^~~~~~~~~~~~~~~~~~~~~
joioi.c:59:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d", &aa[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... |