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>
using namespace std;
const int MAX_N = 50;
const int MAX_T = 50000;
const int MAX_S = 50;
const long long INF = 1e15;
bool solved[MAX_N][MAX_T + 1];
int points[MAX_T + 1], last0[MAX_N][MAX_T + 1];
long long dp[MAX_T + 1][MAX_S + 1], solvers[MAX_T + 1];
int main() {
int n, t, s;
cin >> n >> t >> s;
for ( int i = 1; i <= t; i++ ) {
cin >> points[i];
points[i] += points[i - 1];
}
for ( int j = 0; j < n; j++ ) {
for ( int i = 1; i <= t; i++ ) {
char ch;
cin >> ch;
solved[j][i] = ch - '0';
last0[j][i] = (!solved[j][i] ? i : last0[j][i - 1]);
solvers[i] += ((long long)solved[j][i] << j);
}
}
for ( int i = 0; i <= t; i++ ) {
for ( int k = 0; k <= s; k++ )
dp[i][k] = INF;
}
dp[0][0] = 0;
for ( int i = 1; i <= t; i++ ) {
map<int, int> pos;
for ( int j = 0; j <= s && j <= i; j++ )
pos[i - j] = 0;
for ( int j = 0; j < n; j++ )
pos[last0[j][i]]++;
pos.erase( 0 );
int c = n;
for ( auto p = pos.rbegin(); p != pos.rend(); p++ ) {
int j = p->first;
c -= p->second;
for ( int k = 1; k <= s; k++ )
dp[i][k] = min( dp[i][k], dp[j - 1][k - 1] + (long long)c * (points[i] - points[j - 1]) );
}
}
for ( int k = 1; k <= s; k++ )
cout << dp[t][k] << "\n";
return 0;
}
# | 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... |