QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#396743#5535. Popealasichengzhou#8 4ms42852kbC++142.3kb2024-04-23 09:29:322024-07-04 03:36:47

Judging History

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

  • [2024-07-04 03:36:47]
  • 评测
  • 测评结果:8
  • 用时:4ms
  • 内存:42852kb
  • [2024-04-23 09:29:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e4+4,M=52;
int n,m,S,f[M][N],s[N],c[M],p[M][N];
char ch[M][N];
int 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]);
            }
        }
    }
}
int query(int j,int x,int y)
{
//    cout<<'*'<<j<<' '<<x<<' '<<y<<'*';
    return min(st[j][x][lg[y-x+1]],st[j][y-(1<<lg[y-x+1])+1][lg[y-x+1]]);
}
int main()
{
    scanf("%d%d%d",&n,&m,&S);
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&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;
    }
    for(int i=0;i<=S;i++)
    {
        for(int j=0;j<=m;j++)
        {
            f[i][j]=2e9+1;
        }
    }
    f[0][0]=0;
    init(0);
    for(int i=1;i<=S;i++)
    {
    //    cout<<i<<endl;
        for(int j=1;j<=m;j++)
        {
            f[i][j]=2e9+1;
            int pre=0;
            for(int k=1;k<=n+1;k++)
            {
            //    cout<<p[j][k]<<' ';
                if(pre==p[j][k])
                {
                    continue;
                }
                f[i][j]=min(f[i][j],s[j]*(k-1)+query(k-1,pre,p[j][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("%d\n",f[i][m]);
    //    cout<<f[i][0]<<endl;
    }
    return 0;
}

详细

Subtask #1:

score: 8
Accepted

Test #1:

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

input:

2 3 3
4 3 5
101
110

output:

0
8
16

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 4ms
memory: 42852kb

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: 0
Runtime Error

Test #3:

score: 0
Runtime Error

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:


result:


Subtask #3:

score: 0
Runtime Error

Test #6:

score: 0
Runtime Error

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:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%