This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));(s)<(e)?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int k,n,s;
int arr[20005];
string ac[20005];
int memo[51][20005];
int pp[51];
struct node{
int s,e,m;
int val,lazy;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void propo(){
if (lazy){
val+=lazy;
if (s!=e){
l->lazy+=lazy;
r->lazy+=lazy;
}
lazy=0;
}
}
void update(int i,int j,int k){
if (s==i && e==j) lazy+=k;
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
l->propo(),r->propo();
val=min(l->val,r->val);
}
}
int query(int i,int j){
propo();
if (s==i && e==j) return val;
else if (j<=m) return l->query(i,j);
else if (m<i) return r->query(i,j);
else return min(l->query(i,m),r->query(m+1,j));
}
void clear(){
val=lazy=0;
if (s!=e) l->clear(),r->clear();
}
} *root=new node(0,20005);
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>k>>s;
rep(x,1,k+1) cin>>arr[x];
rep(x,0,n) cin>>ac[x];
rep(x,0,n) ac[x]="$"+ac[x];
memset(memo,63,sizeof(memo));
memo[0][0]=0;
rep(z,1,s+1){
root->clear();
rep(x,0,n) pp[x]=0;
rep(x,1,k+1){
root->update(x-1,x-1,memo[z-1][x-1]);
rep(y,0,n) root->update(pp[y],x-1,arr[x]);
rep(y,0,n) if (ac[y][x]=='0'){
rep(w,pp[y],x) root->update(pp[y],w,-arr[w+1]);
pp[y]=x;
}
memo[z][x]=root->query(0,x-1);
}
}
//rep(z,0,s+1){
//rep(x,0,k+1) cout<<memo[z][x]<<" "; cout<<endl;
//}
rep(z,1,s+1) cout<<memo[z][k]<<endl;
}
Compilation message (stderr)
popeala.cpp: In constructor 'node::node(long long int, long long int)':
popeala.cpp:37:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | s=_s,e=_e,m=s+e>>1;
| ~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |