QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859643#9679. 盒子xcyyyyy0 147ms12112kbC++141.9kb2025-01-17 21:20:542025-01-17 21:21:01

Judging History

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

  • [2025-01-17 21:21:01]
  • 评测
  • 测评结果:0
  • 用时:147ms
  • 内存:12112kb
  • [2025-01-17 21:20:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int a[500005];
long long S[500005];
long long f[500005];
int R[500005];
int sm[15000005],ls[15000005],rs[15000005],tot=0;
void fuzhi(int l,int r,int o,int ll,int rr,int z){
	if(l>=ll&&r<=rr){
		sm[o]=min(sm[o],z);
		return;
	}
	int mid=(l+r)>>1;
	if(mid>=ll){
		if(!ls[o])ls[o]=++tot,sm[tot]=1e9;
		fuzhi(l,mid,ls[o],ll,rr,z);
	}
	if(mid<rr){
		if(!rs[o])rs[o]=++tot,sm[tot]=1e9;
		fuzhi(mid+1,r,rs[o],ll,rr,z);
	}
}
int qiu(int l,int r,int o,int x){
	if(!o)return 1e9;
	if(l==r)return sm[o];
	int mid=(l+r)>>1,ans=sm[o];
	if(x<=mid)ans=min(ans,qiu(l,mid,ls[o],x));
	else ans=min(ans,qiu(mid+1,r,rs[o],x));
	return ans;
}
int n,m,k,c;
void upd(long long &x,long long y){x=min(x,y);}
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d%d",&n,&m,&k,&c);
		for(int i=1;i<=n;++i)scanf("%d",&a[i]),S[i]=S[i-1]+a[i];
		if(m==1){
			long long ans=0;
			for(int i=1;i<=n;++i){
				ans+=1ll*a[i]/k*c;
				ans+=min(c,a[i]%k);
			}
			printf("%lld\n",ans);
			continue;
		}
		for(int i=0;i<=n;++i)f[i]=1e18;
		f[n]=0;
		for(int i=1;i<=tot;++i)sm[i]=ls[i]=rs[i]=0;
		tot=1;sm[1]=n;
		for(int i=n;i>=1;--i){
			if(i+m<=n){
				int j=i+m;
				long long z=k+S[j-m]-S[j-1]-1;
				if(z>=0){
					int L=(S[j-m]-z)%k,R=S[j-m]%k;
					if(L<0)L+=k;
					if(R<0)R+=k;
					if(L<=R){
						fuzhi(0,k-1,1,L,R,j-1);
					}else{
						fuzhi(0,k-1,1,L,k-1,j-1);
						fuzhi(0,k-1,1,0,R,j-1);
					}
				}
			}
			R[i-1]=qiu(0,k-1,1,S[i-1]%k);
		}
		f[0] = 0;
		for(int i=1;i<=n;i++)f[i]=1e18;
		// for(int i=0;i<n;i++)std::cerr << R[i] << std::endl;
		for(int i=0;i<n;i++){
			int j=R[i];long long s;
			// std::cerr << i << " " << j << std::endl;
			s=S[j]-S[i];
			// upd(f[j],f[i]+s/k*c+s%k);
			upd(f[j],f[i]+(s+k-1)/k*c);
			s=S[j-m+1]-S[i];
			upd(f[j-m+2],f[i]+s/k*c+s%k);
		}
		// std::cerr << f[5] << std::endl;
		cout<<f[n]<<endl;
	}
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

3
5 2 4 3
2 2 1 2 2
4 2 4 3
2 4 1 1
10 3 5 1
2 2 2 2 1 1 1 10 2 2

output:

5
5
6

result:

wrong answer 1st numbers differ - expected: '7', found: '5'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 147ms
memory: 12112kb

input:

66664
7 2 82188055 1
35930054 4923258 36288509 46890418 53350617 49812938 68015568
10 2 460335201 1
305598063 240803174 36008172 416771728 391050572 270293987 333994588 436573185 216917970 103343453
9 3 119910901 1
35106715 29444257 72409421 49339248 23617992 3266647 38704192 75874356 72979434
10 1 ...

output:

5
7
4
13
8
2
8
13
3
3
6
10
8
5
11
13
9
14
4
7
4
11
11
4
3
9
6
4
6
5
6
4
4
12
5
9
3
5
10
12
5
6
14
15
4
7
14
14
7
5
7
6
9
5
2
10
8
8
7
5
7
5
11
6
6
5
6
7
4
9
9
9
5
4
4
4
7
6
6
13
6
10
12
4
3
10
14
7
2
7
4
4
6
9
8
13
4
4
8
10
6
6
5
15
10
15
11
3
3
5
7
5
11
13
6
16
13
8
6
10
7
14
11
7
6
9
10
10
8
4
4
7...

result:

wrong answer 2nd numbers differ - expected: '8', found: '7'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%