#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
vector<ll> tree(4*N,0);
vector<ll> lazy(4*N,0);
void pull(int idx){tree[idx]=min(tree[2*idx],tree[2*idx+1]);}
void apply(int idx,ll x){tree[idx]+=x; lazy[idx]+=x;}
void push(int idx){for(int i=0;i<2;i++)apply(2*idx+i,lazy[idx]); lazy[idx]=0;}
void update(int idx,int l,int r,int ql,int qr,ll x)
{
if(ql>qr) return;
if(l==ql&&r==qr) apply(idx,x);
else
{
int m=(l+r)/2;
push(idx);
update(2*idx,l,m,ql,min(qr,m),x);
update(2*idx+1,m+1,r,max(ql,m+1),qr,x);
pull(idx);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin >> m >> n;
int b,p;
cin >> b >> p;
vector<array<int,5>> obstacles(p);
for(auto &[x1,y1,x2,y2,c]:obstacles) cin >> x1 >> y1 >> x2 >> y2 >> c;
int l=0,r=min(n,m)+1;
vector<array<ll,3>> v[m+2];
const ll inf=(1ll<<32);
while(l<r-1)
{
int len=(l+r)/2;
bool ok=0;
auto add=[&](int x1,int y1,int x2,int y2,ll c)
{
v[x1].push_back({y1,y2,c});
v[x2+1].push_back({y1,y2,-c});
};
for(auto [x1,y1,x2,y2,c]:obstacles) add(max(1,x1-len+1),max(1,y1-len+1),x2,y2,c);
if(len>1)
{
add(1,n-len+2,m,n,inf);
add(m-len+2,1,m,n,inf);
}
for(int x=1;x<=m+1;x++)
{
for(auto [y1,y2,c]:v[x]) update(1,1,n,y1,y2,c);
if(x<=m) ok|=(tree[1]<=b);
v[x].clear();
}
if(ok) l=len;
else r=len;
}
cout << l << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
62932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
62924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
62960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
63316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
65612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
86936 KB |
Output is correct |
2 |
Correct |
142 ms |
87020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
121 ms |
87020 KB |
Output is correct |
2 |
Correct |
101 ms |
86560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
63852 KB |
Output is correct |
2 |
Correct |
76 ms |
64140 KB |
Output is correct |
3 |
Correct |
73 ms |
64236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
68852 KB |
Output is correct |
2 |
Correct |
344 ms |
69724 KB |
Output is correct |
3 |
Correct |
287 ms |
69736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
813 ms |
92488 KB |
Output is correct |
2 |
Correct |
131 ms |
91852 KB |
Output is correct |
3 |
Correct |
306 ms |
65460 KB |
Output is correct |
4 |
Correct |
922 ms |
96376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1026 ms |
95480 KB |
Output is correct |
2 |
Correct |
963 ms |
98780 KB |
Output is correct |
3 |
Correct |
723 ms |
90404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1014 ms |
93884 KB |
Output is correct |
2 |
Correct |
1291 ms |
101056 KB |
Output is correct |
3 |
Correct |
1285 ms |
100864 KB |
Output is correct |
4 |
Correct |
1269 ms |
101192 KB |
Output is correct |
5 |
Correct |
1294 ms |
101096 KB |
Output is correct |
6 |
Correct |
972 ms |
90036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5026 ms |
138840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5044 ms |
152696 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5055 ms |
164708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |