Submission #1023258

#TimeUsernameProblemLanguageResultExecution timeMemory
102325812345678Popeala (CEOI16_popeala)C++17
0 / 100
2057 ms7004 KiB
#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<=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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...