/*input
4 4
2
1 1
4 4
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<'('<<P.F<<','<<P.S<<')';
return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;
ll mypow(ll a,ll b){
ll res=1LL;
while(b){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
ll x[305],y[305];
vector<ll> v[45];
int main(){
IOS;
ll n,m,q;
cin>>n>>m>>q;
REP(i,q) cin>>x[i]>>y[i];
REP(i,q) x[i]--,y[i]--;
ll ans=INF64;
for(ll up=0;up<n;up++) for(ll dn=0;dn<n;dn++){
REP(i,n) v[i].clear();
REP(i,q){
for(ll X=x[i]-dn;X<=x[i]+up;X++) if(X>=0&&X<n){
v[X].pb(y[i]);
}
}
REP(i,n) sort(ALL(v[i]));
bool f=1;
REP(i,n) if(SZ(v[i])==0) f=0;
if(!f) continue;
ll cur=0;
ll l=0,r=0;
REP(i,n){
l=max(l,v[i][0]);
r=max(r,m-1-v[i].back());
REP(j,SZ(v[i])-1) cur=max(cur,v[i][j+1]-v[i][j]-1);
}
cur=max(cur,l+r);
ans=min(ans,cur+up+dn);
// cout<<up<<' '<<dn<<' '<<cur<<'\n';
}
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 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 |
376 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 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 |
376 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 |
14 ms |
444 KB |
Output is correct |
19 |
Correct |
13 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
33 ms |
412 KB |
Output is correct |
22 |
Correct |
131 ms |
376 KB |
Output is correct |
23 |
Correct |
19 ms |
376 KB |
Output is correct |
24 |
Correct |
269 ms |
604 KB |
Output is correct |
25 |
Correct |
186 ms |
504 KB |
Output is correct |
26 |
Correct |
447 ms |
536 KB |
Output is correct |
27 |
Correct |
432 ms |
648 KB |
Output is correct |
28 |
Correct |
253 ms |
504 KB |
Output is correct |
29 |
Correct |
374 ms |
632 KB |
Output is correct |
30 |
Correct |
443 ms |
632 KB |
Output is correct |
31 |
Correct |
447 ms |
632 KB |
Output is correct |
32 |
Correct |
447 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 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 |
376 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 |
14 ms |
444 KB |
Output is correct |
19 |
Correct |
13 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
33 ms |
412 KB |
Output is correct |
22 |
Correct |
131 ms |
376 KB |
Output is correct |
23 |
Correct |
19 ms |
376 KB |
Output is correct |
24 |
Correct |
269 ms |
604 KB |
Output is correct |
25 |
Correct |
186 ms |
504 KB |
Output is correct |
26 |
Correct |
447 ms |
536 KB |
Output is correct |
27 |
Correct |
432 ms |
648 KB |
Output is correct |
28 |
Correct |
253 ms |
504 KB |
Output is correct |
29 |
Correct |
374 ms |
632 KB |
Output is correct |
30 |
Correct |
443 ms |
632 KB |
Output is correct |
31 |
Correct |
447 ms |
632 KB |
Output is correct |
32 |
Correct |
447 ms |
732 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
474 ms |
760 KB |
Output is correct |
35 |
Correct |
461 ms |
632 KB |
Output is correct |
36 |
Correct |
475 ms |
628 KB |
Output is correct |
37 |
Correct |
316 ms |
640 KB |
Output is correct |
38 |
Correct |
485 ms |
632 KB |
Output is correct |
39 |
Correct |
445 ms |
680 KB |
Output is correct |
40 |
Correct |
481 ms |
632 KB |
Output is correct |
41 |
Correct |
267 ms |
632 KB |
Output is correct |
42 |
Correct |
352 ms |
736 KB |
Output is correct |
43 |
Correct |
425 ms |
632 KB |
Output is correct |
44 |
Correct |
474 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
- |
# |
Verdict |
Execution time |
Memory |
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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 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 |
376 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 |
14 ms |
444 KB |
Output is correct |
19 |
Correct |
13 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
33 ms |
412 KB |
Output is correct |
22 |
Correct |
131 ms |
376 KB |
Output is correct |
23 |
Correct |
19 ms |
376 KB |
Output is correct |
24 |
Correct |
269 ms |
604 KB |
Output is correct |
25 |
Correct |
186 ms |
504 KB |
Output is correct |
26 |
Correct |
447 ms |
536 KB |
Output is correct |
27 |
Correct |
432 ms |
648 KB |
Output is correct |
28 |
Correct |
253 ms |
504 KB |
Output is correct |
29 |
Correct |
374 ms |
632 KB |
Output is correct |
30 |
Correct |
443 ms |
632 KB |
Output is correct |
31 |
Correct |
447 ms |
632 KB |
Output is correct |
32 |
Correct |
447 ms |
732 KB |
Output is correct |
33 |
Correct |
2 ms |
376 KB |
Output is correct |
34 |
Correct |
474 ms |
760 KB |
Output is correct |
35 |
Correct |
461 ms |
632 KB |
Output is correct |
36 |
Correct |
475 ms |
628 KB |
Output is correct |
37 |
Correct |
316 ms |
640 KB |
Output is correct |
38 |
Correct |
485 ms |
632 KB |
Output is correct |
39 |
Correct |
445 ms |
680 KB |
Output is correct |
40 |
Correct |
481 ms |
632 KB |
Output is correct |
41 |
Correct |
267 ms |
632 KB |
Output is correct |
42 |
Correct |
352 ms |
736 KB |
Output is correct |
43 |
Correct |
425 ms |
632 KB |
Output is correct |
44 |
Correct |
474 ms |
632 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 |
- |