제출 #349970

#제출 시각아이디문제언어결과실행 시간메모리
349970doowey조교 (CEOI16_popeala)C++14
17 / 100
2037 ms2028 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 20010;
const int M = 55;
const ll inf = (ll)1e18;

ll dp[M][N];
ll sum[N];
int cnt[M][N];

int n, t;

ll cost(int li, int ri){
    ll f1 = sum[ri]-sum[li-1];
    ll f2 = 0;
    for(int i = 1; i <= n; i ++ ){
        f2 += (cnt[i][ri]-cnt[i][li-1]==(ri-li+1));
    }
    return f1 * 1ll * f2;
}

int main(){
    fastIO;
    int s;
    cin >> n >> t >> s;
    for(int i = 0 ; i <= s; i ++ ){
        for(int j =0; j <= t; j ++ ){
            dp[i][j]=inf;
        }
    }
    dp[0][0]=0;
    for(int i = 1; i <= t; i ++ ){
        cin >> sum[i];
        sum[i] += sum[i - 1];
    }
    char q;
    for(int i = 1; i <= n; i ++ ){
        for(int j = 1; j <= t; j ++ ){
            cin >> q;
            cnt[i][j]=q-'0';
            cnt[i][j]+=cnt[i][j-1];
        }
    }
    for(int i = 1; i <= s; i ++ ){
        for(int p = 1; p <= t; p ++ ){
            for(int q = 1; q <= p; q ++ ){
                dp[i][p]=min(dp[i][p],cost(q,p)+dp[i-1][q-1]);
            }
        }
        cout << dp[i][t] << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...