#include <bits/stdc++.h>
#define int long long
using namespace std;
namespace std {
template <typename T> ostream &operator<<(ostream &out, const vector<T> &vec) {
out << "[";
for (int i = 0; i < (int)vec.size(); ++i) {
out << vec[i];
if (i + 1 < (int)vec.size())
out << ", ";
}
return out << "]";
}
} // namespace std
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) {
cout << ' ' << H;
dbg_out(T...);
}
#ifdef DEBUG
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif
const int INF = 1e18;
struct SegTree {
vector<int> seg;
int from;
SegTree(int sz) {
from = 1;
while (from < sz)
from *= 2;
seg.assign(2 * from, INF);
}
void upd(int i, int x) {
i += from;
seg[i] = x;
while (i > 1) {
i /= 2;
seg[i] = min(seg[2 * i], seg[2 * i + 1]);
}
}
int query(int deb, int fin) {
deb += from, fin += from;
int ret = INF;
while (deb < fin) {
if (deb % 2)
ret = min(ret, seg[deb++]);
if (fin % 2)
ret = min(ret, seg[--fin]);
deb /= 2;
fin /= 2;
}
return ret;
}
};
signed main(void) {
ios_base::sync_with_stdio(false);
cin.tie(0);
int nbEleves, nbTests, maxSubtasks;
cin >> nbEleves >> nbTests >> maxSubtasks;
vector<int> points(nbTests), prefSum(nbTests + 1);
for (int i = 0; i < nbTests; ++i) {
cin >> points[i];
prefSum[i + 1] = prefSum[i] + points[i];
}
vector<vector<int>> posWA(nbEleves);
for (int iEleve = 0; iEleve < nbEleves; ++iEleve)
for (int iTest = 0; iTest < nbTests; ++iTest) {
char c;
cin >> c;
if (c == '0')
posWA[iEleve].push_back(iTest);
}
vector<SegTree> segtrees(nbEleves + 1, nbTests + 1);
for (int i = 0; i <= nbEleves; ++i)
segtrees[i].upd(0, 0);
for (int nbTaches = 1; nbTaches <= maxSubtasks; ++nbTaches) {
vector<int> dp(nbTests + 1, INF);
for (int testRestant = 1; testRestant <= nbTests; ++testRestant) {
vector<int> posChange;
for (int iEleve = 0; iEleve < nbEleves; ++iEleve) {
int i = lower_bound(posWA[iEleve].begin(), posWA[iEleve].end(),
testRestant) -
posWA[iEleve].begin();
if (i)
posChange.push_back(posWA[iEleve][i - 1]);
}
sort(posChange.rbegin(), posChange.rend());
int prv = testRestant - 1;
for (int nbMauvais = 0; nbMauvais <= (int)posChange.size(); ++nbMauvais) {
int nxt = nbMauvais == (int)posChange.size()
? -1
: posChange[nbMauvais]; // can't take nxt
int nbBons = nbEleves - nbMauvais;
dbg(testRestant, nxt, prv);
dp[testRestant] =
min(dp[testRestant], nbBons * prefSum[testRestant] +
segtrees[nbBons].query(nxt + 1, prv + 1));
prv = nxt;
}
}
for (int nbBons = 0; nbBons <= nbEleves; ++nbBons)
for (int i = 0; i <= nbTests; ++i) {
segtrees[nbBons].upd(i, dp[i] - nbBons * prefSum[i]);
}
dbg(dp);
cout << dp.back() << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
772 KB |
Output is correct |
2 |
Correct |
74 ms |
760 KB |
Output is correct |
3 |
Correct |
82 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
445 ms |
3712 KB |
Output is correct |
2 |
Correct |
650 ms |
3920 KB |
Output is correct |
3 |
Correct |
726 ms |
3984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
89 ms |
772 KB |
Output is correct |
4 |
Correct |
74 ms |
760 KB |
Output is correct |
5 |
Correct |
82 ms |
724 KB |
Output is correct |
6 |
Correct |
445 ms |
3712 KB |
Output is correct |
7 |
Correct |
650 ms |
3920 KB |
Output is correct |
8 |
Correct |
726 ms |
3984 KB |
Output is correct |
9 |
Correct |
1167 ms |
7768 KB |
Output is correct |
10 |
Correct |
1841 ms |
14548 KB |
Output is correct |
11 |
Execution timed out |
2078 ms |
27596 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |