#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int N,rows,cols;
int x[300],y[300];
int xid[300];
int yid[300];
bool cmpx(int a,int b)
{
return x[a]<x[b];
}
bool cmpy(int a,int b)
{
return y[a]<y[b];
}
int cx[600];
int cNorth[600];
int cSouth[600];
int cSum[600];
int cid[600];
int C;
void getColumnVals(int k,int loc)
{
cx[C] = loc;
cSum[C] = 0;
int pre = -1;
for(int j=0;j<N;j++)
if(x[yid[j]] <= loc && x[yid[j]] + k >= loc)
{
cSum[C] = max(cSum[C],y[yid[j]]-pre-1);
if(pre==-1) cNorth[C] = y[yid[j]];
pre = y[yid[j]];
}
cSouth[C] = rows-pre-1;
cSum[C] = max(cSum[C],rows-pre-1);
if(pre==-1) cSum[C] = cNorth[C] = cSouth[C] = 2000000000;
// cout << loc << ": " << cSum[C] << ' ' << cNorth[C] << ' ' << cSouth[C] << '\n';
C++;
}
bool cmpc(int a,int b)
{
return cx[a]<cx[b];
}
int queSum[600];
int queNorth[600];
int queSouth[600];
int backSum,backNorth,backSouth,topSum,topNorth,topSouth;
set<int> visk;
int getMinSum(int k)
{
if(visk.find(k) != visk.end()) return 2000000000;
visk.insert(k);
C = 0;
for(int i=0;i<N;i++)
getColumnVals(k,x[xid[i]]);
for(int i=0;i<N;i++)
getColumnVals(k,x[xid[i]]+k+1);
for(int i=0;i<C;i++)
cid[i] = i;
sort(cid,cid+C,cmpc);
backSum = backNorth = backSouth = 0;
topSum = topNorth = topSouth = 0;
int ans = 2000000000;
for(int i=C-1;i>=0;i--)
{
int cur = cid[i];
while(backSum < topSum && cx[queSum[backSum]]-cx[cur] >= cols)
backSum++;
while(backNorth < topNorth && cx[queNorth[backNorth]]-cx[cur] >= cols)
backNorth++;
while(backSouth < topSouth && cx[queSouth[backSouth]]-cx[cur] >= cols)
backSouth++;
while(backSum < topSum && cSum[cur] >= cSum[queSum[topSum-1]])
topSum--;
while(backNorth < topNorth && cNorth[cur] >= cNorth[queNorth[topNorth-1]])
topNorth--;
while(backSouth < topSouth && cSouth[cur] >= cSouth[queSouth[topSouth-1]])
topSouth--;
queSum[topSum++] = cur;
queNorth[topNorth++] = cur;
queSouth[topSouth++] = cur;
ans = min(ans,max(cSum[queSum[backSum]],cNorth[queNorth[backNorth]]+cSouth[queSouth[backSouth]]));
}
return ans+k;
}
int main()
{
cin >> rows >> cols;
cin >> N;
for(int i=0;i<N;i++)
{
cin >> y[i] >> x[i];
y[i]--,x[i]--;
xid[i] = yid[i] = i;
}
sort(xid,xid+N,cmpx);
sort(yid,yid+N,cmpy);
int ans = 2000000000;
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
{
if(x[xid[j]]>x[xid[i]])
ans = min(ans,getMinSum(x[xid[j]]-x[xid[i]]-1));
ans = min(ans,getMinSum(x[xid[i]]+cols-1-x[xid[j]]));
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2048 KB |
Output is correct |
2 |
Correct |
0 ms |
2048 KB |
Output is correct |
3 |
Correct |
0 ms |
2048 KB |
Output is correct |
4 |
Correct |
0 ms |
2048 KB |
Output is correct |
5 |
Correct |
0 ms |
2048 KB |
Output is correct |
6 |
Correct |
0 ms |
2048 KB |
Output is correct |
7 |
Correct |
0 ms |
2048 KB |
Output is correct |
8 |
Correct |
0 ms |
2048 KB |
Output is correct |
9 |
Correct |
0 ms |
2048 KB |
Output is correct |
10 |
Correct |
0 ms |
2048 KB |
Output is correct |
11 |
Correct |
0 ms |
2048 KB |
Output is correct |
12 |
Correct |
0 ms |
2048 KB |
Output is correct |
13 |
Correct |
0 ms |
2048 KB |
Output is correct |
14 |
Correct |
0 ms |
2048 KB |
Output is correct |
15 |
Correct |
0 ms |
2048 KB |
Output is correct |
16 |
Correct |
0 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2048 KB |
Output is correct |
2 |
Correct |
0 ms |
2048 KB |
Output is correct |
3 |
Correct |
0 ms |
2048 KB |
Output is correct |
4 |
Correct |
0 ms |
2048 KB |
Output is correct |
5 |
Correct |
0 ms |
2048 KB |
Output is correct |
6 |
Correct |
0 ms |
2048 KB |
Output is correct |
7 |
Correct |
0 ms |
2048 KB |
Output is correct |
8 |
Correct |
0 ms |
2048 KB |
Output is correct |
9 |
Correct |
0 ms |
2048 KB |
Output is correct |
10 |
Correct |
0 ms |
2048 KB |
Output is correct |
11 |
Correct |
0 ms |
2048 KB |
Output is correct |
12 |
Correct |
0 ms |
2048 KB |
Output is correct |
13 |
Correct |
0 ms |
2048 KB |
Output is correct |
14 |
Correct |
0 ms |
2048 KB |
Output is correct |
15 |
Correct |
0 ms |
2048 KB |
Output is correct |
16 |
Correct |
0 ms |
2048 KB |
Output is correct |
17 |
Correct |
0 ms |
2048 KB |
Output is correct |
18 |
Correct |
0 ms |
2048 KB |
Output is correct |
19 |
Correct |
0 ms |
2048 KB |
Output is correct |
20 |
Correct |
0 ms |
2048 KB |
Output is correct |
21 |
Correct |
0 ms |
2048 KB |
Output is correct |
22 |
Correct |
6 ms |
2048 KB |
Output is correct |
23 |
Correct |
0 ms |
2048 KB |
Output is correct |
24 |
Correct |
16 ms |
2048 KB |
Output is correct |
25 |
Correct |
9 ms |
2048 KB |
Output is correct |
26 |
Correct |
33 ms |
2048 KB |
Output is correct |
27 |
Correct |
29 ms |
2048 KB |
Output is correct |
28 |
Correct |
13 ms |
2048 KB |
Output is correct |
29 |
Correct |
29 ms |
2048 KB |
Output is correct |
30 |
Correct |
33 ms |
2048 KB |
Output is correct |
31 |
Correct |
33 ms |
2048 KB |
Output is correct |
32 |
Correct |
33 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2048 KB |
Output is correct |
2 |
Correct |
0 ms |
2048 KB |
Output is correct |
3 |
Correct |
0 ms |
2048 KB |
Output is correct |
4 |
Correct |
0 ms |
2048 KB |
Output is correct |
5 |
Correct |
0 ms |
2048 KB |
Output is correct |
6 |
Correct |
0 ms |
2048 KB |
Output is correct |
7 |
Correct |
0 ms |
2048 KB |
Output is correct |
8 |
Correct |
0 ms |
2048 KB |
Output is correct |
9 |
Correct |
0 ms |
2048 KB |
Output is correct |
10 |
Correct |
0 ms |
2048 KB |
Output is correct |
11 |
Correct |
0 ms |
2048 KB |
Output is correct |
12 |
Correct |
0 ms |
2048 KB |
Output is correct |
13 |
Correct |
0 ms |
2048 KB |
Output is correct |
14 |
Correct |
0 ms |
2048 KB |
Output is correct |
15 |
Correct |
0 ms |
2048 KB |
Output is correct |
16 |
Correct |
0 ms |
2048 KB |
Output is correct |
17 |
Correct |
0 ms |
2048 KB |
Output is correct |
18 |
Correct |
0 ms |
2048 KB |
Output is correct |
19 |
Correct |
0 ms |
2048 KB |
Output is correct |
20 |
Correct |
0 ms |
2048 KB |
Output is correct |
21 |
Correct |
0 ms |
2048 KB |
Output is correct |
22 |
Correct |
6 ms |
2048 KB |
Output is correct |
23 |
Correct |
0 ms |
2048 KB |
Output is correct |
24 |
Correct |
16 ms |
2048 KB |
Output is correct |
25 |
Correct |
9 ms |
2048 KB |
Output is correct |
26 |
Correct |
33 ms |
2048 KB |
Output is correct |
27 |
Correct |
29 ms |
2048 KB |
Output is correct |
28 |
Correct |
13 ms |
2048 KB |
Output is correct |
29 |
Correct |
29 ms |
2048 KB |
Output is correct |
30 |
Correct |
33 ms |
2048 KB |
Output is correct |
31 |
Correct |
33 ms |
2048 KB |
Output is correct |
32 |
Correct |
33 ms |
2048 KB |
Output is correct |
33 |
Execution timed out |
2000 ms |
2312 KB |
Execution timed out |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2048 KB |
Output is correct |
2 |
Correct |
0 ms |
2048 KB |
Output is correct |
3 |
Correct |
0 ms |
2048 KB |
Output is correct |
4 |
Correct |
0 ms |
2048 KB |
Output is correct |
5 |
Correct |
0 ms |
2048 KB |
Output is correct |
6 |
Correct |
0 ms |
2048 KB |
Output is correct |
7 |
Correct |
0 ms |
2048 KB |
Output is correct |
8 |
Correct |
0 ms |
2048 KB |
Output is correct |
9 |
Correct |
0 ms |
2048 KB |
Output is correct |
10 |
Correct |
0 ms |
2048 KB |
Output is correct |
11 |
Correct |
0 ms |
2048 KB |
Output is correct |
12 |
Correct |
0 ms |
2048 KB |
Output is correct |
13 |
Correct |
0 ms |
2048 KB |
Output is correct |
14 |
Correct |
0 ms |
2048 KB |
Output is correct |
15 |
Correct |
0 ms |
2048 KB |
Output is correct |
16 |
Correct |
0 ms |
2048 KB |
Output is correct |
17 |
Correct |
0 ms |
2048 KB |
Output is correct |
18 |
Correct |
0 ms |
2048 KB |
Output is correct |
19 |
Correct |
0 ms |
2048 KB |
Output is correct |
20 |
Correct |
0 ms |
2048 KB |
Output is correct |
21 |
Correct |
0 ms |
2048 KB |
Output is correct |
22 |
Correct |
6 ms |
2048 KB |
Output is correct |
23 |
Correct |
0 ms |
2048 KB |
Output is correct |
24 |
Correct |
16 ms |
2048 KB |
Output is correct |
25 |
Correct |
9 ms |
2048 KB |
Output is correct |
26 |
Correct |
33 ms |
2048 KB |
Output is correct |
27 |
Correct |
29 ms |
2048 KB |
Output is correct |
28 |
Correct |
13 ms |
2048 KB |
Output is correct |
29 |
Correct |
29 ms |
2048 KB |
Output is correct |
30 |
Correct |
33 ms |
2048 KB |
Output is correct |
31 |
Correct |
33 ms |
2048 KB |
Output is correct |
32 |
Correct |
33 ms |
2048 KB |
Output is correct |
33 |
Execution timed out |
2000 ms |
2312 KB |
Execution timed out |
34 |
Halted |
0 ms |
0 KB |
- |