Submission #609355

# Submission time Handle Problem Language Result Execution time Memory
609355 2022-07-27T14:14:08 Z Redhood Popeala (CEOI16_popeala) C++14
0 / 100
2000 ms 8976 KB
#include <bits/stdc++.h>
#define fi first
#define se second

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) (int)(x).size()
using namespace std;


typedef long long ll;
typedef long double ld;

const int inf = 2e9 + 1;
const int T = 20'000;
const int S = 51;
int dp[T][S];

int main()
{
    int t, n , s;
    cin >> n >> t >> s;
    vector < int > score(t);
    for(auto &i : score)
    cin >> i;


    vector < string > capble;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        capble.pb(s);
    }

    vector<int>pref(t);

    pref[0] = score[0];
    for(int i = 1; i < t; ++i){
        pref[i] = pref[i - 1] + score[i];
    }

    auto get = [&](int l , int r){
        assert(l != -1);
        return pref[r] - (l == 0 ? 0 : pref[l - 1]);
    };

    int left[t][n];

    for(int i = 0;i < n; ++i){
        int cur = -1;
        for(int j = 0; j < t; ++j){
            if(capble[i][j] == '0')
                cur = j;
            left[j][i] = cur;
        }

    }

    /// yo
    for(int i = 0; i < T; ++i)
        fill(dp[i] , dp[i] + S , inf);


    int opt[t][s + 1];

    for(int f=0;f<t;++f)
        for(int x=0;x<=s;++x)
            opt[f][x]=-1;
    for(int x = 0; x < t; ++x){
        int c = 0;
        for(int f=0;f<n;++f){
            if(left[x][f]==-1)
                c++;
        }
        dp[x][1] = get(0,x) * c;
        opt[x][1] = -1;
    }



    for(int j = 2; j <= s; ++j){
        for(int i = t - 1; i >= 0; --i){

            if(i+1<j){
                opt[i][j]=-1;
                continue;
            }
            int l = max(opt[i][j - 1],j-1-1), r = (i == t - 1 ? i-1 : opt[i + 1][j]);
            r = min(r , i - 1);
            l = j-2, r = i-1;
//            l = j - 2;
            if(l > r) {
                cout << "whata fuk " << i << ' '<<j << ' ' << l << ' ' << r << '\n';
                assert(false);
            }

            int ans = inf;
            int pr = -1;
            for(int cand = l; cand <= r; ++cand){
                if(dp[cand][j-1] != inf){
                    int cost = dp[cand][j-1];
                    int c = 0;
                    for(int f=0;f<n;++f){
                        if(left[i][f] <= cand)
                            c++;
                    }
                    cost += c * get(cand+1, i);
                    if(cost < ans){
                        ans = cost;
                        pr = cand;
                    }
                }
            }
            assert(pr != -1);
            opt[i][j] = pr;
            dp[i][j] = ans;
        }
    }
    for(int i = 0; i < t; ++i){
        for(int j = 0; j <= s; ++j){
            if(opt[i][j] == -1)
                continue;

            if(j - 1 >= 0){
                if(opt[i][j] < opt[i][j - 1]){
                    assert(false);
                }
            }
        }
    }

    for(int k = 1; k <= s; ++k)
        cout << dp[t-1][k] << ' ' << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Runtime error 7 ms 8532 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 234 ms 8976 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 5204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Runtime error 7 ms 8532 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -