QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#426487 | #1961. Postman | MEKHANE | WA | 1ms | 7796kb | C++14 | 1.4kb | 2024-05-31 12:41:45 | 2024-05-31 12:41:45 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define mid (l+r)/2
using namespace std;
const int N=5e5+5,M=1e9;
int n,w,T,wz,rt,tot,t[30*N],ls[30*N],rs[30*N];
ll x[N],t1[30*N];
void add(int &k,int l,int r,int wz){
if(!k) k=++tot; t[k]++,t1[k]+=wz;
if(l==r){t[k]++; return ;}
if(wz<=mid) add(ls[k],l,mid,wz); else add(rs[k],mid+1,r,wz);
}
ll ef(int k,int l,int r,int gs){
if(l==r) return (t[k]<gs?1e18:gs*l);
if(t[ls[k]]<=gs) return t1[ls[k]]+ef(rs[k],mid+1,r,gs-t[ls[k]]);
else return ef(ls[k],l,mid,gs);
}
ll cl(){
sort(x+1,x+n+1); int fj=n,xj,sj; ll res=1e18,dans=0;
rep(i,1,n) if(x[i]>0){fj=i-1; break;}
if(fj==n) return 1e18;
if(fj) dans+=(-x[1])*2+x[n],xj=max(0,w-fj),sj=w-1;
else dans+=x[n],xj=w,sj=w;
if(xj>sj) return 1e18;
priority_queue<int,vector<int>,greater<int>> que;
rep(i,fj+1,n){
if((x[i]==wz||wz==0)&&n-i<=sj) res=min(res,dans+2*ef(rt,0,M,max(0,xj-(n-i)))+x[n]-x[i]);
if(i!=fj+1) add(rt,0,M,x[i]-x[i-1]);
}
rep(i,1,tot) t1[i]=t[i]=ls[i]=rs[i]=0;
tot=0; return res;
}
signed main(){
//freopen("postman.in","r",stdin);
// freopen("postman.out","w",stdout);
ios::sync_with_stdio(false);
cin>>n>>w>>T;
rep(i,1,n) cin>>x[i];
if(T==2) wz=x[n]; ll ans=cl();
rep(i,1,n) x[i]=-x[i];
w=n-w,wz=-wz,ans=min(ans,cl()),cout<<(ans==1e18?-1:ans);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7796kb
input:
100 0 1 751 558 131 292 317 886 785 847 224 668 649 358 725 250 953 65 176 733 461 84 114 977 628 673 798 863 373 827 51 630 518 347 527 876 366 241 452 670 813 314 846 342 357 460 985 581 841 843 282 907 327 656 411 944 421 99 441 388 568 763 167 351 793 916 517 109 999 390 272 639 513 534 304 253 ...
output:
999
result:
ok single line: '999'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7708kb
input:
100 50 1 654 349 533 94 619 754 498 939 469 518 3 661 431 214 195 198 989 548 561 312 262 629 807 981 624 639 178 765 706 782 888 611 553 363 336 91 176 485 735 791 596 455 390 760 995 202 417 82 798 883 209 155 725 908 789 56 49 899 231 423 815 228 314 400 748 946 736 840 385 446 938 284 10 917 593...
output:
1305
result:
wrong answer 1st lines differ - expected: '1397', found: '1305'