QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#528293 | #8268. Tycho | balpoint_pen | 0 | 1ms | 7756kb | C++14 | 1.6kb | 2024-08-23 12:32:01 | 2024-08-23 12:32:04 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
struct Segtree{
int tr[N<<2];
void upd(int p,int l,int r,int x,int y){
if(l==r){
tr[p]=min(tr[p],y);
return ;
}
int mid=l+r>>1;
if(x<=mid)upd(p<<1,l,mid,x,y);
else upd(p<<1|1,mid+1,r,x,y);
tr[p]=min(tr[p<<1],tr[p<<1|1]);
}
int qmin(int p,int l,int r,int ql,int qr){
if(ql>qr||ql>r||qr<l||qr<0)return 9e18;
if(ql<=l&&r<=qr)return tr[p];
int mid=l+r>>1;
if(qr<=mid)return qmin(p<<1,l,mid,ql,qr);
if(ql>mid)return qmin(p<<1|1,mid+1,r,ql,qr);
return min(qmin(p<<1,l,mid,ql,mid),qmin(p<<1|1,mid+1,r,mid+1,qr));
}
}sgt;
int b,p,d,n;
int a[N],dp[N];
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>b>>p>>d>>n;
for(int i=1;i<=n;i++)cin>>a[i];
a[++n]=b;
for(int i=1;i<=n;i++)dp[i]=9e18;
for(int i=1;i<=4*p;i++)sgt.tr[i]=9e18;
sgt.upd(1,0,p-1,0,0);dp[0]=0;
for(int i=1;i<=n;i++){
int pi=a[i]%p;
if(i==n){
for(int j=0;j<i;j++){
int ds=a[i]-a[j];
if(ds%p==0)dp[i]=min(dp[i],dp[j]+(ds/p-1)*d+(i!=n)*(p-ds%p)%p);
else dp[i]=min(dp[i],dp[j]+(ds/p)*d+(i!=n)*(p-ds%p)%p);
}
// int x=sgt.qmin(1,0,p-1,0,pi);
// dp[i]=min(dp[i],x+(a[i]/p-1)*d);
// int y=sgt.qmin(1,0,p-1,pi+1,p-1);
// dp[i]=min(dp[i],y+(a[i]/p)*d);
}
else{
int x=sgt.qmin(1,0,p-1,0,pi-1);
if(a[i]<=p)dp[i]=min(dp[i],x+(a[i]/p)*d+p-pi);
else dp[i]=min(dp[i],x+(a[i]/p-1)*d+p-pi);
int y=sgt.qmin(1,0,p-1,pi,p-1);
dp[i]=min(dp[i],y+(a[i]/p)*d-pi);
}
sgt.upd(1,0,p-1,a[i]%p,dp[i]+a[i]/p*d+pi);
// cout<<"# "<<dp[i]<<'\n';
}
cout<<dp[n]+b;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 1ms
memory: 7756kb
input:
1000000000000 1 1000000 0
output:
1000000999999000000
result:
ok single line: '1000000999999000000'
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 7752kb
input:
100 10 11 10 10 11 20 30 38 49 50 60 70 90
output:
189
result:
wrong answer 1st lines differ - expected: '122', found: '189'
Subtask #2:
score: 0
Wrong Answer
Test #11:
score: 5
Accepted
time: 0ms
memory: 7740kb
input:
108 100 10000 5 10 20 30 40 98
output:
110
result:
ok single line: '110'
Test #12:
score: 5
Accepted
time: 1ms
memory: 7752kb
input:
118 100 10000 5 10 20 30 98 108
output:
120
result:
ok single line: '120'
Test #13:
score: 5
Accepted
time: 0ms
memory: 7680kb
input:
206 100 10000 5 10 20 30 98 196
output:
210
result:
ok single line: '210'
Test #14:
score: 5
Accepted
time: 1ms
memory: 7744kb
input:
128 100 10000 5 10 20 98 108 118
output:
130
result:
ok single line: '130'
Test #15:
score: 5
Accepted
time: 1ms
memory: 7668kb
input:
206 100 10000 5 10 20 98 108 196
output:
210
result:
ok single line: '210'
Test #16:
score: 5
Accepted
time: 1ms
memory: 7740kb
input:
216 100 10000 5 10 20 98 196 206
output:
220
result:
ok single line: '220'
Test #17:
score: 0
Wrong Answer
time: 1ms
memory: 7740kb
input:
304 100 10000 5 10 20 98 196 294
output:
10308
result:
wrong answer 1st lines differ - expected: '310', found: '10308'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #109:
score: 15
Accepted
time: 1ms
memory: 7680kb
input:
1000000000000 1 1000000 0
output:
1000000999999000000
result:
ok single line: '1000000999999000000'
Test #110:
score: 15
Accepted
time: 1ms
memory: 7740kb
input:
108 100 10000 5 10 20 30 40 98
output:
110
result:
ok single line: '110'
Test #111:
score: 15
Accepted
time: 1ms
memory: 7736kb
input:
118 100 10000 5 10 20 30 98 108
output:
120
result:
ok single line: '120'
Test #112:
score: 15
Accepted
time: 1ms
memory: 7684kb
input:
206 100 10000 5 10 20 30 98 196
output:
210
result:
ok single line: '210'
Test #113:
score: 15
Accepted
time: 1ms
memory: 7748kb
input:
128 100 10000 5 10 20 98 108 118
output:
130
result:
ok single line: '130'
Test #114:
score: 15
Accepted
time: 1ms
memory: 7672kb
input:
206 100 10000 5 10 20 98 108 196
output:
210
result:
ok single line: '210'
Test #115:
score: 15
Accepted
time: 1ms
memory: 7752kb
input:
216 100 10000 5 10 20 98 196 206
output:
220
result:
ok single line: '220'
Test #116:
score: 0
Wrong Answer
time: 1ms
memory: 7736kb
input:
304 100 10000 5 10 20 98 196 294
output:
10308
result:
wrong answer 1st lines differ - expected: '310', found: '10308'
Subtask #5:
score: 0
Skipped
Dependency #2:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%