//30 pts. #2
#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> have[45];
vector<int> forup, fordown;
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);
forup.erase(unique(forup.begin(),forup.end()),forup.end());
fordown.erase(unique(fordown.begin(),fordown.end()),fordown.end());
for(auto up : forup) {
for(auto down : fordown) {
for(int row=1;row<=R;row++) have[row].clear();
for(int x=1;x<=n;x++) {
for(int i=max(1,p[x].X-up);i<=min(R,p[x].X+down);i++) {
have[i].push_back(p[x].Y);
}
}
for(int row=1;row<=R;row++) sort(have[row].begin(), have[row].end());
int left = 0, right = 0, gap = 0;
int gaprow = 0, con = 0;
for(int row=1;row<=R;row++) {
if(have[row].size()==0) {
con++;
gaprow = max(gaprow, con);
}
else {
con = 0;
left = max(left, *have[row].begin()-1);
right = max(right, C-*have[row].rbegin());
}
}
for(int row=1;row<=R;row++) {
for(int i=1;i<have[row].size();i++) gap = max(gap, have[row][i]-have[row][i-1]-1-left-right);
}
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
cultivation.cpp: In function 'int main()':
cultivation.cpp:43: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:14: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:15: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 time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
78 ms |
620 KB |
Output is correct |
19 |
Correct |
7 ms |
620 KB |
Output is correct |
20 |
Correct |
2 ms |
620 KB |
Output is correct |
21 |
Correct |
51 ms |
620 KB |
Output is correct |
22 |
Correct |
1022 ms |
632 KB |
Output is correct |
23 |
Correct |
14 ms |
632 KB |
Output is correct |
24 |
Execution timed out |
2055 ms |
632 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
78 ms |
620 KB |
Output is correct |
19 |
Correct |
7 ms |
620 KB |
Output is correct |
20 |
Correct |
2 ms |
620 KB |
Output is correct |
21 |
Correct |
51 ms |
620 KB |
Output is correct |
22 |
Correct |
1022 ms |
632 KB |
Output is correct |
23 |
Correct |
14 ms |
632 KB |
Output is correct |
24 |
Execution timed out |
2055 ms |
632 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
748 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
748 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
476 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
2 ms |
592 KB |
Output is correct |
5 |
Correct |
2 ms |
592 KB |
Output is correct |
6 |
Correct |
2 ms |
592 KB |
Output is correct |
7 |
Correct |
2 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
592 KB |
Output is correct |
9 |
Correct |
2 ms |
592 KB |
Output is correct |
10 |
Correct |
2 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
2 ms |
592 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
78 ms |
620 KB |
Output is correct |
19 |
Correct |
7 ms |
620 KB |
Output is correct |
20 |
Correct |
2 ms |
620 KB |
Output is correct |
21 |
Correct |
51 ms |
620 KB |
Output is correct |
22 |
Correct |
1022 ms |
632 KB |
Output is correct |
23 |
Correct |
14 ms |
632 KB |
Output is correct |
24 |
Execution timed out |
2055 ms |
632 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |