Submission #968290

# Submission time Handle Problem Language Result Execution time Memory
968290 2024-04-23T09:37:19 Z berr Popeala (CEOI16_popeala) C++17
26 / 100
931 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4+30;

int r[N][N];
int gh[57][57];
#define int long long
void solve(){
    int n, t, s; cin >> n >> t >> s;
    vector<int> v(t);
    vector dis(t+2, vector(56, (int)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];

    set<int> upd[t];

    for(int i=0; i<n; i++){
        int k=0;
        for(int l=0; l<t; l++){
            if(se[i][l]=='0'){
                for(int j=l-k; j<l; j++)
                    upd[l].insert(j);
                k = 0;
            }
            else k++;
        }
    }

    for(int i=0; i<55; i++){
        for(int l=0; l<55; l++){
            gh[i][l]=-1;
        }
    }
    int h=0;
    for(auto i=0; i<t; i++){
        h+=upd[i].size();
    }

  //  assert((h < 55*t));
    gh[0][0]=0;
    dis[0][0]=0;

    auto calc=[&](int ri, int l, int s){
        if(dis[l][s]==1e10) return (int)1e10;
        int h = dis[l][s];
        int gh = v[ri];
        if(l) gh-=v[l-1];
        int kac = r[l][ri];

        return h+kac*gh;
    };

    for(int i=0; i<=t; i++){
        //hah;

        for(int j=0; j<54; j++){
            for(int el=0; el<54; 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)
                    upd[i].insert(gh[j][el]);
                    gh[j][el] = -1;
                }
            }
        }
        if(i<t)
        upd[i].insert(i);
        if(i<t)
        for(auto l: upd[i]){
            if(l<0) continue;
            int el = r[l][i];// kaç tane
            

            for(int k=0; k<s; k++){
                if(gh[k][el]==-1) gh[k][el]=l;
                else{
                    int val_new = calc(i, l, k);
                    int val_old = calc(i, gh[k][el], k);


                    ///cout<<val_new<<" "<<val_old<<"\n";
                    if(val_new < val_old){
                        gh[k][el] = l;  
                    }
                }
            }
        }
    }

    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();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 42504 KB Output is correct
2 Correct 44 ms 42836 KB Output is correct
3 Correct 43 ms 42584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 75228 KB Output is correct
2 Correct 247 ms 94032 KB Output is correct
3 Correct 505 ms 129104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 41 ms 42504 KB Output is correct
4 Correct 44 ms 42836 KB Output is correct
5 Correct 43 ms 42584 KB Output is correct
6 Correct 142 ms 75228 KB Output is correct
7 Correct 247 ms 94032 KB Output is correct
8 Correct 505 ms 129104 KB Output is correct
9 Correct 931 ms 217124 KB Output is correct
10 Runtime error 686 ms 262144 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -