QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#288335#7880. Streak Manipulationckiseki#WA 1ms3560kbC++202.7kb2023-12-22 15:14:452023-12-22 15:14:47

Judging History

你现在查看的是最新测评结果

  • [2023-12-22 15:14:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3560kb
  • [2023-12-22 15:14:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#include <experimental/iterator>
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
void debug_(auto s, auto ...a) {
  cerr << "\e[1;32m(" << s << ") = (";
  int f = 0;
  (..., (cerr << (f++ ? ", " : "") << a));
  cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
  cerr << "\e[1;33m[ " << s << " ] = [ ";
  using namespace experimental;
  copy(L, R, make_ostream_joiner(cerr, ", "));
  cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif

const int inf = 1e9;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  string s;
  cin >> s;

  s = '0' + s + '0';
  vector<int> pre(n + 2);
  for (int i = 1; i <= n + 1; i++) {
    pre[i] = pre[i - 1] + (s[i] == '0');
  }

  /*
  vector<int> e;
  for (int i = 0, j = 0; i < n; i = j) {
    for (j = i; j < n; j++) {
      if (s[i] != s[j])
        break;
    }
    e.emplace_back(j - i);
  }
  assert (e.size() % 2 == 1);
  vector<int> one, zero;
  for (size_t i = 1; i < e.size(); i += 2) {
    one.emplace_back(e[i]);
    zero.emplace_back(e[i + 1]);
  }
  */

  // const int l = (int)one.size();
  const auto ok = [&](int L) {
    auto dp = vector(k + 1, vector(n + 2, inf));
    dp[0][0] = 0;

    for (int c = 1; c <= k; c++) {
      deque<pair<int,int>> dq; // value / index
      int mn = inf;
      int j = 0;
      for (int i = 1; i <= n + 1; i++) {
        if (s[i] == '0') {
          while (i - j - 1 >= L) {
            if (s[j] == '0')
              mn = min(mn, dp[c - 1][j] - pre[j]);
            ++j;
          }
          while (!dq.empty() && i - dq.front().second - 1 >= L) {
            dq.pop_front();
          }
          dp[c][i] = mn + pre[i - 1];
          if (!dq.empty()) {
            dp[c][i] = min(dp[c][i], dq.front().first + pre[i - 1]);
          }
          while (!dq.empty() && dq.back().first >= dp[c][i] - pre[i]) {
            dq.pop_back();
          }
          dq.emplace_back(dp[c][i] - pre[i], i);
        }
      }

      /*
      for (int i = 1; i <= n + 1; i++) {
        if (s[i] == '0') {
          for (int j = 0; j < i; j++) {
            if (s[j] == '0') {
              int f = (i - j - 1 >= L);
              dp[c][i] = min(dp[c][i], dp[c - f][j] + pre[i - 1] - pre[j]);
            }
          }
        }
      }
      */
    }

    debug(dp[k][n + 1]);
    return dp[k][n + 1] <= m;
  };

  if (!ok(1)) {
    cout << -1 << '\n';
    return 0;
  }

  int ans = 0;
  for (int step = 1 << 20; step; step >>= 1) {
    if (ok(ans + step)) {
      ans += step;
    }
  }
  cout << ans << '\n';

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3436kb

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3472kb

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

-1

result:

wrong answer 1st numbers differ - expected: '99', found: '-1'