Submission #947842

# Submission time Handle Problem Language Result Execution time Memory
947842 2024-03-17T06:15:13 Z Darren0724 Popeala (CEOI16_popeala) C++17
26 / 100
2000 ms 8164 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
 
int32_t main() {
    LCBorz;
    int n,t,s;cin>>n>>t>>s;
    vector<int> v(t+1);
    for(int i=1;i<=t;i++){
        cin>>v[i];
        v[i]+=v[i-1];
    }
    vector pre(n,vector(t+1,0)),last(t+1,vector(n+2,0));
    for(int i=0;i<n;i++){
        for(int j=1;j<=t;j++){
            char c;cin>>c;
            pre[i][j]=c-'0'+pre[i][j-1];
            last[j][i]=(c=='0'?j:last[j-1][i]);
        }   
    }
    for(int j=1;j<=t;j++){
        last[j][n]=j;
        sort(all(last[j]));
    }
    auto f=[&](int l,int r){
        int cnt=0;
        for(int i=0;i<n;i++){
            if(pre[i][r]-pre[i][l]==r-l){
                cnt++;
            }
        }
        return cnt;
    };
    vector dp(s+1,vector(t+1,INF));
    dp[0][0]=0;
    for(int i=1;i<=s;i++){
        for(int j=1;j<=t;j++){
            for(int cnt=0;cnt<=n;cnt++){
                for(int k=last[j][cnt];k<last[j][cnt+1];k++){
                    //cout<<j<<' '<<k<<' '<<cnt<<endl;
                    dp[i][j]=min(dp[i][j],dp[i-1][k]+cnt*(v[j]-v[k]));
                }
            }
        }
    }
    for(int i=1;i<=s;i++){
        cout<<dp[i][t]<<endl;
    }
 
    
    return 0;
}
/*
5 5 5
1 5 2 4 3
11010
00101
10011
00010
11011
0
3
12
22
40

*/

Compilation message

popeala.cpp: In function 'int32_t main()':
popeala.cpp:30:10: warning: variable 'f' set but not used [-Wunused-but-set-variable]
   30 |     auto f=[&](int l,int r){
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 372 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 872 KB Output is correct
2 Correct 11 ms 904 KB Output is correct
3 Correct 12 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 2136 KB Output is correct
2 Correct 276 ms 3164 KB Output is correct
3 Correct 470 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 372 KB Output is correct
2 Correct 1 ms 360 KB Output is correct
3 Correct 12 ms 872 KB Output is correct
4 Correct 11 ms 904 KB Output is correct
5 Correct 12 ms 856 KB Output is correct
6 Correct 156 ms 2136 KB Output is correct
7 Correct 276 ms 3164 KB Output is correct
8 Correct 470 ms 4180 KB Output is correct
9 Correct 1206 ms 6352 KB Output is correct
10 Execution timed out 2045 ms 8164 KB Time limit exceeded
11 Halted 0 ms 0 KB -