#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const ll inf=(ll)1e9;
int n,t,s,ntot;
int p[20005],nxt[55][20005],c[20005],root,lch[10000005],rch[10000005];
char r[55][20005];
ll dp[20005][55],pref[20005];
vector<pll> qs[20005];
struct line{
ll k,n;
line(ll k=0,ll n=inf):k(k),n(n){}
ll val(ll x){return k*x+n;}
}st[10000005];
void modify(int&id,ll l,ll r,line ln){
if(!id) id=++ntot;
ll mid=(l+r)/2;
if(st[id].val(mid)>ln.val(mid)) swap(st[id],ln);
if(l==r) return;
if(st[id].val(l)>ln.val(l)) modify(lch[id],l,mid,ln);
else modify(rch[id],mid+1,r,ln);
}
ll query(int id,ll l,ll r,ll p){
if(l==r) return st[id].val(p);
ll mid=(l+r)/2;
if(p<=mid) return min(st[id].val(p),query(lch[id],l,mid,p));
else return min(st[id].val(p),query(rch[id],mid+1,r,p));
}
void clr(){
while(ntot){
lch[ntot]=0;
rch[ntot]=0;
st[ntot].k=0;
st[ntot].n=inf;
ntot--;
}
root=0;
}
int main(){
n=readint(); t=readint(); s=readint();
for(int i=1;i<=t;i++) p[i]=readint();
for(int i=1;i<=n;i++) scanf("%s",r[i]+1);
for(int i=1;i<=n;i++){
int lst=t+1;
for(int j=t;j>=1;j--){
if(r[i][j]=='0') lst=j;
nxt[i][j]=lst;
}
}
for(int i=1;i<=t;i++) pref[i]=pref[i-1]+p[i];
for(int i=0;i<=t;i++){
for(int j=0;j<=s;j++){
dp[i][j]=1e18;
}
}
dp[0][0]=0;
for(int j=1;j<=s;j++){
for(int i=1;i<=t;i++) qs[i].clear();
for(int i=1;i<=t;i++){
vector<int> xs;
xs.pb(i);
xs.pb(t+1);
for(int k=1;k<=n;k++){
if(nxt[k][i]<=t) xs.pb(nxt[k][i]),c[nxt[k][i]]++;
}
sort(xs.begin(),xs.end());
xs.erase(unique(xs.begin(),xs.end()),xs.end());
int cnt=n;
for(int p=0;p+1<(int)xs.size();p++){
cnt-=c[xs[p]];
qs[xs[p]].pb(mp(dp[i-1][j-1]-pref[i-1]*cnt,cnt));
}
for(int p:xs) c[p]=0;
}
clr();
for(int i=1;i<=t;i++){
for(auto p:qs[i]) modify(root,0,inf,line(p.se,p.fi));
chkmin(dp[i][j],query(root,0,inf,pref[i]));
}
}
for(int i=1;i<=s;i++) printf("%lld\n",dp[t][i]);
return 0;
}
Compilation message
popeala.cpp: In function 'int main()':
popeala.cpp:69:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
69 | for(int i=1;i<=n;i++) scanf("%s",r[i]+1);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
162604 KB |
Output is correct |
2 |
Correct |
28 ms |
166736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
167260 KB |
Output is correct |
2 |
Correct |
167 ms |
167316 KB |
Output is correct |
3 |
Correct |
155 ms |
167296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
665 ms |
169108 KB |
Output is correct |
2 |
Correct |
919 ms |
171812 KB |
Output is correct |
3 |
Correct |
1262 ms |
173176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
102 ms |
162604 KB |
Output is correct |
2 |
Correct |
28 ms |
166736 KB |
Output is correct |
3 |
Correct |
175 ms |
167260 KB |
Output is correct |
4 |
Correct |
167 ms |
167316 KB |
Output is correct |
5 |
Correct |
155 ms |
167296 KB |
Output is correct |
6 |
Correct |
665 ms |
169108 KB |
Output is correct |
7 |
Correct |
919 ms |
171812 KB |
Output is correct |
8 |
Correct |
1262 ms |
173176 KB |
Output is correct |
9 |
Correct |
1909 ms |
175240 KB |
Output is correct |
10 |
Execution timed out |
2061 ms |
179284 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |