QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#859944 | #9679. 盒子 | phelixzhen_false | 0 | 42ms | 5860kb | C++20 | 2.3kb | 2025-01-18 08:46:42 | 2025-01-18 08:46:53 |
Judging History
answer
#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define siz(vec) ((int)(vec).size())
#define all(vec) (vec).begin(),(vec).end()
template<class T>
void operator +=(vec<T> &a,T b){a.push_back(b);}
template<class T>
void operator --(vec<T> &a){a.pop_back();}
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(exp) if(exp)continue;
#define stop(exp) if(exp)break;
#define ret(exp) if(exp)return;
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define debl(var) cerr<<#var<<'='<<(var)<<";\n"
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define int long long
#define inf (long long)(1e18)
template<class T>
bool Min(T &x,T y){return x>y?x=y,1:0;}
template<class T>
bool Max(T &x,T y){return x<y?x=y,1:0;}
const int mod=998244353;
void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,int y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans;
}
int n,m,k,c,a[500010],s[500010],f[500010];
void work(){
cin>>n>>m>>k>>c;
for(int i=1;i<=n;i++){
cin>>a[i];
s[i]=s[i-1]+a[i];
}
f[n+1]=0;
for(int i=n;i;i--){
f[i]=f[i+1]+a[i];
int lst=0,rem=0;
for(int j=i;j<=n;j++){
// [i,j] clearable
if(a[j]+rem<k){
if(!rem)lst=j;
rem+=a[j];
}else{
int r=a[j]-(k-rem);
if(rem&&j-lst+1>m){
break;
}
rem=r%k;lst=j;
}
if(rem&&j-lst+1>m){
break;
}
// Min(f[i],f[j+1]+(s[j]-s[i-1]+k-1)/k*c);
Min(f[i],f[j+1]+(s[j]-s[i-1])/k*c+(s[j]-s[i-1])%k);
}
}
cout<<f[1]<<'\n';
}
bool Med;
signed main(){
ios::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int T=1;cin>>T;while(T--)work();
// cerr<<"Time: "<<clock()<<" ms;\n";
// cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5860kb
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:
7 7 9
result:
wrong answer 3rd numbers differ - expected: '6', found: '9'
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: 42ms
memory: 5732kb
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:
48647200 449678892 160920462 1776942793 501616863 343756625 1556709978 1693702372 4413760 247985681 566463027 238979794 946842306 294766359 29016619 1464167929 659974547 811499878 1139717945 485716928 502574403 828723043 419392291 25738230 485398189 2490863 1018926006 154983048 394230315 207578034 4...
result:
wrong answer 1st numbers differ - expected: '5', found: '48647200'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%