#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct SegmentTree
{
int sum=0;
int lazy=0;
int s,e;
SegmentTree* next[2];
SegmentTree(int l,int r)
{
s=l;
e=r;
if(s!=e)
{
int mid=(s+e)/2;
next[0]=new SegmentTree(s,mid);
next[1]=new SegmentTree(mid+1,e);
}
}
void push()
{
if(lazy==0)
return;
sum+=(e-s+1)*lazy;
if(s!=e)
{
next[0]->lazy+=lazy;
next[1]->lazy+=lazy;
}
lazy=0;
}
void pull()
{
sum=(next[0]->sum+next[1]->sum);
}
void Update(int l,int r)
{
if(l>r)
return;
push();
if(r<s or e<l)
return;
if(l<=s and e<=r)
{
lazy++;
push();
return;
}
next[0]->Update(l,r);
next[1]->Update(l,r);
pull();
}
int get(int l,int r)
{
push();
if(r<s or e<l)
return 0;
if(l<=s and e<=r)
return sum;
return (next[0]->get(l,r)+next[1]->get(l,r));
}
};
const int T=2e4+1;
const int N=51;
const int inf=2e9;
int points;
string results;
int pre[T];
int zero[N];
int zeros[T][T];
int dp[T][2];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,t,s;
cin>>n>>t>>s;
for(int i=0;i<t;i++)
{
cin>>points;
pre[i+1]=pre[i]+points;
}
for(int i=0;i<n;i++)
{
cin>>results;
for(int r=1;r<=t;r++)
{
if(results[r-1]=='0')
zero[i]=r;
else
zeros[zero[i]+1][r]+=1;
}
}
for(int i=0;i<=t;i++)
{
for(int j=0;j<=s;j++)
dp[i][j]=inf;
for(int j=1;j<=i;j++)
zeros[j][i]+=zeros[j-1][i];
}
dp[0][0]=0;
for(int j=0;j<s;j++)
{
for(int i=0;i<=t;i++)
dp[i][(j+1)%2]=inf;
for(int i=0;i<t;i++)
{
if(dp[i][j%2]==inf)
continue;
for(int new_i=i+1;new_i<=t;new_i++)
dp[new_i][(j+1)%2]=min(dp[new_i][(j+1)%2],dp[i][j%2]+(pre[new_i]-pre[i])*zeros[i+1][new_i]);
}
cout<<dp[t][(j+1)%2]<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
41308 KB |
Output is correct |
2 |
Correct |
11 ms |
41304 KB |
Output is correct |
3 |
Correct |
12 ms |
41308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
172884 KB |
Output is correct |
2 |
Correct |
310 ms |
236468 KB |
Output is correct |
3 |
Runtime error |
36 ms |
262144 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
12 ms |
41308 KB |
Output is correct |
4 |
Correct |
11 ms |
41304 KB |
Output is correct |
5 |
Correct |
12 ms |
41308 KB |
Output is correct |
6 |
Correct |
166 ms |
172884 KB |
Output is correct |
7 |
Correct |
310 ms |
236468 KB |
Output is correct |
8 |
Runtime error |
36 ms |
262144 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |