Submission #962920

# Submission time Handle Problem Language Result Execution time Memory
962920 2024-04-14T09:45:58 Z MilosMilutinovic Popeala (CEOI16_popeala) C++14
8 / 100
17 ms 30188 KB
#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;
}

int n,t,s;
int p[20005],nxt[55][20005],c[20005];
char r[55][20005];
ll dp[55][20005],pref[20005];
vector<pll> qs[20005];

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;
		}
		vector<pll> lines;
		for(int i=1;i<=t;i++){
			for(auto p:qs[i]) lines.pb(p);
			for(auto p:lines){
				chkmin(dp[i][j],p.fi+p.se*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:35:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  for(int i=1;i<=n;i++) scanf("%s",r[i]+1);
      |                        ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6768 KB Output is correct
2 Correct 3 ms 14956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 30044 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 17 ms 30188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6768 KB Output is correct
2 Correct 3 ms 14956 KB Output is correct
3 Runtime error 14 ms 30044 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -