QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211668 | #360. Cultivation | Rafi22# | 0 | 0ms | 3652kb | C++14 | 1.7kb | 2023-10-12 20:11:30 | 2024-07-04 02:19:25 |
answer
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000007;
ll infl=1000000000000000007;
int mod=1000000007;
int mod1=998244353;
const int N=307;
int r,c,n;
int ans=inf;
int x[N],y[N];
void check(int U,int D)
{
set<pair<int,int>>X;
vector<pair<int,int>>E;
int S=0,L=0,R=0;
for(int i=1;i<=n;i++)
{
if(max(1,x[i]-D)==1) X.insert({y[i],i});
else E.pb({max(1,x[i]-D),-i});
if(min(r,x[i]+U)<r) E.pb({min(r,x[i]+U)+1,i});
}
if(sz(X)==0) return ;
R=(*X.begin()).st-1;
L=c-(*--X.end()).st;
int last=-1;
for(auto [Y,i]:X)
{
if(last!=-1) S=max(S,Y-last-1);
last=Y;
}
X.insert({-inf,0});
X.insert({inf,0});
sort(all(E));
for(auto [t,i]:E)
{
if(i<0) X.insert({y[-i],-i});
else
{
X.erase({y[i],i});
if(sz(X)==2) return ;
int LL=(*--X.upper_bound({y[i],0})).st;
int RR=(*X.upper_bound({y[i],0})).st;
if(LL==-inf) R=max(R,RR-1);
if(RR==inf) L=max(L,c-LL);
if(LL!=-inf&&RR!=inf) S=max(S,RR-LL-1);
}
}
ans=min(ans,U+D+max(S,R+L));
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>r>>c>>n;
for(int i=1;i<=n;i++) cin>>x[i]>>y[i];
check(0,0);
// for(int i=0;i<=r;i++) for(int j=0;j<=r;j++) check(i,j);
cout<<ans;
return 0;
}
/*
4 4
15
4 3
2 4
4 4
4 1
3 3
1 2
3 1
2 1
3 4
3 2
4 2
2 3
1 3
2 2
1 4
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
2 4 2 1 1 1 4
output:
1000000007
result:
wrong answer 1st lines differ - expected: '3', found: '1000000007'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #45:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
1000000000 1000000000 17 822413671 70423910 260075513 431043546 300945721 793553248 142848049 163787897 392462410 831950868 699005697 111397300 444396260 130450496 642691616 595456084 467968916 463598810 159764248 611476406 929313754 539645102 365153650 964108073 906780716 373514044 970118116 655138...
output:
1000000007
result:
wrong answer 1st lines differ - expected: '852626202', found: '1000000007'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%