#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
#define REP(i, n) for(int i = 0;i < n;i ++)
#define REP1(i, n) for(int i = 1;i <= n;i ++)
#define FILL(i, n) memset(i, n, sizeof(i))
#define X first
#define Y second
#define pb push_back
#define SZ(_a) ((int)(_a).size())
#define ALL(_a) (_a).begin(), (_a).end()
#ifdef brian
#define IOS()
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...t>void _do(T &&x, t &&...X){cerr<<x<<", ";_do(X...);}
#define debug(...) {\
fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, #__VA_ARGS__);\
_do(__VA_ARGS__);\
}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif
const ll MAXn = 1e5 + 5;
const ll INF = ll(1e18);
const ll MOD = 1000000007;
vector<ii> d;
vector<ll> dt[45];
int main(){
IOS();
ll r, c, n;
cin>>r>>c>>n;
REP1(i, n)
{
ll x, y;
cin>>x>>y;
d.pb(ii(x, y));
}
ll ans = INF;
REP(a, r)REP(b, r)
{
REP1(i, r)dt[i].clear();
for(auto &p:d)for(int i = -a;i <= b;i ++)if(p.X + i > 0 && p.X + i <= r)dt[p.X + i].pb(p.Y);
REP1(i, r)sort(ALL(dt[i])), dt[i].resize(unique(ALL(dt[i])) - dt[i].begin());
bool fg = 0;
ll x = 0, y = 0, mx = 0;
REP1(i, r)
{
if(!SZ(dt[i])){
fg = 1;
break;
}
x = max(x, dt[i][0] - 1);
y = max(y, c - dt[i].back());
for(int j = 0;j < SZ(dt[i]) - 1;j ++)mx = max(mx, dt[i][j + 1] - dt[i][j] - 1);
}
if(fg)continue;
ans = min(ans, max(x + y, mx) + a + b);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
18 ms |
372 KB |
Output is correct |
19 |
Correct |
17 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
44 ms |
436 KB |
Output is correct |
22 |
Correct |
166 ms |
504 KB |
Output is correct |
23 |
Correct |
26 ms |
376 KB |
Output is correct |
24 |
Correct |
325 ms |
504 KB |
Output is correct |
25 |
Correct |
229 ms |
504 KB |
Output is correct |
26 |
Correct |
529 ms |
632 KB |
Output is correct |
27 |
Correct |
510 ms |
784 KB |
Output is correct |
28 |
Correct |
294 ms |
476 KB |
Output is correct |
29 |
Correct |
440 ms |
532 KB |
Output is correct |
30 |
Correct |
518 ms |
516 KB |
Output is correct |
31 |
Correct |
525 ms |
632 KB |
Output is correct |
32 |
Correct |
524 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
18 ms |
372 KB |
Output is correct |
19 |
Correct |
17 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
44 ms |
436 KB |
Output is correct |
22 |
Correct |
166 ms |
504 KB |
Output is correct |
23 |
Correct |
26 ms |
376 KB |
Output is correct |
24 |
Correct |
325 ms |
504 KB |
Output is correct |
25 |
Correct |
229 ms |
504 KB |
Output is correct |
26 |
Correct |
529 ms |
632 KB |
Output is correct |
27 |
Correct |
510 ms |
784 KB |
Output is correct |
28 |
Correct |
294 ms |
476 KB |
Output is correct |
29 |
Correct |
440 ms |
532 KB |
Output is correct |
30 |
Correct |
518 ms |
516 KB |
Output is correct |
31 |
Correct |
525 ms |
632 KB |
Output is correct |
32 |
Correct |
524 ms |
632 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
544 ms |
540 KB |
Output is correct |
35 |
Correct |
550 ms |
764 KB |
Output is correct |
36 |
Correct |
548 ms |
632 KB |
Output is correct |
37 |
Correct |
361 ms |
644 KB |
Output is correct |
38 |
Correct |
548 ms |
760 KB |
Output is correct |
39 |
Correct |
530 ms |
640 KB |
Output is correct |
40 |
Correct |
554 ms |
748 KB |
Output is correct |
41 |
Correct |
322 ms |
504 KB |
Output is correct |
42 |
Correct |
415 ms |
764 KB |
Output is correct |
43 |
Correct |
484 ms |
632 KB |
Output is correct |
44 |
Correct |
559 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
252 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
18 ms |
372 KB |
Output is correct |
19 |
Correct |
17 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
44 ms |
436 KB |
Output is correct |
22 |
Correct |
166 ms |
504 KB |
Output is correct |
23 |
Correct |
26 ms |
376 KB |
Output is correct |
24 |
Correct |
325 ms |
504 KB |
Output is correct |
25 |
Correct |
229 ms |
504 KB |
Output is correct |
26 |
Correct |
529 ms |
632 KB |
Output is correct |
27 |
Correct |
510 ms |
784 KB |
Output is correct |
28 |
Correct |
294 ms |
476 KB |
Output is correct |
29 |
Correct |
440 ms |
532 KB |
Output is correct |
30 |
Correct |
518 ms |
516 KB |
Output is correct |
31 |
Correct |
525 ms |
632 KB |
Output is correct |
32 |
Correct |
524 ms |
632 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
544 ms |
540 KB |
Output is correct |
35 |
Correct |
550 ms |
764 KB |
Output is correct |
36 |
Correct |
548 ms |
632 KB |
Output is correct |
37 |
Correct |
361 ms |
644 KB |
Output is correct |
38 |
Correct |
548 ms |
760 KB |
Output is correct |
39 |
Correct |
530 ms |
640 KB |
Output is correct |
40 |
Correct |
554 ms |
748 KB |
Output is correct |
41 |
Correct |
322 ms |
504 KB |
Output is correct |
42 |
Correct |
415 ms |
764 KB |
Output is correct |
43 |
Correct |
484 ms |
632 KB |
Output is correct |
44 |
Correct |
559 ms |
760 KB |
Output is correct |
45 |
Runtime error |
2 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
46 |
Halted |
0 ms |
0 KB |
- |