#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;
if(lazy[idx]!=0) 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 |
23 ms |
62932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
62832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
62952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
63288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
65644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
86740 KB |
Output is correct |
2 |
Correct |
132 ms |
86896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
87016 KB |
Output is correct |
2 |
Correct |
110 ms |
86580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
63768 KB |
Output is correct |
2 |
Correct |
80 ms |
64108 KB |
Output is correct |
3 |
Correct |
69 ms |
64128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
335 ms |
68492 KB |
Output is correct |
2 |
Correct |
349 ms |
69352 KB |
Output is correct |
3 |
Correct |
289 ms |
69412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
759 ms |
92032 KB |
Output is correct |
2 |
Correct |
132 ms |
91460 KB |
Output is correct |
3 |
Correct |
270 ms |
64964 KB |
Output is correct |
4 |
Correct |
960 ms |
95648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1062 ms |
94676 KB |
Output is correct |
2 |
Correct |
1040 ms |
98032 KB |
Output is correct |
3 |
Correct |
720 ms |
89616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
971 ms |
92892 KB |
Output is correct |
2 |
Correct |
1315 ms |
100312 KB |
Output is correct |
3 |
Correct |
1327 ms |
99888 KB |
Output is correct |
4 |
Correct |
1288 ms |
100484 KB |
Output is correct |
5 |
Correct |
1299 ms |
100300 KB |
Output is correct |
6 |
Correct |
827 ms |
89080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5068 ms |
134220 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5090 ms |
143908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5104 ms |
152816 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |