Submission #1023260

# Submission time Handle Problem Language Result Execution time Memory
1023260 2024-07-14T14:22:29 Z 12345678 Popeala (CEOI16_popeala) C++17
17 / 100
2000 ms 9296 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long

const int nx=55, tx=2e4+5;

int n, t, s, dp[nx][tx], qs[nx], lst[nx][tx];
string str;

int cost(int l, int r)
{
    int tmp=0;
    for (int i=1; i<=n; i++) if (lst[i][r]<l) tmp+=qs[r]-qs[l-1];
    return tmp;
}

void solve(int l, int r, int layer, int optl, int optr)
{
    if (r<l) return;
    int md=(l+r)/2;
    pair<int, int> mn={INT_MAX, 0};
    for (int i=optl; i<=min(md, optr); i++) mn=min(mn, {dp[layer-1][i-1]+cost(i, md), i});
    dp[layer][md]=mn.first;
    //if (layer==2&&md==3) cout<<"debug "<<mn.first<<' '<<mn.second<<'\n';
    solve(l, md-1, layer, optl, mn.second);
    solve(md+1, r, layer, mn.second, optr);
}

int32_t main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>t>>s;
    for (int i=1; i<=t; i++) cin>>qs[i], qs[i]+=qs[i-1];
    for (int i=1; i<=n; i++)
    {
        cin>>str;
        for (int j=1; j<=t; j++)
        {
            if (str[j-1]=='0') lst[i][j]=j;
            else lst[i][j]=lst[i][j-1];
        }
    }
    for (int i=1; i<=t; i++) dp[1][i]=cost(1, i);
    for (int i=2; i<=s; i++) 
    {
        for (int j=i; j<=t; j++)
        {
            dp[i][j]=INT_MAX;
            for (int k=i; k<=j; k++) dp[i][j]=min(dp[i][j], dp[i-1][k-1]+cost(k, j));
        }
        //solve(i, t, i, i, t);
    }
    //for (int i=1; i<=s; i++) for (int j=1; j<=t; j++) cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
    for (int i=1; i<=s; i++) cout<<dp[i][t]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 9064 KB Output is correct
2 Correct 194 ms 9040 KB Output is correct
3 Correct 213 ms 9296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2032 ms 7628 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 220 ms 9064 KB Output is correct
4 Correct 194 ms 9040 KB Output is correct
5 Correct 213 ms 9296 KB Output is correct
6 Execution timed out 2032 ms 7628 KB Time limit exceeded
7 Halted 0 ms 0 KB -