QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#96551 | #360. Cultivation | eyiigjkn | 5 | 3ms | 3736kb | C++14 | 2.6kb | 2023-04-14 14:16:14 | 2023-04-14 14:16:18 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
constexpr int INF=2e9;
int n,D[200010],X[610],id[310],pre[310],nxt[310],F[310][310],G[310][310],H[310][310],f[610],g[610],h[610];
multiset<int> st;
struct Node
{
int x,y;
bool operator<(const Node &t)const{return x<t.x;}
}a[310];
struct Queue
{
int l,r;
pii que[610];
Queue():l(0),r(0){}
void push(const pii &x)
{
while(l<r && que[r-1]<x) r--;
que[r++]=x;
}
void pop(int k)
{
while(l<r && que[l].first<=k) l++;
}
int top(){return l<r?que[l].first:INF;}
void clear(){l=r=0;}
}qF,qG,qH;
inline void chkmin(int &x,const int &y){x=min(x,y);}
inline void chkmax(int &x,const int &y){x=max(x,y);}
void del(int k)
{
if(pre[k]) st.erase(st.find(a[k].y-a[pre[k]].y-1));
if(nxt[k]<=n) st.erase(st.find(a[nxt[k]].y-a[k].y-1));
if(pre[k] && nxt[k]<=n) st.insert(a[nxt[k]].y-a[pre[k]].y-1);
pre[nxt[k]]=pre[k];
nxt[pre[k]]=nxt[k];
}
void add(int k){pre[nxt[k]]=nxt[pre[k]]=k;}
int main()
{
int R,C,ans=INF,tot=0;
cin>>R>>C>>n;
for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
sort(a+1,a+n+1);
iota(id+1,id+n+2,1);
sort(id+1,id+n+1,[](int i,int j){return a[i].y<a[j].y;});
for(int i=1;i<=n+1;i++) pre[id[i]]=id[i-1];
for(int i=0;i<=n;i++) nxt[id[i]]=id[i+1];
for(int i=1;i<=n;i++)
{
st={0};
for(int j=nxt[0];nxt[j]<=n;j=nxt[j]) st.insert(a[nxt[j]].y-a[j].y-1);
for(int j=n;j>=i;j--)
{
F[i][j]=a[nxt[0]].y-1;
G[i][j]=*st.rbegin();
H[i][j]=C-a[pre[n+1]].y;
del(j);
}
for(int j=i;j<=n;j++) add(j);
pre[nxt[i]]=pre[i];
nxt[pre[i]]=nxt[i];
}
for(int i=1;i<=n;i++)
for(int j=1;j<i && a[j].x<a[i].x;j++)
D[++tot]=a[i].x-a[j].x-1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
D[++tot]=(a[i].x-1)+(R-a[j].x);
sort(D+1,D+tot+1);
tot=unique(D+1,D+tot+1)-D-1;
for(int i=1;i<=tot;i++)
{
int d=D[i],cnt=0;
for(int j=1;j<=n;j++) X[++cnt]=a[j].x;
for(int j=1;j<=n;j++) X[++cnt]=a[j].x+d+1;
inplace_merge(X+1,X+n+1,X+cnt+1);
cnt=unique(X+1,X+cnt+1)-X-1;
for(int j=1,l=1,r=0;j<=cnt;j++)
{
while(l<=n && a[l].x+d<X[j]) l++;
while(r<n && a[r+1].x<=X[j]) r++;
if(l>r) f[j]=g[j]=h[j]=INF;
else f[j]=F[l][r],g[j]=G[l][r],h[j]=H[l][r];
}
for(int l=1,r=1;l<=cnt;l++)
{
for(;r<=cnt && X[r]-X[l]<R;r++)
{
qF.push({f[r],r});
qG.push({g[r],r});
qH.push({h[r],r});
}
int le=qF.top(),mx=qG.top(),ri=qH.top();
if(le<INF && mx<INF && ri<INF) chkmin(ans,d+max(le+ri,mx));
qF.pop(l);qG.pop(l);qH.pop(l);
}
qF.clear();qG.clear();qH.clear();
}
cout<<ans<<endl;
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 2ms
memory: 3648kb
input:
2 4 2 1 1 1 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
4 1 1 2 1
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
3 3 3 1 2 1 3 3 3
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
2 2 1 1 2
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3720kb
input:
4 4 10 4 2 2 3 2 4 4 1 1 2 2 1 4 3 3 3 3 1 1 4
output:
2
result:
ok single line: '2'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
4 4 1 4 1
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3624kb
input:
4 4 3 2 2 3 3 1 4
output:
5
result:
ok single line: '5'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3724kb
input:
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
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3580kb
input:
4 3 3 2 1 2 3 4 1
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 1ms
memory: 3496kb
input:
4 4 2 3 4 2 4
output:
5
result:
ok single line: '5'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3624kb
input:
2 4 1 1 2
output:
4
result:
ok single line: '4'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
3 3 4 2 1 1 1 3 2 3 1
output:
2
result:
ok single line: '2'
Test #13:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
3 4 3 1 4 3 3 3 4
output:
4
result:
ok single line: '4'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
3 3 2 2 1 3 3
output:
4
result:
ok single line: '4'
Test #15:
score: 0
Accepted
time: 1ms
memory: 3520kb
input:
4 4 2 2 4 3 1
output:
6
result:
ok single line: '6'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3540kb
input:
4 4 3 2 2 2 1 4 2
output:
4
result:
ok single line: '4'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #17:
score: 0
Wrong Answer
time: 3ms
memory: 3632kb
input:
15 15 20 6 13 14 4 11 13 15 3 12 4 10 4 11 6 8 9 12 12 2 15 4 3 8 15 8 4 3 1 5 10 11 12 8 7 13 10 11 4 1 3
output:
17
result:
wrong answer 1st lines differ - expected: '13', found: '17'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #45:
score: 0
Wrong Answer
time: 2ms
memory: 3736kb
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:
-2147262853
result:
wrong answer 1st lines differ - expected: '852626202', found: '-2147262853'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%