QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#528307#8268. Tychobalpoint_pen0 1ms7808kbC++141.8kb2024-08-23 12:38:322024-08-23 12:38:32

Judging History

你现在查看的是最新测评结果

  • [2024-08-23 12:38:32]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:7808kb
  • [2024-08-23 12:38:32]
  • 提交

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+1,p-1);
			dp[i]=min(dp[i],y+(a[i]/p)*d-pi);
			x=sgt.qmin(1,0,p-1,pi,pi);
//			cout<<x<<endl;
			dp[i]=min(dp[i],x+(a[i]/p-1)*d-pi); 
		}
		sgt.upd(1,0,p-1,a[i]%p,dp[i]-a[i]/p*d+pi);
//		cout<<dp[i]+a[i]/p*d+pi<<'\n';
//		cout<<"# "<<dp[i]<<'\n';
	}
	cout<<dp[n]+b;
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 8
Accepted
time: 1ms
memory: 7692kb

input:

1000000000000 1 1000000 0

output:

1000000999999000000

result:

ok single line: '1000000999999000000'

Test #2:

score: 8
Accepted
time: 1ms
memory: 7768kb

input:

100 10 11 10
10
11
20
30
38
49
50
60
70
90

output:

122

result:

ok single line: '122'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 7764kb

input:

100 10 11 15
1
5
9
15
24
25
39
40
45
66
75
79
85
95
97

output:

135

result:

wrong answer 1st lines differ - expected: '138', found: '135'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 5
Accepted
time: 0ms
memory: 7752kb

input:

108 100 10000 5
10
20
30
40
98

output:

110

result:

ok single line: '110'

Test #12:

score: 5
Accepted
time: 0ms
memory: 7748kb

input:

118 100 10000 5
10
20
30
98
108

output:

120

result:

ok single line: '120'

Test #13:

score: 5
Accepted
time: 1ms
memory: 7808kb

input:

206 100 10000 5
10
20
30
98
196

output:

210

result:

ok single line: '210'

Test #14:

score: 0
Wrong Answer
time: 1ms
memory: 7684kb

input:

128 100 10000 5
10
20
98
108
118

output:

-9690

result:

wrong answer 1st lines differ - expected: '130', found: '-9690'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #109:

score: 15
Accepted
time: 0ms
memory: 7692kb

input:

1000000000000 1 1000000 0

output:

1000000999999000000

result:

ok single line: '1000000999999000000'

Test #110:

score: 15
Accepted
time: 0ms
memory: 7776kb

input:

108 100 10000 5
10
20
30
40
98

output:

110

result:

ok single line: '110'

Test #111:

score: 15
Accepted
time: 0ms
memory: 7740kb

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: 7752kb

input:

206 100 10000 5
10
20
30
98
196

output:

210

result:

ok single line: '210'

Test #113:

score: 0
Wrong Answer
time: 1ms
memory: 7688kb

input:

128 100 10000 5
10
20
98
108
118

output:

-9690

result:

wrong answer 1st lines differ - expected: '130', found: '-9690'

Subtask #5:

score: 0
Skipped

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

0%