Submission #568586

#TimeUsernameProblemLanguageResultExecution timeMemory
568586Waratpp123The Kingdom of JOIOI (JOI17_joioi)C++14
0 / 100
0 ms212 KiB
#include<bits/stdc++.h> using namespace std; int a[2010][2010]; struct A{ int i,j,w; bool operator<(const A&o)const{ return w>o.w; } }; vector<A> g; int main(){ int i,j,n,m; scanf("%d %d",&n,&m); for(i=1;i<=n;i++){ for(j=1;j<=m;j++){ scanf("%d",&a[i][j]); } } for(i=1;i<=n;i++){ for(j=1;j<m;j++){ g.push_back({2*i-1,2*j,abs(a[i][j+1]-a[i][j])}); } } for(i=1;i<n;i++){ for(j=1;j<=m;j++){ g.push_back({2*i,2*j-1,abs(a[i+1][j]-a[i][j])}); } } sort(g.begin(),g.end()); int l=-1,r=n+m+1,mid; while(l<r){ mid=(l+r+1)/2; int ch=0,ans=0; vector<pair<int,int>> v; v.clear(); for(i=0;i<=mid;i++){ v.push_back({g[i].i,g[i].j}); } sort(v.begin(),v.end()); int inc=-1,dec=1000000007; for(auto x: v){ if(x.second>=inc){ inc=x.second; }else{ ch=1; break; } } if(ch==0) ans=1; ch=0; for(auto x: v){ if(x.second<=dec){ dec=x.second; }else{ ch=1; break; } } if(ch==0) ans=1; if(ans==1) l=mid; else r=mid-1; } printf("%d\n",g[l+1].w); return 0; }

Compilation message (stderr)

joioi.cpp: In function 'int main()':
joioi.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
joioi.cpp:16:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |             scanf("%d",&a[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...