답안 #110863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110863 2019-05-12T16:29:52 Z WLZ The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
3 ms 384 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 0x3f3f3f3f;

int h, w, mx = 0, mn = INF;
vector< vector<int> > a;

void flip_h() {
  for (int j = 0; j < w; j++) {
    for (int i = 0; i < h / 2; i++) {
      swap(a[h - i - 1][j], a[i][j]);
    }
  }
}

void flip_v() {
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w / 2; j++) {
      swap(a[i][w - j - 1], a[i][j]);
    }
  }
}

int check(int k) {
  int t = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w - 1; j++) {
      if (a[i][j] < mx - k) {
        t = max(t, j + 1);
      }
    }
    for (int j = 0; j < t; j++) {
      if (a[i][j] > mn + k) {
        return 0;
      }
    }
  }
  return 1;
}

int solve() {
  int lo = 0, hi = mx - mn, ans;
  while (lo <= hi) {
    int mid = lo + (hi - lo) / 2;
    if (check(mid)) {
      hi = mid - 1;
      ans = mid;
    } else {
      lo = mid + 1;
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  a.assign(h, vector<int>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> a[i][j];
      mx = max(mx, a[i][j]);
      mn = min(mn, a[i][j]);
    }
  }
  int ans = solve();
  flip_h();
  ans = min(ans, solve());
  flip_v();
  ans = min(ans, solve());
  flip_h();
  ans = min(ans, solve());
  cout << ans << '\n';
  return 0;
}

Compilation message

joioi.cpp: In function 'int solve()':
joioi.cpp:53:10: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return ans;
          ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -