QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#396757#5535. Popealasichengzhou#26 466ms93972kbC++143.0kb2024-04-23 10:01:032024-07-04 03:36:50

Judging History

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

  • [2024-07-04 03:36:50]
  • 评测
  • 测评结果:26
  • 用时:466ms
  • 内存:93972kb
  • [2024-04-23 10:01:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL inf=0x3f3f3f3f3f3f3f3f;
const int N=2e4+4,M=52;
int n,m,S;
LL f[M][N],s[N],c[M],p[N][M];
char ch[M][N];
LL st[M][N][15],lg[N];
void init(int x)
{
    lg[1]=0;
    for(int i=2;i<=m+1;i++)
    {
        lg[i]=lg[i/2]+1;
    }
    for(int j=0;j<=n;j++)
    {
        for(int i=0;i<=m;i++)
        {
            st[j][i][0]=f[x][i]-s[i]*j;
        }
        for(int k=1;k<=14;k++)
        {
            for(int i=0;i<=m;i++)
            {
                st[j][i][k]=min(st[j][i][k-1],st[j][i+(1<<(k-1))][k-1]);
            }
        }
    }
}
LL query(int k,int j,int x,int y)
{
//    cout<<'*'<<j<<' '<<x<<' '<<y<<'*';
/*    LL ret=inf;
    for(int i=x;i<=y;i++)
    {
        ret=min(ret,f[k][i]-j*s[i]);
    }
    return ret;*/
    return min(st[j][x][lg[y-x+1]],st[j][y-(1<<lg[y-x+1])+1][lg[y-x+1]]);
}
LL l[N],r[N],v[N];
int main()
{
    scanf("%d%d%d",&n,&m,&S);
    for(int i=1;i<=m;i++)
    {
        scanf("%lld",&s[i]);
        s[i]+=s[i-1];
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%s",ch[i]+1);
    }
    f[0][0]=0;
    for(int t=1;t<=n;t++)
    {
        c[t]=0;
    }
    for(int j=1;j<=m;j++)
    {
    for(int t=1;t<=n;t++)
    {
        if(ch[t][j]=='0')
        {
            c[t]=j;
        }
        p[j][t]=c[t];
    }
    sort(p[j]+1,p[j]+n+1);
    p[j][n+1]=j;
    }
    memset(f,0x3f,sizeof(f));
    f[0][0]=0;
    init(0);
    for(int i=1;i<=S;i++)
    {
    //    cout<<i<<endl;
        for(int k=0;k<=n;k++)
        {
            l[k]=0,r[k]=-1,v[k]=inf;
        }
        for(int j=1;j<=m;j++)
        {
            f[i][j]=inf;
            int pre=0;
            for(int k=1;k<=n+1;k++)
            {
            //    cout<<p[j][k]<<' ';
                if(pre==p[j][k])
                {
                    continue;
                }
                while(pre==l[k-1]&&r[k-1]<p[j][k]-1)
                {
                    r[k-1]++;
                    v[k-1]=min(v[k-1],f[i-1][r[k-1]]-(k-1)*s[r[k-1]]);
                }
                if(pre>r[k-1])
                {
                    v[k-1]=inf;
                    l[k-1]=pre;r[k-1]=pre-1;
                    while(r[k-1]<p[j][k]-1)
                    {
                    r[k-1]++;
                    v[k-1]=min(v[k-1],f[i-1][r[k-1]]-(k-1)*s[r[k-1]]);
                    }
                }
                f[i][j]=min(f[i][j],s[j]*(k-1)+v[k-1]);
                pre=p[j][k];
            }
        //    cout<<endl;
        //    cout<<i<<' '<<j<<' '<<f[i][j]<<endl;
        //    cout<<endl;
        /*    for(int k=j-1;k>=i-1;k--)
            {
                if(i==1&&k>0)
                {
                    continue;
                }
                cout<<j<<' '<<k<<' '<<f[i-1][k]+(s[j]-s[k])*cnt<<endl;
                f[i][j]=min(f[i][j],f[i-1][k]+(s[j]-s[k])*cnt);
            }*/
        }
        init(i);
        printf("%lld\n",f[i][m]);
    //    cout<<f[i][0]<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 8
Accepted

Test #1:

score: 8
Accepted
time: 0ms
memory: 22536kb

input:

2 3 3
4 3 5
101
110

output:

0
8
16

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 65688kb

input:

35 40 15
3657 2870 9633 4742 6403 1197 1327 9983 5095 1033 2356 2681 9948 6851 6494 1965 6698 5860 8718 3453 9739 5794 7452 9556 5798 5141 4009 1869 2474 6480 8270 6280 4446 8052 2155 3226 1667 843 2851 6305
1001111110101111111111111110111111111111
1111111111111111111111111111111111111111
1111111111...

output:

2237081
2324849
2390859
2474206
2512547
2586745
2634155
2721923
2787933
2965077
3067335
3199190
3273388
3320798
3497942

result:

ok 15 lines

Subtask #2:

score: 9
Accepted

Test #3:

score: 9
Accepted
time: 44ms
memory: 90560kb

input:

50 500 50
2038 388 7128 2805 5579 3731 7082 6271 5626 5928 8728 304 2767 8798 8311 8389 7924 1727 8612 7438 6588 7056 4588 3823 4615 4201 6337 370 1178 2694 7211 5841 6159 5419 7907 7080 1436 1867 4643 7361 1743 3185 9089 2317 593 9466 8700 9757 8776 8077 1274 1951 4362 1077 3344 2876 4067 1267 8350...

output:

0
95786
114798
244998
580014
717459
985251
1168070
1515088
1816096
2029416
2220312
2309682
2390264
2424480
2759496
2896941
3164733
3347552
3694570
3964964
4276878
4561422
4894290
5003990
5139573
5527629
5756985
5971037
6262492
6443498
6612787
6894109
7085248
7273926
7535859
7746387
8014179
8196998
8...

result:

ok 50 lines

Test #4:

score: 0
Accepted
time: 44ms
memory: 85908kb

input:

48 500 50
446 3830 1528 4330 8911 4558 846 2868 9188 1998 3322 1814 2987 5215 7205 9816 5235 4701 4702 6676 2319 1784 5640 9926 8364 4807 4576 1935 9599 4040 2345 1633 4142 6357 9262 9937 4120 3173 7766 9601 8936 3122 4307 4714 6174 6772 9560 3922 8704 5953 5511 2445 7737 4847 3210 886 6021 9644 803...

output:

0
21408
78954
207754
262858
446698
518514
726354
1052758
1260598
1379440
1514236
1803401
1987241
2059057
2266897
2437072
2676962
2919983
3054779
3409065
3587711
3747167
3834239
3977615
4217505
4548935
4878013
5209443
5467997
5688991
5975512
6111756
6195604
6455044
6809330
7115552
7538608
7744528
783...

result:

ok 50 lines

Test #5:

score: 0
Accepted
time: 44ms
memory: 91008kb

input:

50 500 50
6699 143 4520 2827 506 5190 6117 6490 2219 1723 8693 6430 268 7651 2239 5694 9812 7679 7286 919 6700 9632 2940 3900 9214 7738 3303 1608 8103 406 8651 1959 3280 9029 9278 8175 7398 1742 2818 5354 6941 7740 5687 2549 5345 2267 516 1112 3027 1353 238 8848 8516 1674 4127 8982 4214 1833 2398 94...

output:

0
75650
328273
403923
602803
686125
761775
1016085
1263535
1517845
1718599
1829161
2142083
2330921
2591745
2785985
3027953
3209469
3407613
3617926
3687751
3942061
4152895
4239093
4493403
4755137
4967314
5030524
5284834
5590684
5743514
5867414
6091442
6345752
6651602
6810900
6934800
7158828
7573484
7...

result:

ok 50 lines

Subtask #3:

score: 9
Accepted

Test #6:

score: 9
Accepted
time: 269ms
memory: 89224kb

input:

48 2200 50
337 3453 6137 1365 4085 2098 573 5755 4273 791 629 3815 1240 5977 8595 9987 9020 5999 9071 655 8343 4000 5410 3356 4673 7505 8440 259 5473 9902 7131 1896 8264 816 2911 1052 8757 5517 4111 9878 7684 3757 5880 6524 6338 7356 1354 3100 9447 8440 8994 4598 1942 7759 3915 3175 980 5528 3090 77...

output:

0
0
0
0
0
0
660
1718
3383
7088
12274
27776
53830
98036
155047
181101
309819
445072
559490
686254
836830
992254
1134321
1269574
1383992
1510756
1661332
1775704
1904422
2038217
2154093
2280857
2431433
2586857
2729260
2884684
3039287
3166051
3321475
3488325
3640414
3790990
3917932
4068508
4209483
43362...

result:

ok 50 lines

Test #7:

score: 0
Accepted
time: 372ms
memory: 93060kb

input:

50 3000 50
5950 9687 1494 6034 4761 8813 28 5374 6549 5784 7122 6628 7625 1592 8053 6314 9372 6900 648 6460 9268 1116 8934 4230 1174 7325 9231 2614 772 4884 4623 9657 1066 3497 7229 1688 8252 2304 5745 1326 9955 3210 8024 6132 3843 5064 2006 6419 71 2345 198 8006 1436 7082 1269 7055 9759 5497 6895 1...

output:

0
0
0
245
1568
12203
29667
79846
154150
252262
360356
458468
602146
700258
855538
993529
1104983
1252566
1350678
1505958
1643949
1764141
1943732
2063924
2253778
2462901
2583093
2772947
2989382
3146278
3362713
3520158
3736593
4006843
4193364
4383218
4628512
4756549
5002392
5130429
5400679
5674379
588...

result:

ok 50 lines

Test #8:

score: 0
Accepted
time: 466ms
memory: 93972kb

input:

50 4000 50
4834 5642 7536 3065 7147 350 2008 8039 3592 4684 3322 807 7023 2937 6910 1227 2027 164 2114 9086 8542 3383 552 4788 35 1988 3351 3344 1515 47 1778 5064 6486 3858 6470 8794 796 4418 93 8192 6908 6828 5856 8724 4727 5801 9128 149 9060 442 7609 4429 555 476 6766 8033 9525 7092 1087 9092 2261...

output:

0
0
960
3400
93350
160662
329266
374002
610868
736276
973142
1103078
1339944
1616402
1841701
1994630
2231496
2318246
2480630
2648601
2682901
2919767
3196225
3461989
3715674
3876356
3982056
4181769
4344330
4605432
4711132
5059032
5184080
5347130
5468027
5539945
5625289
5753285
5838629
6086765
6200903...

result:

ok 50 lines

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #9:

score: 0
Time Limit Exceeded

input:

48 20000 50
1549 695 1682 1506 1690 1775 1618 1612 1266 143 616 1765 8 478 1380 917 565 377 1666 483 25 1352 1436 47 865 885 1243 1364 13 880 722 1434 1839 707 1504 1694 285 1764 147 53 1261 854 130 1779 1770 245 1328 717 865 1423 1256 1697 1335 1435 342 1119 797 1005 1042 249 1406 781 1593 1326 770...

output:


result: