# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44830 | bogdan10bos | Popeala (CEOI16_popeala) | C++14 | 1213 ms | 15116 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
//#define FILE_IO
typedef pair<int, int> pii;
int N, M, K;
int v[20005], sum[20005];
int dp[55][20005];
int cnt[55], pos[55];
int itv[55][2];
char s[55][20005];
deque<pii> dq[55][55];
int main()
{
#ifdef FILE_IO
freopen("1.in", "r", stdin);
freopen("1.out", "w", stdout);
#endif
scanf("%d%d%d", &N, &M, &K);
for(int i = 1; i <= M; i++) scanf("%d", &v[i]), sum[i] = sum[i - 1] + v[i];
for(int i = 1; i <= N; i++)
scanf("%s", s[i] + 1);
for(int i = 1; i <= M; i++)
for(int j = 1; j <= N; j++)
{
if(s[j][i] == '0') cnt[j] = 0;
else cnt[j]++;
if(cnt[j] == i) dp[1][i] += sum[i];
}
for(int i = 1; i <= K; i++) dp[i][0] = 2e9 + 1;
for(int i = 1; i <= N; i++) cnt[i] = 0;
for(int i = 1; i <= M; i++)
{
int ii = i;
int cnt1 = 0;
for(int j = 1; j <= N; j++)
{
if(s[j][i] == '0') cnt[j] = 0;
else cnt[j]++, cnt1++;
pos[j] = i - cnt[j] + 1;
}
sort(pos + 1, pos + N + 1);
pos[0] = 1;
pos[N + 1] = i + 1;
int lst = 1;
for(int j = 0; j <= cnt1; j++)
{
int st = pos[j];
int dr = pos[j + 1] - 1;
for(int i = 1; i < K; i++)
{
for(int k = itv[j][1] + 1; k <= dr; k++)
{
int val = dp[i][k - 1] - j * sum[k - 1];
while(!dq[j][i].empty() && dq[j][i].back().first >= val) dq[j][i].pop_back();
dq[j][i].push_back({val, k});
}
while(!dq[j][i].empty() && dq[j][i].front().second < st) dq[j][i].pop_front();
}
itv[j][0] = st;
itv[j][1] = dr;
}
for(int j = 2; j <= K; j++)
{
dp[j][i] = 2e9 + 1;
if(i < j) continue;
for(int k = 0; k <= cnt1; k++)
if(!dq[k][j - 1].empty())
dp[j][i] = min(dp[j][i], dq[k][j - 1].front().first + k * sum[i]);
}
}
for(int i = 1; i <= K; i++)
printf("%d\n", dp[i][M]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |