QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#379790 | #8572. Passing Game | ucup-team266# | WA | 61ms | 27476kb | C++14 | 2.6kb | 2024-04-06 19:08:29 | 2024-04-06 19:08:30 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
ll X[301000],G[300100];
#define pi pair<ll,ll>
#define mp make_pair
const int I=1e9;
const ll I2=1e18;
#define pb push_back
#define F first
#define S second
ll d1[301000],d2[300100],o1[300100],o2[301000];
ll d1_[301000],d2_[301000];
int s1,s2;
pi sta[301000];int top;
pi operator - (const pi &a,const pi &b){return mp(a.F-b.F,a.S-b.S);}
__int128 cro(pi a,pi b){return ((__int128)a.F)*b.S-((__int128)b.F)*a.S;}
ll E(pi a,ll x){return a.F*x+a.S;}
void sol(){
scanf("%d%d",&n,&m);m=min(m,128);
vector<pi>v1,v2;
for(int i=1;i<=n;i++)scanf("%lld",&X[i]);
for(int i=1;i<=n;i++)scanf("%lld",&G[i]);
if(n==1){puts("0");return;}
if(X[1]>X[n]){for(int i=1;i<=n;i++)X[i]=I+1-X[i];}
for(int i=2;i<n;i++){
if(X[i]>X[n])continue;
if(X[i]<X[1])v1.pb(mp(X[1]-X[i],G[i]));
else v2.pb(mp(X[i]-X[1],G[i]));
}
sort(v1.begin(),v1.end()),sort(v2.begin(),v2.end());
vector<pi>fz;
ll ns=G[1];
for(pi e:v1)if(ns>e.S)ns=e.S,fz.pb(e);v1=fz;
fz.clear();
ns=G[1];
for(pi e:v2)if(ns>e.S)ns=e.S,fz.pb(e);v2=fz;
ll ans=(X[n]-X[1])*G[1];
s1=v1.size(),s2=v2.size();
d1[0]=d2[0]=0;
for(int i=1;i<=s1;i++)o1[i]=((i>1)?v1[i-2].S:G[1])*(v1[i-1].F-((i>1)?v1[i-2].F:0)),d1[i]=d1[i-1]+o1[i];
for(int i=1;i<=s2;i++)o2[i]=((i>1)?v2[i-2].S:G[1])*(v2[i-1].F-((i>1)?v2[i-2].F:0)),d2[i]=d2[i-1]+o2[i];
if(s2)ans=min(ans,d2[s2]+v2[s2-1].S*(X[n]-X[1]-v2[s2-1].F));
for(int e=1;e<=m;e++){
if(e&1){for(int i=1;i<=s1;i++)ans=min(ans,d1[i]+(X[n]-X[1]+v1[i-1].F)*v1[i-1].S);}
else{for(int i=1;i<=s2;i++)ans=min(ans,d2[i]+(X[n]-X[1]-v2[i-1].F)*v2[i-1].S);}
for(int i=1;i<=s1;i++)d1_[i]=I2;for(int i=1;i<=s2;i++)d2_[i]=I2;
//d1_i+S[i](X[i]+X[j])->d2[j]
top=0;
for(int i=s1;i;i--){
pi ut=mp(v1[i-1].S,d1[i]+v1[i-1].S*v1[i-1].F);
while(top&&cro(sta[top]-sta[top-1],ut-sta[top])<=0)top--;
sta[++top]=ut;
}
for(int i=s2,j=1;i;i--){
ll A=v2[i-1].F;
while(j<top&&E(sta[j],A)>E(sta[j+1],A))j++;
d2_[i]=min(d2_[i],E(sta[j],A));
}
top=0;
for(int i=s2;i;i--){
pi ut=mp(v2[i-1].S,d2[i]+v2[i-1].S*v2[i-1].F);
while(top&&cro(sta[top]-sta[top-1],ut-sta[top])<=0)top--;
sta[++top]=ut;
}
for(int i=s1,j=1;i;i--){
ll A=v1[i-1].F;
while(j<top&&E(sta[j],A)>E(sta[j+1],A))j++;
d1_[i]=min(d1_[i],E(sta[j],A));
}
for(int i=2;i<=s1;i++)d1_[i]=min(d1_[i],d1_[i-1]+o1[i]);
for(int i=2;i<=s2;i++)d2_[i]=min(d2_[i],d2_[i-1]+o2[i]);
for(int i=1;i<=s1;i++)d1[i]=d1_[i];
for(int i=1;i<=s2;i++)d2[i]=d2_[i];
}
printf("%lld\n",ans);
}
int main(){
int T;scanf("%d",&T);
while(T--)sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 18080kb
input:
2 4 2 3 2 1 6 3 1 1 3 2 0 1 2 1 2
output:
7 1
result:
ok 2 number(s): "7 1"
Test #2:
score: 0
Accepted
time: 61ms
memory: 27476kb
input:
1 300000 204334 809492393 304618667 173130445 377106790 364888630 949045125 622060683 557772818 216607577 848817467 862855568 507840723 120816645 639713488 741781998 682531787 685261161 601686403 355792373 162819930 710057718 234560726 998604853 678957602 485413982 855985802 109303681 979706626 4822...
output:
31313390701066
result:
ok 1 number(s): "31313390701066"
Test #3:
score: -100
Wrong Answer
time: 42ms
memory: 21540kb
input:
3 100000 65460 217141764 710454586 789075415 24849107 685675008 839804815 638763480 327755609 43827967 390187172 301370841 622696676 598237196 232099091 211987715 416876077 572665966 73382836 520033984 808399404 752832432 341795744 434460344 535426588 136624537 997406768 297342165 558882675 26863877...
output:
80618298664266 47230361360721 59110547802683
result:
wrong answer 1st numbers differ - expected: '70635841128944', found: '80618298664266'