QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211656 | #360. Cultivation | Rafi22# | 0 | 1ms | 3608kb | C++14 | 1.7kb | 2023-10-12 19:58:04 | 2024-07-04 02:19:23 |
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});
// cout<<max(1,x[i]-D)<<" "<<min(r,x[i]+U)<<endl;
}
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;
if(LL==-inf) R=max(L,LL-1);
int RR=(*X.upper_bound({y[i],0})).st;
if(RR==inf) L=max(R,c-RR);
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];
for(int i=0;i<=r;i++) for(int j=0;j<=r;j++) check(i,j);
cout<<ans;
return 0;
}
/*
2 4
2
1 1
1 4
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 1ms
memory: 3608kb
input:
2 4 2 1 1 1 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
4 1 1 2 1
output:
3
result:
ok single line: '3'
Test #3:
score: -5
Wrong Answer
time: 0ms
memory: 3480kb
input:
3 3 3 1 2 1 3 3 3
output:
1
result:
wrong answer 1st lines differ - expected: '3', found: '1'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Time Limit Exceeded
Test #45:
score: 0
Time Limit Exceeded
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:
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%