QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250865#6300. Best Carry Player 2DepletedPrism#WA 0ms3632kbC++172.0kb2023-11-13 20:00:112023-11-13 20:00:12

Judging History

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

  • [2023-11-13 20:00:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2023-11-13 20:00:11]
  • 提交

answer

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

using LL = long long;
using i128 = __int128;

i128 xpw10(int x, int l) { // x * (10 ** l)
  static vector<i128> pw10{1};
  int n = (int)pw10.size();
  if (l >= n) {
    pw10.resize(l + 1);
    for (int i = n; i <= l; ++i)
      pw10[i] = 10 * pw10[i - 1];
  }
  return x * pw10[l];
}

void print(i128 x) {
  if (x > 0) {
    print(x / 10);
    cout << char('0' + x % 10);
  }
}

int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int ti;
  cin >> ti;
  while (ti--) {
    LL x; int k;
    cin >> x >> k;

    vector<int> a;
    for (LL i = x; i > 0; i /= 10)
      a.push_back(int(i % 10));
    int n = (int)a.size(), m = n + k;
    a.resize(m + 1, 0);
    vector<int> nl(m + 1);
    nl[m] = (a[m] == 9);
    for (int i = m - 1; i >= 0; --i)
      nl[i] = (a[i] == 9)? nl[i + 1] + 1: 0;

    // for (auto v: a) cout << v << ' ';
    // cout << endl;
    // for (auto v: nl) cout << v << ' ';
    // cout << endl;

    i128 ans = (i128(1) << 126) - 1 + (i128(1) << 126);
    if (k == 0) {
      for (int i = 0; i <= m; ++i) if (a[i] < 9) {
        ans = xpw10(1, i);
        break;
      }
    } else {
      for (int p = 0; p < n; ++p) {
        auto b = a;
        i128 y = 0;
        int cur = k;
        for (int i = p; i < m; ++i) if (b[i] > 0) {
          int j = i; // [i, j]: j - i + 1, 
          while (j + 1 < m && cur - (j + 1 + nl[j + 2] - i + 1) >= 0)
            ++j;
          if (cur - (j + nl[j + 1] - i + 1) >= 0) {
            j += nl[j + 1];
            cur -= (j - i + 1);
            // cout << cur << endl;
            // cout << "[" << i << ", " << j << "]" << endl;
            y += xpw10(10 - b[i], i);
            for (int l = i + 1; l <= j; ++l)
              y += xpw10(9 - b[l], l);
            ++b[j + 1], i = j;
            if (cur == 0) break;
          }
        }
        if (cur == 0)
          ans = min(ans, y);
      }
    }

    print(ans), cout << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3628kb

input:

4
12345678 0
12345678 5
12345678 18
990099 5

output:

1
54322
999999999987654322
9910

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3632kb

input:

21
999990000099999 0
999990000099999 1
999990000099999 2
999990000099999 3
999990000099999 4
999990000099999 5
999990000099999 6
999990000099999 7
999990000099999 8
999990000099999 9
999990000099999 10
999990000099999 11
999990000099999 12
999990000099999 13
999990000099999 14
999990000099999 15
999...

output:

100000
10000
1000
100
10
1
900001
9900001
99900001
999900001
10999910000
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
99999999999999999900000000000000000
1000000000000000000

result:

wrong answer 11th lines differ - expected: '10000000001', found: '10999910000'