# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127370 | roseanne_pcy | Popeala (CEOI16_popeala) | C++14 | 367 ms | 16652 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>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
const int maxt = 2e4+5;
const int maxn = 55;
ll pts[maxt];
char foo[maxn][maxt];
int n, t, s;
vector<int> lims[maxt];
ll mem[maxt];
ll dp[maxn][maxt];
void clear()
{
for(int i = 0; i<= n; i++) mem[i] = 1e18+5;
}
int main()
{
scanf("%d %d %d", &n, &t, &s);
for(int i = 1; i<= t; i++)
{
scanf("%lld", &pts[i]);
pts[i] += pts[i-1];
}
for(int i = 1; i<= n; i++)
{
scanf("%s", foo[i]+1);
}
for(int i = 1; i<= n; i++)
{
int last = 0;
for(int j = 1; j<= t; j++)
{
if(foo[i][j] == '1')
{
lims[j].pb(last);
}
else
{
lims[j].pb(j);
last = j;
}
}
}
for(int i = 1; i<= t; i++)
{
lims[i].pb(i);
sort(lims[i].begin(), lims[i].end());
}
for(int i = 0; i<= s; i++)
{
for(int j = 0; j<= t; j++)
{
dp[i][j] = 1e18;
}
}
dp[0][0] = 0;
for(int i = 1; i<= s; i++)
{
clear();
for(int j = 1; j<= t; j++)
{
// printf("computing %d\n", j);
for(int k = 0; k<= n; k++)
{
for(int run = j>1?lims[j-1][k]:0; run< lims[j][k]; run++)
{
mem[k] = min(mem[k], dp[i-1][run]-pts[run]*k);
// if(k == 0) printf("cand2 %d-%d\n", dp[i-1][run], pts[run]*k);
}
// printf("[%d..%d), %d\n", j>1?lims[j-1][k]:0, lims[j][k], mem[k]);
if(lims[j][k]> 0) dp[i][j] = min(dp[i][j], mem[k]+k*pts[j]);
// printf("cand %d\n", mem[k]+k*pts[j]);
}
// printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
}
printf("%lld\n", dp[i][t]);
}
}
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... |