# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1071607 |
2024-08-23T09:17:33 Z |
정희우(#11139) |
Cultivation (JOI17_cultivation) |
C++17 |
|
18 ms |
1500 KB |
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
const int MAX_N=310;
const int INF=2.01e+9;
int n,mx,my;
pii pos[MAX_N];
int xa[MAX_N],ya[MAX_N];
vint xsum;
struct Seg
{
int lm,rm,tm;
int lv,rv;
void init()
{
lm=rm=tm=lv=rv=0;
}
void init2()
{
lm=rm=tm=0;
lv=-1;rv=my+1;
}
void operator += (const Seg &o)
{
lm=max(lm,o.lm);
rm=max(rm,o.rm);
tm=max(tm,o.tm);
if(rv==0 && o.lv==my)
tm=INF;
else if(rv==0)
lm=max(lm,o.lv-rv);
else if(o.lv==my)
rm=max(rm,o.lv-rv);
else
tm=max(tm,o.lv-rv);
if(lv==-1)lv=o.lv;
rv=o.rv;
}
Seg operator + (const Seg &o)
{
Seg ret;
ret.lm=max(lm,o.lm);
ret.rm=max(rm,o.rm);
ret.tm=max(tm,o.tm);
return ret;
}
};
Seg seg[MAX_N<<4];
void update_lazy(int i)
{
if(seg[i].lv==-1)return;
seg[i<<1]+=seg[i];
seg[i<<1|1]+=seg[i];
seg[i].init2();
}
void init_(int i,int s,int e)
{
seg[i].init2();
if(s+1==e)
{
seg[i].init();
return;
}
init_(i<<1,s,(s+e)>>1);
init_(i<<1|1,(s+e)>>1,e);
}
void update_(int i,int s,int e,int l,int r,Seg v)
{
if(s>=r || e<=l)return;
if(l<=s && e<=r)
{
seg[i]+=v;
return;
}
update_lazy(i);
update_(i<<1,s,(s+e)>>1,l,r,v);
update_(i<<1|1,(s+e)>>1,e,l,r,v);
}
void fillup(int i,int s,int e)
{
if(s+1==e)return;
update_lazy(i);
fillup(i<<1,s,(s+e)>>1);
fillup(i<<1|1,(s+e)>>1,e);
seg[i]=seg[i<<1]+seg[i<<1|1];
}
Seg find_(int i,int s,int e,int l,int r)
{
if(s>=r || e<=l)return {0,0,0,0,0};
if(l<=s && e<=r)return seg[i];
return find_(i<<1,s,(s+e)>>1,l,r)+find_(i<<1|1,(s+e)>>1,e,l,r);
}
int calc(int dx)
{
vint px;
for(int i=0;i<n;i++)
{
px.push_back(xa[i]);
px.push_back(xa[i]-1);
px.push_back(xa[i]+dx);
px.push_back(xa[i]+dx+1);
}
sort(px.begin(),px.end());
px.resize(unique(px.begin(),px.end())-px.begin());
int pn=px.size();
init_(1,0,pn);
for(int i=0;i<n;i++)
{
int l=lower_bound(px.begin(),px.end(),xa[i])-px.begin();
int r=upper_bound(px.begin(),px.end(),xa[i]+dx)-px.begin();
update_(1,0,pn,l,r,{0,0,0,ya[i]-1,ya[i]});
}
update_(1,0,pn,0,pn,{0,0,0,my,my+1});
fillup(1,0,pn);
int ret=INF;
for(auto x : px)
{
if(x>1+dx)break;
int l=lower_bound(px.begin(),px.end(),x)-px.begin();
int r=upper_bound(px.begin(),px.end(),x+mx-1)-px.begin();
Seg v=find_(1,0,pn,l,r);
ret=min(ret,max(v.lm+v.rm,v.tm));
}
return ret;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> mx >> my >> n;
for(int i=0;i<n;i++)
cin >> pos[i].second >> pos[i].first;
sort(pos,pos+n);
for(int i=0;i<n;i++)
{
xa[i]=pos[i].second;
ya[i]=pos[i].first;
}
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
xsum.push_back(max(0,xa[i]-xa[j]-1));
xsum.push_back(mx-xa[i]+xa[j]-1);
}
sort(xsum.begin(),xsum.end());
xsum.resize(unique(xsum.begin(),xsum.end())-xsum.begin());
int ans=INF;
for(auto dx : xsum)
ans=min(ans,calc(dx)+dx);
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
2 ms |
564 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
7 ms |
992 KB |
Output is correct |
25 |
Correct |
5 ms |
860 KB |
Output is correct |
26 |
Correct |
11 ms |
1500 KB |
Output is correct |
27 |
Correct |
12 ms |
1500 KB |
Output is correct |
28 |
Correct |
7 ms |
992 KB |
Output is correct |
29 |
Correct |
11 ms |
1500 KB |
Output is correct |
30 |
Correct |
14 ms |
1500 KB |
Output is correct |
31 |
Correct |
11 ms |
1500 KB |
Output is correct |
32 |
Correct |
16 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
2 ms |
564 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
7 ms |
992 KB |
Output is correct |
25 |
Correct |
5 ms |
860 KB |
Output is correct |
26 |
Correct |
11 ms |
1500 KB |
Output is correct |
27 |
Correct |
12 ms |
1500 KB |
Output is correct |
28 |
Correct |
7 ms |
992 KB |
Output is correct |
29 |
Correct |
11 ms |
1500 KB |
Output is correct |
30 |
Correct |
14 ms |
1500 KB |
Output is correct |
31 |
Correct |
11 ms |
1500 KB |
Output is correct |
32 |
Correct |
16 ms |
1500 KB |
Output is correct |
33 |
Correct |
4 ms |
1496 KB |
Output is correct |
34 |
Correct |
9 ms |
1500 KB |
Output is correct |
35 |
Correct |
18 ms |
1500 KB |
Output is correct |
36 |
Correct |
13 ms |
1496 KB |
Output is correct |
37 |
Correct |
15 ms |
1500 KB |
Output is correct |
38 |
Correct |
12 ms |
1500 KB |
Output is correct |
39 |
Correct |
17 ms |
1500 KB |
Output is correct |
40 |
Correct |
17 ms |
1496 KB |
Output is correct |
41 |
Correct |
10 ms |
1500 KB |
Output is correct |
42 |
Correct |
15 ms |
1500 KB |
Output is correct |
43 |
Correct |
11 ms |
1500 KB |
Output is correct |
44 |
Correct |
12 ms |
1500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
2 ms |
564 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
7 ms |
992 KB |
Output is correct |
25 |
Correct |
5 ms |
860 KB |
Output is correct |
26 |
Correct |
11 ms |
1500 KB |
Output is correct |
27 |
Correct |
12 ms |
1500 KB |
Output is correct |
28 |
Correct |
7 ms |
992 KB |
Output is correct |
29 |
Correct |
11 ms |
1500 KB |
Output is correct |
30 |
Correct |
14 ms |
1500 KB |
Output is correct |
31 |
Correct |
11 ms |
1500 KB |
Output is correct |
32 |
Correct |
16 ms |
1500 KB |
Output is correct |
33 |
Correct |
4 ms |
1496 KB |
Output is correct |
34 |
Correct |
9 ms |
1500 KB |
Output is correct |
35 |
Correct |
18 ms |
1500 KB |
Output is correct |
36 |
Correct |
13 ms |
1496 KB |
Output is correct |
37 |
Correct |
15 ms |
1500 KB |
Output is correct |
38 |
Correct |
12 ms |
1500 KB |
Output is correct |
39 |
Correct |
17 ms |
1500 KB |
Output is correct |
40 |
Correct |
17 ms |
1496 KB |
Output is correct |
41 |
Correct |
10 ms |
1500 KB |
Output is correct |
42 |
Correct |
15 ms |
1500 KB |
Output is correct |
43 |
Correct |
11 ms |
1500 KB |
Output is correct |
44 |
Correct |
12 ms |
1500 KB |
Output is correct |
45 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
46 |
Halted |
0 ms |
0 KB |
- |