# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
706362 | Baytoro | The Kingdom of JOIOI (JOI17_joioi) | C++17 | 2048 ms | 86196 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=998244353;
const int N=2005;
int a[N][N],tmp[N][N];
int n,m;
int calc(int x){
int mn=INF,mx=-INF;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
mn=min(mn,tmp[i][j]),mx=max(mx,tmp[i][j]);
}
for(int i=1, l=m+1;i<=n;i++){
for(int j=1;j<l;j++){
if(tmp[i][j]-mn>x){
l=j;
break;
}
}
for(int j=l;j<=m;j++){
if(mx-tmp[i][j]>x) return false;
}
}
return true;
}
int check(int x){
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
tmp[i][j]=a[i][j];
for(int I=0;I<2;I++){
for(int J=0;J<2;J++){
if(calc(x)) return true;
for(int i=1;i<=n;i++){
for(int l=1,r=m;l<r;l++,r--){
swap(tmp[i][l],tmp[i][r]);
}
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
tmp[i][j]=-tmp[i][j];
}
return false;
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
int l=-1,r=1e9;
while(r-l>1){
int md=(l+r)/2;
if(check(md)) r=md;
else l=md;
}
cout<<r;
}
main(){
//fopn("cbarn");
ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
컴파일 시 표준 에러 (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... |