# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
77835 | Vardanyan | The Kingdom of JOIOI (JOI17_joioi) | C++14 | 1521 ms | 253164 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 2007;
int a[N][N];
int n,m;
int mns = 1000*1000*1000;
bool rot(){
vector<vector<int> > v;
for(int i = 1;i<=n;i++){
vector<int> u;
for(int j = 1;j<=m;j++) u.push_back(a[i][j]);
reverse(u.begin(),u.end());
v.push_back(u);
}
for(int j = 1;j<=n;j++){
for(int i = 0;i<v[j-1].size();i++){
a[i+1][j] = v[j-1][i];
}
}
swap(n,m);
}
bool check(int x){
bool f = false;
int ed = m;
int mx = 0;
int mn = 1000*1000*1000+5;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=ed;j++){
if(a[i][j]-mns>x){
ed = j-1;
break;
}
}
for(int j = ed+1;j<=m;j++){
mx = max(mx,a[i][j]);
mn = min(mn,a[i][j]);
}
}
if(mx-mn<=x) f = true;
return f;
}
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]);
mns = min(mns,a[i][j]);
}
int mnans = 1000*1000*1000;
for(int i = 0;i<4;i++){
int l = 0;
int r = 1000*1000*1000;
int ans = r;
while(l<=r){
int mid = (l+r)/2;
if(check(mid)){
ans = mid;
r = mid-1;
}
else l = mid+1;
}
mnans = min(mnans,ans);
rot();
}
cout<<mnans<<endl;
return 0;
}
컴파일 시 표준 에러 (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... |