답안 #680697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
680697 2023-01-11T14:22:41 Z peijar 조교 (CEOI16_popeala) C++17
26 / 100
2000 ms 34092 KB
#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>> prvWA(nbEleves, vector<int>(nbTests + 1, -1));
  for (int i = 0; i < nbEleves; ++i)
    for (int j = 0; j < nbTests; ++j) {
      char c;
      cin >> c;
      prvWA[i][j + 1] = prvWA[i][j];
      if (c == '0')
        prvWA[i][j + 1] = j;
    }

  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) {
        if (prvWA[iEleve][testRestant] != -1)
          posChange.push_back(prvWA[iEleve][testRestant]);
      }
      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;
        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 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 924 KB Output is correct
2 Correct 63 ms 904 KB Output is correct
3 Correct 62 ms 924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 4392 KB Output is correct
2 Correct 475 ms 4884 KB Output is correct
3 Correct 646 ms 5304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 66 ms 924 KB Output is correct
4 Correct 63 ms 904 KB Output is correct
5 Correct 62 ms 924 KB Output is correct
6 Correct 361 ms 4392 KB Output is correct
7 Correct 475 ms 4884 KB Output is correct
8 Correct 646 ms 5304 KB Output is correct
9 Correct 1058 ms 9884 KB Output is correct
10 Correct 1552 ms 17288 KB Output is correct
11 Execution timed out 2075 ms 34092 KB Time limit exceeded
12 Halted 0 ms 0 KB -