QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#859756#9679. 盒子rotcar070 256ms13816kbC++142.4kb2025-01-17 22:52:282025-01-17 22:52:29

Judging History

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

  • [2025-01-17 22:52:29]
  • 评测
  • 测评结果:0
  • 用时:256ms
  • 内存:13816kb
  • [2025-01-17 22:52:28]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int N=5e5+5;
int n,m,k,c;
int a[N];
typedef long long ll;
ll sum[N];
int rt[N];
ll dp[5005][5005];
#define ls p<<1
#define rs p<<1|1
constexpr int inf=1e9;
struct seg{
    int t[N<<2],g[N<<2];
    inline void app(int p,int k){t[p]=min(t[p],k),g[p]=min(g[p],k);}
    inline void pd(int p){if(g[p]<inf)app(ls,g[p]),app(rs,g[p]),g[p]=inf;}
    void build(int p,int l,int r){
        t[p]=g[p]=inf;
        if(l==r) return;
        int mid=l+r>>1;
        build(ls,l,mid),build(rs,mid+1,r);
    }
    void modify(int p,int l,int r,int ql,int qr,int k){
        if(ql>qr) return;
        if(ql<=l&&r<=qr) return app(p,k);
        int mid=l+r>>1;pd(p);
        if(ql<=mid) modify(ls,l,mid,ql,qr,k);
        if(qr>mid) modify(rs,mid+1,r,ql,qr,k);
    }
    int query(int p,int l,int r,int k){
        if(l==r) return t[p];
        int mid=l+r>>1;pd(p);
        return k<=mid?query(ls,l,mid,k):query(rs,mid+1,r,k);
    }
}A;
inline void solve(){
    cin>>n>>m>>k>>c;
    vector<pair<int,int>> v;
    vector<int> tmp;
    for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+a[i],v.emplace_back(sum[i]%k,i),tmp.emplace_back(sum[i]%k);
    tmp.emplace_back(0);
    sort(tmp.begin(),tmp.end());tmp.erase(unique(tmp.begin(),tmp.end()));
    sort(v.begin(),v.end());
    int tt=tmp.size();
    auto lb=[&](const auto&x,const auto&v){return lower_bound(x.begin(),x.end(),v)-x.begin()+1;};
    if(k<=c) return cout<<sum[n]<<'\n',void();
    auto cal=[&](ll x){return x/k*c+min<ll>(x%k,c);};
    auto chk=[&](auto&x,auto y){(x>y)&&(x=y);};
    memset(rt,0x3f,sizeof(*rt)*(n+1));
    A.build(1,1,tt);
    for(int i=n-m+1;i>=0;i--){
        int x=sum[i+m-1]-k+1;
        int r=(x%k+k)%k;
        rt[i+1]=A.query(1,1,tt,lb(tmp,sum[i]%k));
        if(x<sum[i]){
            int xx=(sum[i]+k-1)%k,w=lb(tmp,xx+1)-1;
            if(r<=xx) A.modify(1,1,tt,lb(tmp,r),w,i+m);
            else A.modify(1,1,tt,lb(tmp,r),tt,i+m),A.modify(1,1,tt,1,w,i+m);
        }
    }
    // for(int i=1;i<=n;i++) cout<<rt[i]<<' ';cout<<'\n';
    for(int i=0;i<=n+1;i++)
    for(int j=0;j<=n+1;j++) dp[i][j]=1e18;
    dp[1][1]=0;
    for(int i=1;i<=n;i++)
    for(int j=1;j<=i;j++){
        chk(dp[i+1][i+1],dp[i][j]+cal(sum[i]-sum[j-1]));
        if(rt[j]>i+1) chk(dp[i+1][j],dp[i][j]);
    }
    cout<<dp[n+1][n+1]<<'\n';
}
int main(){
    int T;cin>>T;
    while(T--) solve();   
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 17
Accepted
time: 0ms
memory: 13816kb

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
6

result:

ok 3 number(s): "7 7 6"

Test #2:

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

input:

65
7 1 27 22
70 29 32 15 69 79 84
10 2 2 1
76 63 99 67 75 30 29 45 79 23
9 1 4 3
47 91 10 30 91 29 12 14 53
10 1 5 4
92 22 92 27 30 50 59 6 57 58
5 2 15 15
59 27 70 24 11
5 2 42 42
70 50 42 55 5
6 2 54 46
67 14 52 80 95 3
10 2 89 88
55 14 45 14 90 81 38 40 54 17
5 2 93 86
35 58 76 64 73
6 1 45 43
63...

output:

320
293
287
398
191
222
271
445
285
344
307
270
348
312
370
427
199
184
318
502
344
197
330
233
262
220
454
243
160
280
482
580
330
373
202
293
228
590
268
472
253
494
523
476
186
223
368
323
368
392
507
494
132
209
224
250
297
216
525
557
172
448
433
430
578

result:

wrong answer 40th numbers differ - expected: '475', found: '472'

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: 256ms
memory: 11732kb

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
8
4
13
8
3
8
13
3
4
6
10
8
5
11
13
9
14
5
7
5
11
11
4
3
9
7
4
6
5
6
4
5
12
5
9
3
5
10
12
6
6
14
15
4
7
13
14
7
5
7
6
9
5
3
10
8
8
7
6
7
5
11
6
6
5
6
7
4
9
9
9
6
4
4
5
7
6
6
13
6
10
12
5
4
10
13
7
3
7
5
4
7
9
8
13
4
4
8
10
6
6
6
15
10
13
11
3
4
6
7
5
11
13
6
15
13
8
7
10
7
14
11
7
6
9
10
10
8
4
5
7...

result:

wrong answer 47th numbers differ - expected: '14', found: '13'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%