제출 #706362

#제출 시각아이디문제언어결과실행 시간메모리
706362BaytoroThe Kingdom of JOIOI (JOI17_joioi)C++17
100 / 100
2048 ms86196 KiB
#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) 메시지

joioi.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   75 | main(){
      | ^~~~
joioi.cpp: In function 'void fopn(std::string)':
joioi.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
joioi.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...