Submission #46535

#TimeUsernameProblemLanguageResultExecution timeMemory
46535ikura355Cultivation (JOI17_cultivation)C++14
5 / 100
27 ms680 KiB
#include<bits/stdc++.h> using namespace std; #define pii pair<int,int> #define X first #define Y second const int maxn = 300 + 5; const int inf = 1e9; int n,R,C; pii p[maxn]; vector<int> forup, fordown; int sz; map<int,int> mp; vector<int> have[maxn*2]; int main() { scanf("%d%d%d",&R,&C,&n); for(int i=1;i<=n;i++) scanf("%d%d",&p[i].X,&p[i].Y); int ans = inf; for(int i=1;i<=n;i++) forup.push_back(p[i].X-1), fordown.push_back(R-p[i].X); sort(forup.begin(),forup.end()); sort(fordown.begin(),fordown.end()); forup.erase(unique(forup.begin(),forup.end()),forup.end()); fordown.erase(unique(fordown.begin(),fordown.end()),fordown.end()); sort(&p[1],&p[n+1]); for(auto up : forup) { for(auto down : fordown) { mp.clear(); sz = 0; for(int x=1;x<=n;x++) { mp[max(1,p[x].X-up)]; mp[min(R,p[x].X+down)]; } for(auto &t : mp) t.second = ++sz; for(int i=1;i<=sz;i++) have[i].clear(); for(int x=1;x<=n;x++) { for(int i=mp[max(1,p[x].X-up)];i<=mp[min(R,p[x].X+down)];i++) { have[i].push_back(p[x].Y); } } for(int row=1;row<=sz;row++) sort(have[row].begin(), have[row].end()); int left = 0, right = 0, gap = 0; for(int row=1;row<=sz;row++) { left = max(left, *have[row].begin()-1); right = max(right, C-*have[row].rbegin()); } for(int row=1;row<=sz;row++) { for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right); } int gaprow = 0; for(int i=2;i<=n;i++) gaprow = max(gaprow, p[i].X-p[i-1].X-1-up-down); ans = min(ans, up + down + left + right + gap + gaprow); // printf("up = %d down = %d (%d) : use %d %d %d\n",up,down,gaprow,left,right,gap); } } printf("%d",ans); }

Compilation message (stderr)

cultivation.cpp: In function 'int main()':
cultivation.cpp:45:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
              for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right);
                          ~^~~~~~~~~~~~~~~~~
cultivation.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&R,&C,&n);
  ~~~~~^~~~~~~~~~~~~~~~~~~
cultivation.cpp:16:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%d%d",&p[i].X,&p[i].Y);
                        ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...