이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
int mn = 1e9, mx = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
mn = min(mn, a[i][j]);
mx = max(mx, a[i][j]);
}
}
auto Can = [&](int dif) {
int col = 1e9;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i][j] < mx - dif) {
col = min(col, j);
}
}
for (int j = 0; j < m; j++) {
if (a[i][j] > mn + dif && j >= col) {
return false;
}
}
}
return true;
};
int ans = 1e9;
function<void()> Do = [&]() {
int bot = 0, top = 1e9;
while (bot <= top) {
int mid = bot + top >> 1;
if (Can(mid)) {
ans = min(ans, mid);
top = mid - 1;
} else {
bot = mid + 1;
}
}
};
Do();
reverse(a.begin(), a.end());
Do();
for (int i = 0; i < n; i++) reverse(a[i].begin(), a[i].end());
Do();
reverse(a.begin(), a.end());
Do();
cout << ans << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
joioi.cpp: In lambda function:
joioi.cpp:42:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid = bot + top >> 1;
| ~~~~^~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |