# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
97521 | popovicirobert | Popeala (CEOI16_popeala) | C++14 | 523 ms | 28700 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>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const ll INF = 1e15;
const int MAXN = 50;
const int MAXT = 20000;
int pts[MAXT + 1], sp[MAXT + 1];
char res[MAXN + 1][MAXT + 1];
int ind[MAXN + 1][MAXT + 1];
ll dp[2][MAXT + 1];
ll mn[2][MAXN + 1][MAXT + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, j, n, t, s;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> t >> s;
for(i = 1; i <= t; i++) {
cin >> pts[i];
sp[i] = sp[i - 1] + pts[i];
}
for(i = 1; i <= n; i++) {
cin >> res[i] + 1;
for(j = 1; j <= t; j++) {
res[i][j] -= '0';
if(res[i][j] == 0) {
ind[i][j] = j;
}
else {
ind[i][j] = ind[i][j - 1];
}
}
}
vector < vector <int> > pos(t + 1);
for(i = 1; i <= t; i++) {
for(j = 1; j <= n; j++) {
pos[i].push_back(ind[j][i]);
}
sort(pos[i].begin(), pos[i].end());
pos[i].push_back(i);
}
dp[0][0] = 0;
for(j = 1; j <= t; j++) {
dp[0][j] = INF;
}
for(int k = 1; k <= s; k++) {
for(i = 0; i <= n; i++) {
mn[1 - k & 1][i][0] = dp[1 - k & 1][0];
for(j = 1; j <= t; j++) {
mn[1 - k & 1][i][j] = min(mn[1 - k & 1][i][j - 1], dp[1 - k & 1][j] - sp[j] * i);
}
}
dp[k & 1][0] = INF;
for(j = 1; j <= t; j++) {
dp[k & 1][j] = INF;
for(i = 0; i < pos[j].size(); i++) {
if(pos[j][i] > 0) {
dp[k & 1][j] = min(dp[k & 1][j], mn[1 - k & 1][i][pos[j][i] - 1] + sp[j] * i);
//cerr << pos[j][i] << " ";
}
}
//cerr << " ";
//cerr << dp[k & 1][j] << " ";
}
//cerr << "\n";
cout << dp[k & 1][t] << "\n";
}
//cin.close();
//cout.close();
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... |