#include <bits/stdc++.h>
using namespace std;
int dp[20005][55];
int cost[4005][4005];
int n,t,s;
int val[20005];
bool have[55][20005];
bool bad[55];
int mycost[55];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>t>>s;
for(int i=1;i<=t;i++)
cin>>val[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=t;j++)
{
char c;
cin>>c;
have[i][j]=c-'0';
}
for(int i=1;i<=t;i++)
{
for(int j=1;j<=n;j++)
{
bad[j]=0;
mycost[j]=0;
}
int cur=0;
for(int j=i;j<=t;j++)
{
for(int k=1;k<=n;k++)
if(!bad[k])
{
if(have[k][j])
{
cur+=val[j];
mycost[k]+=val[j];
}
else
{
bad[k]=1;
cur-=mycost[k];
mycost[k]=0;
}
}
cost[i][j]=cur;
}
}
dp[0][0]=0;
for(int i=1;i<=s;i++)
dp[0][i]=2e9;
for(int j=1;j<=s;j++)
{
for(int i=1;i<=t;i++)
{
dp[i][0]=2e9;
dp[i][j]=2e9;
for(int k=i-1;k>=0;k--)
dp[i][j]=min(dp[i][j],dp[k][j-1]+cost[k+1][i]);
}
}
for(int i=1;i<=s;i++)
cout<<dp[t][i]<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3108 KB |
Output is correct |
2 |
Correct |
19 ms |
3196 KB |
Output is correct |
3 |
Correct |
19 ms |
3156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
815 ms |
19408 KB |
Output is correct |
2 |
Correct |
1785 ms |
31152 KB |
Output is correct |
3 |
Execution timed out |
2081 ms |
47092 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
18 ms |
3108 KB |
Output is correct |
4 |
Correct |
19 ms |
3196 KB |
Output is correct |
5 |
Correct |
19 ms |
3156 KB |
Output is correct |
6 |
Correct |
815 ms |
19408 KB |
Output is correct |
7 |
Correct |
1785 ms |
31152 KB |
Output is correct |
8 |
Execution timed out |
2081 ms |
47092 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |