Submission #237145

# Submission time Handle Problem Language Result Execution time Memory
237145 2020-06-04T20:41:02 Z Sorting Popeala (CEOI16_popeala) C++14
0 / 100
24 ms 1536 KB
#include <bits/stdc++.h>

using namespace std;

const int k_T = 2e4 + 3;
const int k_N = 50 + 3;
const int k_S = 50 + 3;

int n, t, s;
int points[k_T];
string results[k_N];

long long dp[k_S][k_T];

int sum[k_N];
bool counts[k_N];

void divide_and_conquer(int l, int r, int sl, int sr, int subtasks){
    if(l > r)
        return;

    //cout << l << " " << r << " " <<  " " << sl << " " << sr << " " << subtasks << endl;

    int mid = (l + r) >> 1;

    for(int i = 0; i < n; ++i){
        sum[i] = 0;
        counts[i] = 1;
    }

    dp[subtasks][mid] = INT_MAX;
    int smid = sr;
    for(int i = mid; i <= n - 1; ++i){
        int add = 0;
        for(int j = 0; j < n; ++j){
            sum[j] += points[i];
            if(results[j][i] == '0')
                counts[j] = 0;

            if(counts[j])
                add += sum[j];
        }

        long long curr = add + dp[subtasks - 1][i + 1];
        if(curr <= dp[subtasks][mid]){
            dp[subtasks][mid] = curr;
            smid = i;
        }
    }

    divide_and_conquer(l, mid - 1, sl, smid, subtasks);
    divide_and_conquer(mid + 1, r, smid, sr, subtasks);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> t >> s;

    for(int i = 0; i < t; ++i)
        cin >> points[i];
    for(int i = 0; i < n; ++i)
        cin >> results[i];

    for(int pos = 0, subtasks = 0; pos <= t; ++pos)
        dp[subtasks][pos] = (pos == t) ? 0 : INT_MAX;

    for(int subtasks = 1; subtasks <= s; ++subtasks){
        divide_and_conquer(0, t - 1, 0, t - 1, subtasks);
        dp[subtasks][t] = INT_MAX;
    }

    for(int subtasks = 1; subtasks <= s; ++subtasks)
        cout << dp[subtasks][0] << "\n";
}
/*
2 3 3
4 3 5
011
011
*/
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -