답안 #788619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
788619 2023-07-20T12:18:24 Z WLZ 조교 (CEOI16_popeala) C++17
100 / 100
356 ms 255564 KB
#include <bits/stdc++.h>
using namespace std;

const int INF = 0x3f3f3f3f;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, t, s;
  cin >> n >> t >> s;
  vector<int> points(t + 1, 0);
  for (int i = 1; i <= t; i++) cin >> points[i], points[i] += points[i - 1];
  vector<string> results(n);
  for (int i = 0; i < n; i++) cin >> results[i], results[i] = "$" + results[i];
  vector< vector<int> > dp(t + 1, vector<int>(s + 1, INF)); dp[0][0] = 0;
  vector< vector< vector<int> > > mn(t + 1, vector< vector<int> >(s + 1, vector<int>(n + 1, INF))); mn[0][0].assign(n + 1, 0);
  vector<int> last(n, -1), order(n);
  iota(order.begin(), order.end(), 0);
  for (int i = 1; i <= t; i++) {
    for (int j = 0; j < n; j++) if (results[j][i] == '0') last[j] = i;
    sort(order.begin(), order.end(), [&](int a, int b) {
      return last[a] < last[b];
    });
    for (int j = 1; j <= s; j++) {
      dp[i][j] = mn[i - 1][j - 1][n] + n * points[i];
      for (int k = n - 1; k >= 0; k--) {
        if (last[order[k]] == -1) continue;
        dp[i][j] = min(dp[i][j], mn[last[order[k]] - 1][j - 1][k] + k * points[i]);
      }
    }
    for (int j = 0; j <= s; j++) {
      for (int k = 0; k <= n; k++) mn[i][j][k] = min(mn[i - 1][j][k], dp[i][j] - k * points[i]);
    }
  }
  for (int i = 1; i <= s; i++) cout << dp[t][i] << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 6604 KB Output is correct
2 Correct 7 ms 6228 KB Output is correct
3 Correct 8 ms 6604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 26632 KB Output is correct
2 Correct 53 ms 38612 KB Output is correct
3 Correct 74 ms 51356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 8 ms 6604 KB Output is correct
4 Correct 7 ms 6228 KB Output is correct
5 Correct 8 ms 6604 KB Output is correct
6 Correct 37 ms 26632 KB Output is correct
7 Correct 53 ms 38612 KB Output is correct
8 Correct 74 ms 51356 KB Output is correct
9 Correct 108 ms 83144 KB Output is correct
10 Correct 142 ms 108740 KB Output is correct
11 Correct 325 ms 239376 KB Output is correct
12 Correct 341 ms 255476 KB Output is correct
13 Correct 356 ms 255564 KB Output is correct
14 Correct 330 ms 255464 KB Output is correct
15 Correct 327 ms 255428 KB Output is correct