/*input
2 3 3
4 3 5
101
110
*/
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define MNTO(x,y) x=min(x,y)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define ll long long
const int maxn=2e4+5;
int dp[maxn][55];
bool ok[maxn];
int arr[maxn];
string s[maxn];
int cnt[55][maxn];
int turn[55][maxn];
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n,m,S;
cin>>n>>m>>S;
REP1(i,m) cin>>arr[i];
REP(i,n){
cin>>s[i];
s[i]="0"+s[i];
REP1(j,m){
char c=s[i][j];
cnt[i][j]=cnt[i][j-1]+(c-'0');
}
}
REP1(i,m){
REP1(j,n){
int l=0,r=i;
while(l<r){
int mid=(l+r+1)/2;
int ans=0;
REP(a,n){
if(cnt[a][i]-cnt[a][mid]!=(i-mid)) ++ans;
}
if(ans>=j) l=mid;
else r=mid-1;
}
}
}
REP(i,m+1) REP(j,S+1) dp[i][j]=INT_MAX;
dp[0][0]=0;
REP1(i,m){
int cnt=n;
int sum=0;
REP(a,n) ok[a]=1;
for(int j=i;j>=0;j--){
if(j!=i){
REP1(k,S){
if(dp[j][k-1]==INT_MAX) continue;
MNTO(dp[i][k],dp[j][k-1]+cnt*sum);
}
}
sum+=arr[j];
cnt=0;
REP(a,n){
if(s[a][j]=='0') ok[a]=0;
if(ok[a]) ++cnt;
}
}
}
REP1(j,S) cout<<dp[m][j]<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
1392 KB |
Output is correct |
2 |
Correct |
28 ms |
1364 KB |
Output is correct |
3 |
Correct |
61 ms |
1284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
391 ms |
2168 KB |
Output is correct |
2 |
Correct |
706 ms |
2548 KB |
Output is correct |
3 |
Correct |
1182 ms |
3016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
852 KB |
Output is correct |
2 |
Correct |
1 ms |
1108 KB |
Output is correct |
3 |
Correct |
64 ms |
1392 KB |
Output is correct |
4 |
Correct |
28 ms |
1364 KB |
Output is correct |
5 |
Correct |
61 ms |
1284 KB |
Output is correct |
6 |
Correct |
391 ms |
2168 KB |
Output is correct |
7 |
Correct |
706 ms |
2548 KB |
Output is correct |
8 |
Correct |
1182 ms |
3016 KB |
Output is correct |
9 |
Execution timed out |
2072 ms |
4080 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |