Submission #63098

# Submission time Handle Problem Language Result Execution time Memory
63098 2018-07-31T16:50:34 Z bazsi700 Popeala (CEOI16_popeala) C++14
26 / 100
2000 ms 222748 KB
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

bool solved[51][20001];
int dp[20001][51];
int minval[20002][52][52];
int prefsum[20002];
int conssolved[51][20001]; //[x][y]=z means, the xth solved y-z+1,y-z+2,...,y tasks but not the y-z th

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,t,s;
	cin >> n >> t >> s;
	vi p(t+1);
	for(int i = 1; i <= t; i++) {
		cin >> p[i];
		prefsum[i] = prefsum[i-1]+p[i];
	}
	for(int i = 1; i <= n; i++) {
		int lastnotsolv = 0;
		for(int j = 1; j <= t; j++) {
			char ch;
			cin >> ch;
			solved[i][j] = (ch == '1');
			if(!solved[i][j]) {
				lastnotsolv = j;
			}
			conssolved[i][j] = j-lastnotsolv;
		}
	}
	int sum = 0;
	for(int j = 0; j <= s; j++) {
		for(int i = 0; i <= t; i++) {
			for(int per = 0; per <= n; per++) {
				minval[i][j][per] = 2*MOD;
			}
		}
	}
	for(int i = 1; i <= t; i++) {
		sum+= p[i];
		int solv = 0;
		for(int j = 1; j <= n; j++) {
			if(conssolved[j][i] == i) {
				solv++;
			}
		}
		dp[i][1] = solv*sum;
		for(int pers = 0; pers <= n; pers++) {
			minval[i][2][pers] = min(minval[i-1][2][pers]+pers*p[i],dp[i][1]);
		}
		//cout << (dp[i][1] > MOD ? -1 : dp[i][1]) << " ";
	}
	//cout << endl;

	for(int j = 2; j <= s; j++) {
		for(int i = 1; i <= t; i++) {
		//	dp[i][j] = 2*MOD;
			//sum = 0;
			vector<int> solves;
		//	set<int> tocheck;
			//tocheck.insert(1);
			for(int st = 1; st <= n; st++) {
				solves.push_back(conssolved[st][i]);
			//	tocheck.insert(conssolved[st][i]+1);
			}
			sort(solves.begin(),solves.end());
			int ind = 0;
			//for(int currsiz =1; currsiz <= i-j+1; currsiz++) {
			sum = prefsum[i]-prefsum[i-1];
			dp[i][j] = minval[i-1][j][n-ind]+sum*(n-ind);
			for(int currsiz : solves) {
				currsiz++;
				if(currsiz > i-j+1) {
					break;
				}
				while(ind < n && solves[ind] < currsiz) {
					ind++;
				}
				sum = prefsum[i]-prefsum[i-currsiz];
				//sum+= p[i-currsiz+1];
				if(dp[i][j] == dp[i][j-1]) {
					break;
				}
			//	if(ind == n) {
					dp[i][j] = min(dp[i][j],minval[i-currsiz][j][n-ind]+sum*(n-ind));
				//	if(j == 3 && minval[i-currsiz][j][n-ind]+sum*(n-ind) == 0) {
				//		cout << i << " " << currsiz << " " << ind << endl;
				//	}
				//	break;
				//}
			}
			for(int pers = 0; pers <= n; pers++) {
				minval[i][j+1][pers] = min(minval[i-1][j+1][pers]+pers*p[i],dp[i][j]);
			}
			//cout << (dp[i][j] > MOD ? -1 : dp[i][j]) << " ";
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	//	cout << endl;
	}
	for(int i = 1; i <= s; i++) {
		cout << dp[t][i] << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 1124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 6584 KB Output is correct
2 Correct 75 ms 6584 KB Output is correct
3 Correct 71 ms 6584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 397 ms 25256 KB Output is correct
2 Correct 528 ms 34216 KB Output is correct
3 Correct 637 ms 45120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 1124 KB Output is correct
3 Correct 72 ms 6584 KB Output is correct
4 Correct 75 ms 6584 KB Output is correct
5 Correct 71 ms 6584 KB Output is correct
6 Correct 397 ms 25256 KB Output is correct
7 Correct 528 ms 34216 KB Output is correct
8 Correct 637 ms 45120 KB Output is correct
9 Correct 951 ms 72768 KB Output is correct
10 Correct 1624 ms 95396 KB Output is correct
11 Execution timed out 2062 ms 222748 KB Time limit exceeded
12 Halted 0 ms 0 KB -