Submission #955065

#TimeUsernameProblemLanguageResultExecution timeMemory
955065edogawa_somethingCultivation (JOI17_cultivation)C++17
5 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vii; typedef pair<ll,ll> pii; #define F first #define S second #define pb push_back #define eb emplace_back #define all(v) v.begin(),v.end() #define pow poww const ll M=5000; const ll inf=2e18; const ll mod=1e9+7; ll pow(ll x,ll y){ ll res=1; x%=mod; while(y>0){ if((y&1)) res*=x,res%=mod; x*=x,x%=mod; y=(y>>1); } return res; } ll r,c,n; pii a[M]; vii v,vv; bool chk(ll x,ll y){ sort(all(v)); if(v[0]-1>x||r-v.back()>y) return 0; for(int i=1;i<v.size();i++){ if(v[i]-v[i-1]-1>x+y) return 0; } return 1; } ll solve(ll x,ll y){ v.clear(),vv.clear(); for(int i=0;i<n;i++){ if(i==0) v.pb(a[i].F); if(i>0){ if(a[i].S==a[i-1].S){ v.pb(a[i].F); } else{ if(chk(x,y)) vv.pb(a[i-1].S); v.clear(); v.pb(a[i].F); } } } if(chk(x,y)) vv.pb(a[n-1].S); if(vv.empty()) return inf; ll res=0; sort(all(vv)); res=vv[0]-1+c-vv.back(); for(int i=1;i<vv.size();i++){ res=max(res,vv[i]-vv[i-1]-1); } return res; } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int TC=1; //cin>>TC; while(TC--){ cin>>r>>c>>n; for(int i=0;i<n;i++){ cin>>a[i].S>>a[i].F; } sort(a,a+n); for(int i=0;i<n;i++) swap(a[i].F,a[i].S); ll ans=inf; for(int i=0;i<=40;i++){ for(int j=0;j<=40;j++){ ans=min(ans,solve(i,j)+i+j); } } cout<<ans<<'\n'; } return 0; } /* */

Compilation message (stderr)

cultivation.cpp: In function 'bool chk(ll, ll)':
cultivation.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |   for(int i=1;i<v.size();i++){
      |               ~^~~~~~~~~
cultivation.cpp: In function 'll solve(ll, ll)':
cultivation.cpp:63:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int i=1;i<vv.size();i++){
      |               ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...