답안 #610400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
610400 2022-07-28T07:24:21 Z Drew_ 조교 (CEOI16_popeala) C++17
100 / 100
1691 ms 15256 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define size(x) (int)x.size()

const int MAX = 2e4 + 69;
const int inf = 2e9 + 69;

int N, S, T;
int ar[MAX], pfx[MAX];
int prv[69][MAX]; // prv[i][j]: closest '0' to the left from task `j` for contestant `i`
int dp[69][MAX];

int main()
{
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> N >> T >> S;
	for (int i = 1; i <= T; ++i)
		cin >> ar[i], pfx[i] = ar[i] + pfx[i-1];

	for (int i = 1; i <= N; ++i)
	{
		char s[MAX]; cin >> (s+1);
		for (int j = 1; j <= T; ++j)
		{
			if (s[j] == '0') prv[i][j] = j;
			else prv[i][j] = prv[i][j-1];
		}
	}

	for (int i = 0; i < 69; ++i)
		fill(dp[i], dp[i] + MAX, inf);
	dp[0][0] = 0;

	int val[MAX][69] = {};
	for (int g = 1; g <= S; ++g)
	{
		for (int i = 0; i <= T; ++i)
			for (int j = 0; j <= N; ++j)
				val[i][j] = inf;

		for (int i = 1; i <= T; ++i)
		{
			vector<int> v = { 1 };
			for (int j = 1; j <= N; ++j) if (prv[j][i] < i)
				v.pb(prv[j][i] + 1);
			sort(v.begin(), v.end());

			for (int j = 0; j <= N; ++j)
				val[i][j] = min(val[i-1][j], dp[g-1][i-1] - j * pfx[i-1]);
			for (int j = 0; j < size(v); ++j)
				dp[g][i] = min(dp[g][i], j * pfx[i] + val[(j+1 < size(v) ? v[j+1] - 1 : i)][j]);
		}
	}
	
	for (int g = 1; g <= S; ++g)
		cout << dp[g][T] << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11092 KB Output is correct
2 Correct 7 ms 11220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 11464 KB Output is correct
2 Correct 41 ms 11348 KB Output is correct
3 Correct 45 ms 11468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 174 ms 11792 KB Output is correct
2 Correct 276 ms 11960 KB Output is correct
3 Correct 322 ms 12176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 11092 KB Output is correct
2 Correct 7 ms 11220 KB Output is correct
3 Correct 45 ms 11464 KB Output is correct
4 Correct 41 ms 11348 KB Output is correct
5 Correct 45 ms 11468 KB Output is correct
6 Correct 174 ms 11792 KB Output is correct
7 Correct 276 ms 11960 KB Output is correct
8 Correct 322 ms 12176 KB Output is correct
9 Correct 502 ms 12680 KB Output is correct
10 Correct 656 ms 13088 KB Output is correct
11 Correct 1207 ms 15096 KB Output is correct
12 Correct 1490 ms 15256 KB Output is correct
13 Correct 1671 ms 15248 KB Output is correct
14 Correct 1691 ms 15256 KB Output is correct
15 Correct 1634 ms 15252 KB Output is correct