#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 int inf=2e8;
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=(ll)1e18):k(k),n(n){}
ll val(ll x){return k*x+n;}
}st[10000005];
void modify(int&id,int l,int r,line ln){
if(!id) id=++ntot;
int 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,int l,int r,int p){
if(l==r) return st[id].val(p);
int 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=(ll)1e18;
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++){
if(dp[i-1][j-1]==(ll)1e18) continue;
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);
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
162748 KB |
Output is correct |
2 |
Correct |
28 ms |
166740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
167256 KB |
Output is correct |
2 |
Correct |
139 ms |
167252 KB |
Output is correct |
3 |
Correct |
147 ms |
167280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
599 ms |
168528 KB |
Output is correct |
2 |
Correct |
840 ms |
171632 KB |
Output is correct |
3 |
Correct |
1203 ms |
172944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
162748 KB |
Output is correct |
2 |
Correct |
28 ms |
166740 KB |
Output is correct |
3 |
Correct |
144 ms |
167256 KB |
Output is correct |
4 |
Correct |
139 ms |
167252 KB |
Output is correct |
5 |
Correct |
147 ms |
167280 KB |
Output is correct |
6 |
Correct |
599 ms |
168528 KB |
Output is correct |
7 |
Correct |
840 ms |
171632 KB |
Output is correct |
8 |
Correct |
1203 ms |
172944 KB |
Output is correct |
9 |
Correct |
1721 ms |
174928 KB |
Output is correct |
10 |
Execution timed out |
2044 ms |
178768 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |