Submission #924349

# Submission time Handle Problem Language Result Execution time Memory
924349 2024-02-08T21:27:34 Z JakobZorz Popeala (CEOI16_popeala) C++17
17 / 100
2000 ms 64080 KB
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
 
int n,t,s;
int pts[20000];
int done[50][20000];
ll dp[51][20001];
const int TREE_SIZE=1<<15;

struct Tree{
    vector<ll>tree,lazy;
    
    void build(vector<ll>init){
        tree=vector<ll>(2*TREE_SIZE);
        lazy=vector<ll>(2*TREE_SIZE);
        for(int i=0;i<int(init.size());i++)
            tree[TREE_SIZE+i]=init[i];
        for(int i=TREE_SIZE-1;i>0;i--)
            tree[i]=min(tree[2*i],tree[2*i+1]);
    }
    
    void push(int node){
        if(lazy[node]){
            tree[node]+=lazy[node];
            if(node<TREE_SIZE){
                lazy[2*node]+=lazy[node];
                lazy[2*node+1]+=lazy[node];
            }
            lazy[node]=0;
        }
    }
    
    void add(int node,int rl,int rr,int l,int r,ll x){
        push(node);
        if(r<=rl||rr<=l)
            return;
        if(l<=rl&&rr<=r){
            lazy[node]+=x;
            push(node);
            return;
        }
        
        int mid=(rl+rr)/2;
        add(2*node,rl,mid,l,r,x);
        add(2*node+1,mid,rr,l,r,x);
        tree[node]=min(tree[2*node],tree[2*node+1]);
    }
    
    void add(int l,int r,ll x){
        add(1,0,TREE_SIZE,l,r,x);
    }
    
    ll get_min(int node,int rl,int rr,int l,int r){
        push(node);
        if(r<=rl||rr<=l)
            return 1e18;
        if(l<=rl&&rr<=r)
            return tree[node];
        
        int mid=(rl+rr)/2;
        return min(get_min(2*node,rl,mid,l,r),get_min(2*node+1,mid,rr,l,r));
    }
    
    ll get_min(int l,int r){
        return get_min(1,0,TREE_SIZE,l,r);
    }
};

Tree cost[51];

void solve(){
    cin>>n>>t>>s;
    for(int i=0;i<t;i++)
        cin>>pts[i];
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        for(int j=0;j<t;j++){
            if(str[j]=='1'){
                if(j)
                    done[i][j]=done[i][j-1]+1;
                else
                    done[i][j]=1;
            }
        }
    }
    
    for(int i=0;i<51;i++)
        for(int j=0;j<20001;j++)
            dp[i][j]=1e18;
    
    dp[0][0]=0;
    
    for(int num=1;num<=s;num++){
        for(int p=0;p<=n;p++){
            vector<ll>init;
            for(int i=0;i<=t;i++)
                init.push_back(dp[num-1][i]);
            cost[p].build(init);
        }
        
        for(int i=0;i<=t;i++){
            if(i){
                vector<int>vec;
                vec.push_back(i);
                vec.push_back(0);
                for(int p=0;p<n;p++)
                    vec.push_back(done[p][i-1]);
                sort(vec.begin(),vec.end());
                reverse(vec.begin(),vec.end());
                for(int j=0;j<=n;j++){
                    dp[num][i]=min(dp[num][i],cost[j].get_min(i-vec[j],i-vec[j+1]));
                }
            }
            
            for(int p=0;p<=n;p++){
                cost[p].add(0,i+1,pts[i]*p);
            }
        }
    }
    
    for(int i=0;i<s;i++)
        cout<<dp[i+1][t]<<"\n";
}
 
int main(){
    ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
    //freopen("input.in","r",stdin);freopen("output.out","w",stdout);
    int t=1;//cin>>t;
    while(t--)solve();
    return 0;
}
 
/*
 
2 3 3
4 3 5
101
110
 
 
0
8
16
 
 */
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12380 KB Output is correct
2 Correct 80 ms 48476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 736 ms 63836 KB Output is correct
2 Correct 680 ms 62056 KB Output is correct
3 Correct 720 ms 64080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2025 ms 62288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 12380 KB Output is correct
2 Correct 80 ms 48476 KB Output is correct
3 Correct 736 ms 63836 KB Output is correct
4 Correct 680 ms 62056 KB Output is correct
5 Correct 720 ms 64080 KB Output is correct
6 Execution timed out 2025 ms 62288 KB Time limit exceeded
7 Halted 0 ms 0 KB -