Submission #968344

# Submission time Handle Problem Language Result Execution time Memory
968344 2024-04-23T10:27:42 Z berr Popeala (CEOI16_popeala) C++17
26 / 100
447 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4+30;
 
int r[N][N];
int gh[57][57];
vector<int> v;
 int s, t;
long long dis[N][55];

auto calc(int ri, int l, int f){
    if(l<=t && f <= s && ri <t){
        if(dis[l][f]==(long long)1e10) return (long long)1e10;
        long long h = dis[l][f];
        long long gh = v[ri];
        if(l) gh-=v[l-1];
        long long kac = r[l][ri];
 
        return h+kac*gh;
    }
    return (long long) 1e10;
};

void solve(){
    int n; cin >> n >> t >> s;
    v.resize(t);
    for(int i=0; i<=t; i++){
        for(int l=0; l<=s; l++){
            dis[i][l] = 1e10;
        }
    }
 
    for(auto &i: v) cin >> i;
 
    vector<string> se(n);
 
    for(auto &i: se){
        cin >> i;
        int k=i[0]-'0';
 
        for(int l=1; l<t; l++){
            if(i[l]=='0'){
                if(k)
                for(int j=l-k; j<l; j++){
                    for(int g=j; g<l; g++){
                        r[j][g]++;
                    }
                }
                k=0;
            }
            else k++;
        }
 
        if(k){
            for(int j=t-k; j<t; j++){
                for(int g=j; g<t; g++){
                    r[j][g]++;
                }
            }        
        }
    } 
 
    for(int i=1; i<t; i++) v[i] += v[i-1];
 
    int h=0;
 
 
    for(int i=0; i<55; i++){
        for(int l=0; l<55; l++){
            gh[i][l]=-1;
        }
    }
 
   // assert((h < 55*t));
    gh[0][0]=0;
    dis[0][0]=0;
 

    for(int i=0; i<=t; i++){
        //hah;
 
        for(int j=0; j<50; j++){
            for(int el=0; el<=50; el++){
                if(gh[j][el]!=-1){
                    if(i!=0)
                    dis[i][j+1] = min(dis[i][j+1], calc(i-1, gh[j][el], j));
                 
                }
            }
        }
    
        if(i!=t)
        for(int l=0; l<n; l++){
            if(se[l][i]=='0'){
                for(int j=i-1; j>=0; j--){
                    if(se[l][j]=='0') break;
        
                    if(j<0) continue;
                    int el = r[j][i];// kaç tane
         
         
                    for(int k=0; k<s; k++){
         
                        if(gh[k][el]==-1) gh[k][el]=j;
                        else{
                            int val_new = calc(i, j, k);
                            int val_old = calc(i, gh[k][el], k);
                            if(val_new < val_old){
                                gh[k][el] = j;  
                            }
                        }
                    }
                }
            }
        }
        int el = r[i][i];// kaç tane
         
         
        for(int k=0; k<s; k++){

            if(gh[k][el]==-1) gh[k][el]=i;
            else{
                int val_new = calc(i, i, k);
                int val_old = calc(i, gh[k][el], k);
                if(val_new < val_old){
                    gh[k][el] = i;  
                }
            }
        }
    
    }
 
    for(int i=1; i<=s; i++) cout<<dis[t][i]<<"\n";
}
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    /*freopen("popeala.in", "r", stdin);
    freopen("popeala.out", "w", stdout);
*/
    solve();
}

Compilation message

popeala.cpp: In function 'void solve()':
popeala.cpp:65:9: warning: unused variable 'h' [-Wunused-variable]
   65 |     int h=0;
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 4532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 43612 KB Output is correct
2 Correct 19 ms 43612 KB Output is correct
3 Correct 19 ms 43768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 107608 KB Output is correct
2 Correct 109 ms 115136 KB Output is correct
3 Correct 168 ms 127876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 4532 KB Output is correct
3 Correct 36 ms 43612 KB Output is correct
4 Correct 19 ms 43612 KB Output is correct
5 Correct 19 ms 43768 KB Output is correct
6 Correct 98 ms 107608 KB Output is correct
7 Correct 109 ms 115136 KB Output is correct
8 Correct 168 ms 127876 KB Output is correct
9 Correct 363 ms 177744 KB Output is correct
10 Correct 447 ms 237736 KB Output is correct
11 Runtime error 108 ms 262148 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -