#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1000005;
ll tree[4*N];
ll lazy[4*N];
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,int x)
{
if(ql>qr) return;
if(l==ql&&r==qr) apply(idx,ll(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<int,3>> v[m+2];
while(l<r-1)
{
int len=(l+r)/2;
bool ok=0;
int limm=m-len+1;
int limn=n-len+1;
auto add=[&](int x1,int y1,int x2,int y2,int 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),min(x2,limm),min(y2,limn),c);
for(int x=1;x<=limm+1;x++)
{
for(auto [y1,y2,c]:v[x]) update(1,1,limn,y1,y2,c);
if(x<=limm) ok|=(tree[1]<=b);
v[x].clear();
}
if(ok) l=len;
else r=len;
}
cout << l << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
7188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
34388 KB |
Output is correct |
2 |
Correct |
120 ms |
56708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
56772 KB |
Output is correct |
2 |
Correct |
50 ms |
38088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
2004 KB |
Output is correct |
2 |
Correct |
51 ms |
1768 KB |
Output is correct |
3 |
Correct |
40 ms |
1908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
178 ms |
10392 KB |
Output is correct |
2 |
Correct |
279 ms |
10152 KB |
Output is correct |
3 |
Correct |
225 ms |
10556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
48016 KB |
Output is correct |
2 |
Correct |
106 ms |
28656 KB |
Output is correct |
3 |
Correct |
245 ms |
35872 KB |
Output is correct |
4 |
Correct |
760 ms |
66636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
583 ms |
67112 KB |
Output is correct |
2 |
Correct |
938 ms |
68596 KB |
Output is correct |
3 |
Correct |
165 ms |
48096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
50924 KB |
Output is correct |
2 |
Correct |
1236 ms |
70916 KB |
Output is correct |
3 |
Correct |
1175 ms |
70604 KB |
Output is correct |
4 |
Correct |
1144 ms |
71044 KB |
Output is correct |
5 |
Correct |
1143 ms |
71120 KB |
Output is correct |
6 |
Correct |
105 ms |
48888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5044 ms |
95800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5039 ms |
101272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5033 ms |
106184 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |