Submission #955138

#TimeUsernameProblemLanguageResultExecution timeMemory
955138edogawa_somethingCultivation (JOI17_cultivation)C++17
30 / 100
95 ms856 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=5e5+10; 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]; bool ck[41]; vii v,vv[41]; void chk(ll x,ll y,ll s){ if(v.empty()) return; sort(all(v)); memset(ck,0,sizeof(ck)); for(auto it:v){ ll z=it; for(int i=0;i<=x;i++){ if(z<0) break; ck[z]=1; z--; } z=it; for(int i=0;i<=y;i++){ if(z>r) break; ck[z]=1; z++; } } for(int i=1;i<=r;i++){ if(ck[i]) vv[i].pb(s); } } ll solve(ll x,ll y){ v.clear(); for(int i=1;i<=r;i++) vv[i].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{ chk(x,y,a[i-1].S); v.clear(); v.pb(a[i].F); } } } chk(x,y,a[n-1].S); ll w=0,e=0,ov=0; for(int i=1;i<=r;i++){ if(vv[i].empty()) return inf; w=max(w,vv[i][0]-1); e=max(e,c-vv[i].back()); for(int j=1;j<vv[i].size();j++){ ov=max(ov,vv[i][j]-vv[i][j-1]-1); } } return max(ov,e+w); } 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(ll i=0;i<=50;i++){ for(ll j=0;j<=50;j++){ ans=min(ans,solve(i,j)+i+j); } } cout<<ans<<'\n'; } return 0; } /* */

Compilation message (stderr)

cultivation.cpp: In function 'll solve(ll, ll)':
cultivation.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     for(int j=1;j<vv[i].size();j++){
      |                 ~^~~~~~~~~~~~~
#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...