QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#276218#7880. Streak Manipulation01shijian#WA 1ms3812kbC++201.8kb2023-12-05 18:14:492023-12-05 18:14:49

Judging History

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

  • [2023-12-05 18:14:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3812kb
  • [2023-12-05 18:14:49]
  • 提交

answer

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

#ifdef LOCAL
  #include <debugger>
#else
  #define debug(...) 42
#endif

template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }

constexpr int INF = 1E9;

void solve() {
  int n, m, k; cin >> n >> m >> k;
  string str; cin >> str;
  str = "0" + str + "0";
  vector<int> s(n + 1), pre(n + 1);
  for (int i = 1; i <= n; i ++ ) {
    s[i] = s[i - 1] + (str[i] == '0');
  }
  int last = 0;
  for (int i = 1; i <= n; i ++ ) {
    if (str[i] == '0') {
      last = i;
      pre[i] = i;
    } else {
      pre[i] = last;
    }
  }

  auto check = [&] (int x) -> bool {
    vector<vector<int> > dp(n + 2, vector<int> (k + 1, INF));
    dp[0][0] = 0; // d[i][j]   s[i] = 0 并且有j个合法的子串的最小操作次数 01xxx0  j  
    for (int i = x; i <= n; i ++ ) if (str[i + 1] == '0') {
      if (str[i] == '0') {
        for (int j = 0; j <= k; j ++ ) {
          chkmin(dp[i][j], dp[pre[i - 1]][j]);
        }  
      }
      for (int j = 1; j <= k; j ++ ) {
        int p = pre[i - x];  //  s[r] - s[l - 1]
        chkmin(dp[i + 1][j], dp[p][j - 1] + s[i] - s[p]);        
      }
    } else if (str[i] == '0') {
      for (int j = 0; j <= k; j ++ ) {
        chkmin(dp[i][j], dp[pre[i - 1]][j]);
      }
    }
    for (int i = 0; i <= n + 1; i ++ ) if (dp[i][k] <= m) {
      return true;
    }    
    return false;
  };

  if (not check(1)) return cout << "-1\n", void();

  int l = 1, r = n;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (check(mid)) l = mid;
    else r = mid - 1;
  }

  cout << l << "\n";

  

}
int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  solve();
  return 0;
}

詳細信息

Test #1:

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

input:

8 3 2
10110110

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

12 3 3
100100010011

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

4 4 4
0000

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1000 200 5
0001001000101001110010011001101010110101101100010100111110111111010010001100100111100101011100011101011001110010111100100100011001010011000100011111010110100001101110101001110000001000111010000111110100111101100110011010011111000111101001010011000111010111010100101111100000100001011001010...

output:

9

result:

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