QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875476#9684. 倾诉testngifaicnslvthis#0 0ms0kbC++141.6kb2025-01-29 20:38:052025-01-29 20:38:11

Judging History

This is the latest submission verdict.

  • [2025-01-29 20:38:11]
  • Judged
  • Verdict: 0
  • Time: 0ms
  • Memory: 0kb
  • [2025-01-29 20:38:05]
  • Submitted

answer

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

using i64 = long long;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

bool check(int n, int k, vector<int> a, int target_max_worry) {
  function<bool(vector<int>, int)> solve = 
    [&](vector<int> current_worries, int operations_left) {
    if (*max_element(current_worries.begin(), current_worries.end()) <= target_max_worry) {
      return true;
    }
    if (operations_left == 0) {
      return false;
    }
    for (int p = 0; p < n - 1; ++p) {
      vector<int> next_worries = current_worries;
      next_worries[p + 1] += next_worries[p] / 2;
      next_worries[p] /= 2;
      if (solve(next_worries, operations_left - 1)) {
        return true;
      }
    }
    return false;
  };
  return solve(a, k);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }

    int low = 0, high = *max_element(a.begin(), a.end());
    int min_max_worry = high;
    while (low <= high) {
      int mid = low + (high - low) / 2;
      if (check(n, k, a, mid)) {
        min_max_worry = mid;
        high = mid - 1;
      } else {
        low = mid + 1;
      }
    }

    i64 s = (i64)min_max_worry;
    for (int i = 0; i < k; ++i) {
      s *= 2;
    }

    if (s == 0) {
      cout << 0 << '\n';
    } else {
      string binary_s = "";
      while (s > 0) {
        binary_s = (s % 2 == 0 ? "0" : "1") + binary_s;
        s /= 2;
      }
      cout << binary_s << '\n';
    }
  }
  return 0;
}

詳細信息

Subtask #1:

score: 0
Time Limit Exceeded

Test #1:

score: 0
Time Limit Exceeded

input:

5
6 1
11764 28428 28179 18698 6443 20288
6 3
29 17548 61962 31242 8172 4107
6 15
7 2 239427 137145 171239 3
6 4
294 211 407 190 2 2
6 5
197190 265870 12121 144584 21313 14169

output:


result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Time Limit Exceeded

Test #60:

score: 0
Time Limit Exceeded

input:

1666
6 1
282 719 29 355 388 275
6 1
348 766 91 299 474 96
6 23
5 2 8554 8554 8554 2
6 1
84 195 23 37 120 117
6 3
8 3 51 62 28 5
6 3
3 64 64 4 4 2
6 9
5 552 552 552 552 5
6 3
3611 1144 417 3461 459 755
6 3
777 315 1007 5 2 1061
6 6
1300 2101 4 1877 360 2434
6 1
384 713 168 25 524 390
6 3
203 18 305 1...

output:


result:


Subtask #6:

score: 0
Memory Limit Exceeded

Test #80:

score: 0
Memory Limit Exceeded

input:

3333
6 1000000000
131727 7 4 170194 6 59263
6 1000000000
417714 286613 7 310122 6 4
6 1000000000
63764 2430 2696 6699 8478 22261
6 1000000000
217 131 6 1487 2927 2
6 1000000000
26225 27991 3842 72525 4521 5231
6 1000000000
34409 26001 23563 19345 30764 24919
6 1000000000
97981 138532 59280 82393 128...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #4:

0%