Submission #46515

#TimeUsernameProblemLanguageResultExecution timeMemory
46515ikura355Cultivation (JOI17_cultivation)C++14
5 / 100
3 ms748 KiB
//#3 #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 szx, szy; int rec[maxn]; map<int,int> mpx, mpy; int cnt[maxn*2][maxn]; 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); //prep sort(&p[1],&p[n+1]); for(int i=1;i<=n;i++) mpy[p[i].Y]; for(auto &t : mpy) { t.second = ++szy; rec[szy] = t.first; } for(int i=1;i<=n;i++) { forup.push_back(p[i].X-1); fordown.push_back(R-p[i].X); } //solve int ans = inf; for(auto up : forup) { for(auto down : fordown) { //gap row int gaprow = 0; for(int i=2;i<=n;i++) gaprow = max(gaprow, p[i].X-p[i-1].X-1-up-down); //cpidx for x mpx.clear(); for(int i=1;i<=n;i++) mpx[max(1,p[i].X-up)], mpx[min(R,p[i].X+down)]; int szx = 0; for(auto &t : mpx) t.second = ++szx; //place for(int x=1;x<=szx;x++) for(int y=1;y<=szy;y++) cnt[x][y] = 0; for(int i=1;i<=n;i++) cnt[mpx[max(1,p[i].X-up)]][mpy[p[i].Y]]++, cnt[mpx[min(R,p[i].X+down)]+1][mpy[p[i].Y]]--; for(int x=1;x<=szx;x++) for(int y=1;y<=szy;y++) cnt[x][y] += cnt[x-1][y]; //show // printf("up = %d down = %d\n",up,down); // for(int x=1;x<=szx;x++) { // for(int y=1;y<=szy;y++) printf("%d ",cnt[x][y]); // printf("\n"); // } // printf("-------------------------\n"); //left and right int left = 0, right = 0; for(int x=1;x<=szx;x++) { for(int y=1;y<=szy;y++) { if(cnt[x][y]) { left = max(left, rec[y] - 1); break; } } for(int y=szy;y>=1;y--) { if(cnt[x][y]) { right = max(right, C - rec[y]); break; } } } //gap int gap = 0; for(int x=1;x<=szx;x++) { int last = -1; for(int y=1;y<=szy;y++) { if(last!=-1) { gap = max(gap, rec[y] - rec[last] - 1 - left - right); } last = y; } } 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:20: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:21: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...