Submission #1023255

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

using namespace std;

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);
}

int 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<=n; 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 2396 KB Output is correct
2 Incorrect 2 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 214 ms 4868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2063 ms 6644 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Incorrect 2 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -