#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;
template<class X, class Y>
inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
const int MAXN = 20004;
const int MAXGROUP = 52;
int cnt[MAXN], sumP[MAXN], dp[MAXGROUP][MAXN], maxL[MAXGROUP][MAXN];
int point[MAXN], sum[MAXGROUP][MAXN], numTest, numPerson, maxGroup;
bool result[MAXGROUP][MAXN];
void DnC(int id, int l, int r, int optL, int optR) {
if(l > r)
return;
int mid = (l + r) >> 1, opt(-1);
for (int i = optL; i <= min(mid - 1, optR); ++i)
cnt[i] = 0;
int cntn(numPerson);
for (int j = 1; j <= numPerson; ++j) {
if(maxL[j][mid] > min(mid - 1, optR) + 1) {
--cntn;
} else {
++cnt[maxL[j][mid]];
}
}
for (int i = min(mid - 1, optR); i >= optL; --i) {
//cout << i << ' ' << mid << ' ' << cntn << '\n';
if(minimize(dp[id][mid], dp[id - 1][i] + cntn * (sumP[mid] - sumP[i])))
opt = i;
cntn -= cnt[i + 1];
}
DnC(id, l, mid - 1, optL, opt);
DnC(id, mid + 1, r, opt, optR);
}
void process(void) {
cin >> numPerson >> numTest >> maxGroup;
for (int i = 1; i <= numTest; ++i) {
cin >> point[i];
sumP[i] = sumP[i - 1] + point[i];
}
for (int j = 1; j <= numPerson; ++j) {
for (int i = 1; i <= numTest; ++i) {
char c;
cin >> c;
result[j][i] = (c == '1');
sum[j][i] = sum[j][i - 1] + result[j][i];
}
}
for (int j = 1; j <= maxGroup; ++j) {
for (int i = 1; i <= numTest; ++i)
dp[j][i] = 1e9+7;
}
for (int i = 1; i <= numTest; ++i) {
int cnt(0);
for (int j = 1; j <= numPerson; ++j)
cnt += (sum[j][i] == i);
dp[1][i] = cnt * sumP[i];
}
for (int i = 1; i <= numTest; ++i) {
for (int j = 1; j <= numPerson; ++j)
maxL[j][i] = (result[j][i] & result[j][i - 1]) ? maxL[j][i - 1] : i + (!result[j][i]);
}
/*for (int j = 1; j <= numPerson; ++j) {
for (int i = 1; i <= numTest; ++i)
cout << maxL[j][i] << " \n"[i == numTest];
}*/
for (int i = 2; i <= maxGroup; ++i)
DnC(i, i, numTest, 1, numTest);
for (int i = 1; i <= maxGroup; ++i)
cout << dp[i][numTest] << '\n';
}
int main(void) {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
process();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
8656 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
10844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
11356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
8656 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |