#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef unsigned long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
freopen("Problem.in", "r", stdin); freopen("Problem.out", "w", stdout);
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
const ll INF = 1e14;
/***********************CEOI 2016 D2 Popeala*****************************************/
const int MAXN = 50, MAXT = 20000;
int N, T, S;
ll P[MAXT];
int res[MAXN][MAXT];
ll dp[MAXN + 1][MAXT + 1];
int G[MAXT];
ll best[MAXN + 1];
int last[MAXN];
v<int> badIntv[MAXT];
int main() {
io();
cin >> N >> T >> S;
FOR(i, 0, T) cin >> P[i];
FOR(i, 0, N) FOR(j, 0, T) {
char c; cin >> c;
res[i][j] = c - '0';
}
FORE(i, 0, S) FORE(j, 0, T)
dp[i][j] = INF;
dp[0][T] = 0;
FOR(i, 0, N) last[i] = T;
RFORE(i, T - 1, 0) {
FOR(c, 0, N) if (res[c][i] == 0) {
if (i + 1 < last[c])
badIntv[i].push_back(last[c] - 1);
last[c] = i;
}
sort(all(badIntv[i]));
}
FORE(k, 1, S) {
FORE(g, 0, N) best[g] = INF;
RFORE(i, T - 1, 0) {
FORE(g, 0, N) best[g] += g*P[i];
for (auto j : badIntv[i])
best[G[j]] = INF;
if (!badIntv[i].empty()) {
int pb = 0; // pointer to first j<badintv[i][pb]
int sum = P[i];
FOR(j, i + 1, T) {
G[j] -= badIntv[i].size() - pb;
sum += P[j];
minn(best[G[j]], G[j] * sum + dp[k - 1][j + 1]);
while (pb < badIntv[i].size() && badIntv[i][pb] <= i)
pb++;
if (pb == badIntv[i].size())
break;
}
}
// add i into best
int num1 = 0;
FOR(c, 0, N) if (res[c][i] == 1)
num1++;
G[i] = num1;
minn(best[num1], P[i] * num1 + dp[k - 1][i + 1]);
// calc dp[k][i]
FORE(g, 0, N)
minn(dp[k][i], best[g]);
// cout << "dp " << k << " " << i << " = " << dp[k][i] << "\n";
}
}
FORE(i, 1, S)
cout << dp[i][0] << "\n";
}
Compilation message
popeala.cpp: In function 'int main()':
popeala.cpp:93:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while (pb < badIntv[i].size() && badIntv[i][pb] <= i)
~~~^~~~~~~~~~~~~~~~~~~
popeala.cpp:95:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (pb == badIntv[i].size())
~~~^~~~~~~~~~~~~~~~~~~~
popeala.cpp: In function 'void io()':
popeala.cpp:33:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("Problem.in", "r", stdin); freopen("Problem.out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:33:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("Problem.in", "r", stdin); freopen("Problem.out", "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |