이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 4100;
int cnt[maxn][maxn], n, t, s;
int pref[55][maxn];
int points[maxn];
int prefpoints[maxn];
int dp[maxn][maxn];
bool matrix[maxn][maxn];
/*
n - contestants
t - test cases
s - subtasks
*/
int main() {
cin>>n>>t>>s;
for(int i=1;i<=t;i++) {
cin>>points[i];
prefpoints[i] = prefpoints[i-1] + points[i];
}
string code;
for(int i=0;i<n;i++) {
cin>>code;
for(int j=1;j<=t;j++) {
pref[i][j] = pref[i][j-1] + int(code[j-1]-'0');
}
}
for(int i=1;i<=t;i++) {
for(int j=1;j<=i;j++) {
for(int k=0;k<n;k++) {
if(pref[k][i] - pref[k][j-1] == (i-j+1)) {
cnt[j][i]++;
}
}
}
}
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for(int i=1;i<=t;i++) {
for(int j=1;j<=s;j++) {
dp[i][j] = INT_MAX;
for(int x=0;x<i;x++) {
if(dp[x][j-1] != -1) {
dp[i][j] = min(dp[i][j], dp[x][j-1] + (prefpoints[i] - prefpoints[x]) * cnt[x+1][i]);
}
}
if(dp[i][j] == INT_MAX) dp[i][j] = -1;
}
}
for(int i=1;i<=s;i++) {
cout<<dp[t][i]<<"\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... |