답안 #874939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874939 2023-11-18T06:50:04 Z Ghulam_Junaid 조교 (CEOI16_popeala) C++17
0 / 100
108 ms 11356 KB
#include <bits/stdc++.h>
using namespace std;

const int T = 2e4 + 10;
const int N = 52;
const int S = 52;

int t, n, s, points[T], pref[T], dp[T][S];
int mat[N][T], perf_mat[N][T], maxl[N][T];

int good(int l, int r){
    int ans = 0;
    for (int i=1; i<=n; i++)
        ans += ((perf_mat[i][r] - perf_mat[i][l - 1]) == (r - l + 1));
    return ans;
}

int main(){
    cin >> n >> t >> s;
    for (int i=1; i<=t; i++)
        cin >> points[i], pref[i] = pref[i - 1] + points[i];

    for (int i=1; i<=n; i++){
        for (int j=1; j<=t; j++){
            char c;
            cin >> c;
            mat[i][j] = (c - '0');
            perf_mat[i][j] = mat[i][j] + perf_mat[i][j - 1];
        }
    }

    for (int l=1; l<=t; l++){
        int cnt = good(l, t);
        int summ = pref[t] - pref[l - 1];
        dp[l][1] = cnt * summ;
        // cout << l << " 1 : " << dp[l][1] << endl;
    }

    for (int i=1; i<=n; i++){
        maxl[i][t + 1] = t + 1;
        for (int j = t; j > 0; j--){
            maxl[i][j] = maxl[i][j + 1];
            if (!mat[i][j])
                maxl[i][j] = j;
        }
    }

    vector<int> inds;
    for (int subs = 2; subs <= s; subs++){
        for (int l = 1; l <= t; l++){
            if ((t - l + 1) < subs)
                continue;

            inds.clear();
            for (int i=1; i<=n; i++)
                inds.push_back(maxl[i][l]);

            sort(inds.begin(), inds.end());
            dp[l][subs] = dp[l + 1][subs - 1] + good(l, l) * points[l];

            // cout << "init = " << dp[l][subs] << endl;

            int rem = n;
            for (int x : inds){
                int r = x + 1;
                if ((t - r + 1) < (subs - 1))
                    break;

                rem--;
                dp[l][subs] = min(dp[l][subs], dp[r][subs - 1] + rem * (pref[r - 1] - pref[l - 1]));
            }

            // cout << l << " " << subs << " : " << dp[l][subs] << endl;
        }
    }

    for (int i=1; i<=s; i++)
        cout << dp[1][i] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 8796 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 9048 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 108 ms 11356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 8796 KB Output isn't correct
3 Halted 0 ms 0 KB -