Submission #349966

# Submission time Handle Problem Language Result Execution time Memory
349966 2021-01-18T19:01:50 Z doowey Popeala (CEOI16_popeala) C++14
0 / 100
74 ms 2156 KB
#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;
}

void solve(int d, int l, int r, int optl, int optr){
    if(l > r) return;
    int mid = (l + r) / 2;
    int opt = optl;
    ll cur = inf;
    ll ch;
    for(int i = optl; i <= min(mid,optr); i ++ ){
        ch = cost(i,mid) + dp[d-1][i-1];
        if(cur > ch){
            cur = ch;
            opt = i;
        }
    }
    dp[d][mid]=cur;
    solve(d,l,mid-1,optl,opt);
    solve(d,mid+1,r,opt,optr);
}
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 ++ ){
        solve(i, 1, t, 1, t);
        cout << dp[i][t] << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 620 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 2156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 620 KB Output isn't correct