이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define N 40
#define M 300
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void sort(int *aa, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;
while (j < k)
if (aa[j] == a)
j++;
else if (aa[j] < a) {
tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
i++, j++;
} else {
k--;
tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
}
sort(aa, l, i);
l = k;
}
}
int main() {
static int ii[M], jj[M], jj_[M];
int n, m, k, k_, h, i, u, d;
long long l, r, c, ans;
scanf("%d%d%d", &n, &m, &k);
for (h = 0; h < k; h++)
scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
ans = INF;
for (u = 0; u < n; u++)
for (d = 0; d < n; d++) {
l = r = c = 0;
for (i = 0; i < n; i++) {
k_ = 0;
for (h = 0; h < k; h++)
if (ii[h] - u <= i && i <= ii[h] + d)
jj_[k_++] = jj[h];
if (k_ == 0) {
c = INF;
break;
}
sort(jj_, 0, k_);
l = max(l, jj_[0] - 0), r = max(r, m - 1 - jj_[k_ - 1]);
for (h = 1; h < k_; h++)
c = max(c, jj_[h] - jj_[h - 1] - 1);
}
ans = min(ans, u + d + max(l + r, c));
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cultivation.c: In function 'main':
cultivation.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d%d%d", &n, &m, &k);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cultivation.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d%d", &ii[h], &jj[h]), ii[h]--, jj[h]--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |