제출 #1357277

#제출 시각아이디문제언어결과실행 시간메모리
1357277Faisal_Saqib조교 (CEOI16_popeala)C++17
0 / 100
161 ms1628 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e4+10;
const ll inf=1e12;
#define int ll
int p[N];
ll rd[N][16];
int dp[N][51];
int getpc(int l,int r)
{

    int lg=__lg(r-l+1);
    return  __builtin_popcountll(rd[l][lg]&rd[r-(1<<lg)+1][lg]);
}
int cost(int l,int r)
{
   return (getpc(l,r)*(p[r]-p[l-1]));
}
int getmin(int l,int r,int j,int x)
{
    int s=l,e=r+1;
    while(s+1<e)
    {
        int m=(s+e)>>1;
        if(dp[m-2][j-1]-x*p[m-2] >=  dp[m-1][j-1]-x*p[m-1])
        {
            s=m;
        }
        else
        {
            e=m;
        }
    }
    return dp[s-1][j-1]-x*p[s-1];
    // int ans=inf;
    // for(int ip=l;ip<=r;ip++)
    // {
    //     ans=min(ans,dp[ip-1][j-1]-x*p[ip-1]);
    // }
    // return ans;
}
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,t,s;
    cin>>n>>t>>s;
    for(int i=1;i<=t;i++)
    {
        cin>>p[i];
        p[i]+=p[i-1];
    }
    for(int i=0;i<n;i++)
    {
        string q;
        cin>>q;
        for(int j=1;j<=t;j++)
        {
            if(q[j-1]=='1')
                rd[j][0]|=(1ll<<i);
        }
    }
    for(int j=1;j<16;j++)
    {
        for(int i=1;i+(1<<j)-1<=t;i++)
        {
            rd[i][j]=(rd[i][j-1]&rd[i+(1<<(j-1))][j-1]);
        }
    }
    for(int i=0;i<=t;i++)
    {
        for(int j=0;j<=s;j++)
        {
            dp[i][j]=inf;
        }
    }
    dp[0][0]=0;
    for(int i=1;i<=t;i++)
    {
        vector<pair<int,int>> ch;
        int lst=i;
        while(lst>0)
        {
            // ch.push_back(lst);
            int s=0,e=lst;
            while(s+1<e)
            {
                int m=(s+e)>>1;
                if(getpc(m,i)==getpc(lst,i))
                {
                    e=m;
                }
                else
                {
                    s=m;
                }
            }
            // int x=getpc(e,i);
            // dp[i][j]=
            ch.push_back({e,lst});
            lst=e-1;
        }
        // cout<<"for task "<<i<<endl;
        // for(auto [l,r]:ch)
        // {
        //     cout<<l<<' '<<r<<endl;
        // }
        // reverse(begin(ch),end(ch));
        for(int j=1;j<=s and j<=i;j++)
        {
            // ptr=
            for(auto [l,r]:ch)
            {
                // cout<<l<<' '<<r<<endl;
                int x=getpc(r,i);
                // as we progress in ch the x decreases
                dp[i][j]=min(dp[i][j],getmin(1,r,j,x) + x*p[i]);
            }
        }
    }
    // for(int j=1;j<=s;j++)
    // {
    //     for(int i=j;i<=t;i++)
    //     {
    //         for(int ip=j;ip<=i;ip++)
    //         {
    //             dp[i][j]=min(dp[i][j],dp[ip-1][j-1]+cost(ip,i));
    //         }
    //     }
    // }
    for(int j=1;j<=s;j++)
        cout<<dp[t][j]<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...