Submission #874903

# Submission time Handle Problem Language Result Execution time Memory
874903 2023-11-18T05:02:46 Z Faisal_Saqib Popeala (CEOI16_popeala) C++17
17 / 100
452 ms 262144 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct SegmentTree
{
    int sum=0;
    int lazy=0;
    int s,e;
    SegmentTree* next[2];
    SegmentTree(int l,int r)
    {
        s=l;
        e=r;
        if(s!=e)
        {
            int mid=(s+e)/2;
            next[0]=new SegmentTree(s,mid);
            next[1]=new SegmentTree(mid+1,e);
        }
    }
    void push()
    {
        if(lazy==0)
            return;
        sum+=(e-s+1)*lazy;
        if(s!=e)
        {
            next[0]->lazy+=lazy;
            next[1]->lazy+=lazy;
        }
        lazy=0;
    }
    void pull()
    {        
        sum=(next[0]->sum+next[1]->sum);
    }
    void Update(int l,int r)
    {
        if(l>r)
            return;
        push();
        if(r<s or e<l)
            return;
        if(l<=s and e<=r)
        {
            lazy++;
            push();
            return;
        }
        next[0]->Update(l,r);
        next[1]->Update(l,r);
        pull();
    }
    int get(int l,int r)
    {
        push();
        if(r<s or e<l)
            return 0;
        if(l<=s and e<=r)
            return sum;
        return (next[0]->get(l,r)+next[1]->get(l,r));
    }
};
const int T=2e4+10;
const int N=52;
const int inf=2e9+1;
int points[1];
string results[N];
int pre[T];
int ptr[N];
int zero[N];
SegmentTree* zeros[T];
int dp[T][N];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,t,s;
    cin>>n>>t>>s;
    for(int i=0;i<t;i++)
    {
        cin>>points[0];
        zeros[i+1]=new SegmentTree(1,t);
        pre[i+1]=pre[i]+points[0];
    }
    for(int i=0;i<n;i++)
        cin>>results[i];
    for(int i=0;i<=t;i++)
        for(int j=0;j<=s;j++)
            dp[i][j]=inf;       
    dp[0][0]=0;
    for(int r=1;r<=t;r++)
    {
        for(int i=0;i<n;i++)
        {
            if(results[i][r-1]=='0')
                zero[i]=max(zero[i],r);
            zeros[r]->Update(zero[i]+1,r);
        }
    }   
    for(int i=0;i<t;i++)
    {
        for(int j=0;j<s;j++)
        {
            if(dp[i][j]==inf)
                continue;
            for(int new_i=i+1;new_i<=t;new_i++)
            {
                dp[new_i][j+1]=min(dp[new_i][j+1],dp[i][j]+(pre[new_i]-pre[i])*zeros[new_i]->get(i+1,i+1));
            }
        }
    }
    for(int j=1;j<=s;j++)
        cout<<dp[t][j]<<'\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 396 ms 25948 KB Output is correct
2 Correct 443 ms 26196 KB Output is correct
3 Correct 452 ms 25944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 172 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 396 ms 25948 KB Output is correct
4 Correct 443 ms 26196 KB Output is correct
5 Correct 452 ms 25944 KB Output is correct
6 Runtime error 172 ms 262144 KB Execution killed with signal 9
7 Halted 0 ms 0 KB -