# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
62254 | kingpig9 | The Kingdom of JOIOI (JOI17_joioi) | C++11 | 3104 ms | 52860 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
void setmin (int &a, int b) {
if (a > b) {
a = b;
}
}
void setmax (int &a, int b) {
if (a < b) {
a = b;
}
}
int N, M, mx = 0, mn = 1e9;
int A[MAXN][MAXN];
int msk[MAXN][MAXN];
int mnpos[2][MAXN], mxpos[2][MAXN]; //min position for each of them
void calcpos() {
for (int i = 1; i <= N; i++) {
mnpos[0][i] = mnpos[1][i] = M + 1;
mxpos[0][i] = mxpos[1][i] = 0;
for (int j = 1; j <= M; j++) {
for (int k = 0; k < 2; k++) {
if (msk[i][j] == (1 << k)) {
setmin(mnpos[k][i], j);
setmax(mxpos[k][i], j);
}
}
}
}
}
bool solve (int b) {
//can the bit b be monotonically increasing??
int cur = 0;
for (int i = 1; i <= N; i++) {
if (mxpos[b][i] > mnpos[b ^ 1][i]) {
return false;
}
//so can take mxpos[b][i] <= j < mnpos[b ^ 1][i]
if (cur >= mnpos[b ^ 1][i]) {
return false;
}
setmax(cur, mxpos[b][i]);
}
return true;
}
bool moo (int g) {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
msk[i][j] = 0;
if (A[i][j] <= mn + g) {
msk[i][j] ^= 1;
}
if (A[i][j] >= mx - g) {
msk[i][j] ^= 2;
}
if (msk[i][j] == 0) {
return false;
}
}
}
calcpos();
if (solve(0) || solve(1)) {
return true;
}
//check if it can be decreasing or increasing!
for (int i = 1; i <= N; i++) {
reverse(msk[i] + 1, msk[i] + M + 1);
}
calcpos();
if (solve(0) || solve(1)) {
return true;
}
return false;
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
scanf("%d", &A[i][j]);
setmin(mn, A[i][j]);
setmax(mx, A[i][j]);
}
}
int lo = -1, hi = mx - mn;
while (hi - lo > 1) {
int mid = (lo + hi) / 2;
if (moo(mid)) {
hi = mid;
} else {
lo = mid;
}
}
printf("%d\n", hi);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |