답안 #341700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
341700 2020-12-30T13:18:41 Z phathnv 조교 (CEOI16_popeala) C++11
0 / 100
2 ms 492 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int T = 4001;
const int N = 51;
const int S = 51;
const int INF = 2e9 + 10;

int n, t, s, p[N], cost[N][N], dp[S][T];
string a[N];

void ReadInput(){
    cin >> n >> t >> s;
    for(int i = 1; i <= t; i++)
        cin >> p[i];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] = '*' + a[i];
    }
}

int Cost(int l, int r){
    int sum = 0, cnt = 0;
    for(int i = l; i <= r; i++)
        sum += p[i];
    for(int i = 1; i <= n; i++){
        bool flag = 0;
        for(int j = l; j <= r; j++)
            if (a[i][j] == '0'){
                flag = 1;
                break;
            }
        if (!flag)
            cnt++;
    }
    return sum * cnt;
}

void Calc(int id, int l, int r, int from, int to){
    if (l > r)
        return;
    int mid = (l + r) >> 1, pos = -1;
    dp[id][mid] = INF;
    for(int i = from; i <= min(mid, to); i++){
        int val = dp[id - 1][i - 1] + Cost(i, mid);
        if (dp[id][mid] > val){
            dp[id][mid] = val;
            pos = i;
        }
    }
    Calc(id, l, mid - 1, from, pos);
    Calc(id, mid + 1, r, pos, to);
}

void Solve(){
    for(int i = 1; i <= t; i++)
        dp[1][i] = Cost(1, i);
    for(int i = 2; i <= s; i++)
        Calc(i, i, t, i, t);
    for(int i = 1; i <= s; i++)
        cout << dp[i][t] << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ReadInput();
    Solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 2 ms 404 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 2 ms 404 KB Output isn't correct