QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#108902 | #360. Cultivation | lmeowdn | 5 | 4ms | 3912kb | C++17 | 3.0kb | 2023-05-26 22:25:31 | 2023-05-26 22:25:37 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define popc __builtin_popcount
#define clz __builtin_clz
#define ctz __builtin_ctz
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef long double ld;
typedef unsigned long long ull;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
return x*w;
}
const int N=309,inf=1e12;
int R,C,n,f[N][N],g[N][N],h[N][N],k[N*N*2],tot,cnt,ans,sum;
int b[N*2],af[N*2],ag[N*2],ah[N*2];
struct node {int x,y;} a[N];
multiset<int>sh;
set<int>sp;
bool cmp(const node &a,const node &b) {
return a.x==b.x?a.y<b.y:a.x<b.x;
}
signed main() {
R=read(), C=read(), n=read(), ans=inf;
rep(i,1,n) a[i].x=read(), a[i].y=read();
sort(a+1,a+n+1,cmp); k[++tot]=0; k[++tot]=R-1;
rep(i,1,n) rep(j,1,n) if(a[i].x-a[j].x>0) k[++tot]=a[i].x-a[j].x-1;
rep(i,1,n) rep(j,1,n) if(R-a[i].x+a[j].x>0) k[++tot]=R-a[i].x+a[j].x-1;
sort(k+1,k+tot+1); tot=unique(k+1,k+tot+1)-k-1;
rep(l,1,n) {
sh.clear(), sp.clear(); int sf=inf, sg=inf;
rep(r,l,n) {
sf=min(sf,a[r].y-1), sg=min(sg,C-a[r].y);
auto it=sp.lower_bound(a[r].y);
if(it!=sp.begin()&&it!=sp.end()) {
auto tmp=it; int xl=*--tmp, xr=*it;
sh.erase(sh.find(xr-xl-1));
}
if(it!=sp.begin()) {
auto tmp=it; int xl=*--tmp;
sh.insert(a[r].y-xl-1);
}
if(it!=sp.end()) {
int xr=*it;
sh.insert(xr-a[r].y-1);
}
sp.insert(a[r].y);
if(sh.size()) h[l][r]=*sh.rbegin();
f[l][r]=sf, g[l][r]=sg;
}
}
rep(l,1,n+1) rep(r,1,n+1) if(l>r||l>n||r>n)
f[l][r]=g[l][r]=h[l][r]=inf;
rep(t,1,tot) {
rep(i,1,n) b[i]=a[i].x, b[i+n]=a[i].x+k[t]+1;
inplace_merge(b+1,b+n+1,b+2*n+1);
cnt=unique(b+1,b+2*n+1)-b-1;
int l=1, r=1, tick=0;
rep(i,1,cnt) {
while(l<=n&&a[l].x<b[i]-k[t]) ++l;
while(r<n&&a[r+1].x<=b[i]) ++r;
if(i==1||f[l][r]!=af[tick]||g[l][r]!=ag[tick]||h[l][r]!=ah[tick])
++tick, af[tick]=f[l][r], ag[tick]=g[l][r], ah[tick]=h[l][r], b[tick]=b[i];
}
cnt=tick;
static int qf[N*2],lf,rf; lf=1, rf=0;
static int qg[N*2],lg,rg; lg=1, rg=0;
static int qh[N*2],lh,rh; lh=1, rh=0;
int res=inf; sum+=cnt;
rep(i,1,cnt-1) {
while(lf<=rf&&af[qf[rf]]<=af[i]) --rf;
while(lg<=rg&&ag[qg[rg]]<=ag[i]) --rg;
while(lh<=rh&&ah[qh[rh]]<=ah[i]) --rh;
qf[++rf]=qg[++rg]=qh[++rh]=i;
while(lf<=rf&&b[i+1]-b[qf[lf]+1]>=R) ++lf;
while(lg<=rg&&b[i+1]-b[qg[lg]+1]>=R) ++lg;
while(lh<=rh&&b[i+1]-b[qh[lh]+1]>=R) ++lh;
int mf=af[qf[lf]], mg=ag[qg[lg]], mh=ah[qh[lh]];
if(b[i+1]-b[1]>=R&&mf<inf&&mg<inf&&mh<inf)
res=min(res,max(mf+mg,mh));
}
ans=min(ans,res+k[t]);
}
printf("%lld\n",ans);
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 3ms
memory: 3520kb
input:
2 4 2 1 1 1 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3524kb
input:
4 1 1 2 1
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 3ms
memory: 3536kb
input:
3 3 3 1 2 1 3 3 3
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 3ms
memory: 3656kb
input:
2 2 1 1 2
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3692kb
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: 3ms
memory: 3656kb
input:
4 4 1 4 1
output:
6
result:
ok single line: '6'
Test #7:
score: 0
Accepted
time: 3ms
memory: 3588kb
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: 3556kb
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: 4ms
memory: 3692kb
input:
4 3 3 2 1 2 3 4 1
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3544kb
input:
4 4 2 3 4 2 4
output:
5
result:
ok single line: '5'
Test #11:
score: 0
Accepted
time: 3ms
memory: 3600kb
input:
2 4 1 1 2
output:
4
result:
ok single line: '4'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3672kb
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: 3ms
memory: 3664kb
input:
3 4 3 1 4 3 3 3 4
output:
4
result:
ok single line: '4'
Test #14:
score: 0
Accepted
time: 2ms
memory: 3716kb
input:
3 3 2 2 1 3 3
output:
4
result:
ok single line: '4'
Test #15:
score: 0
Accepted
time: 4ms
memory: 3524kb
input:
4 4 2 2 4 3 1
output:
6
result:
ok single line: '6'
Test #16:
score: 0
Accepted
time: 3ms
memory: 3768kb
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: 10
Accepted
time: 2ms
memory: 3788kb
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:
13
result:
ok single line: '13'
Test #18:
score: 0
Accepted
time: 4ms
memory: 3780kb
input:
25 25 66 24 6 12 18 11 2 24 18 6 9 20 6 15 19 17 2 15 9 15 20 18 9 5 19 9 2 6 12 22 16 6 2 1 5 14 24 12 21 17 24 10 15 21 1 20 22 11 24 11 4 6 21 18 12 25 20 16 3 18 16 6 4 20 9 6 15 24 14 3 20 9 9 25 9 18 6 4 16 12 7 14 22 20 25 24 10 11 14 17 6 23 23 21 12 18 22 8 23 1 11 17 18 8 5 3 7 1 17 8 12 4...
output:
9
result:
ok single line: '9'
Test #19:
score: -10
Wrong Answer
time: 3ms
memory: 3760kb
input:
36 38 28 30 5 4 23 29 20 1 36 8 28 8 9 5 26 23 16 26 1 24 38 22 36 4 26 9 7 10 24 20 11 31 5 24 30 26 30 18 15 14 1 23 31 20 7 23 30 33 9 27 33 8 7 9 16 33 5
output:
2147483648
result:
wrong answer 1st lines differ - expected: '30', found: '2147483648'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #45:
score: 0
Wrong Answer
time: 4ms
memory: 3912kb
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:
2150278263
result:
wrong answer 1st lines differ - expected: '852626202', found: '2150278263'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%