QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#441812#6300. Best Carry Player 2james1BadCreeper#WA 15ms3584kbC++171.3kb2024-06-14 18:44:302024-06-14 18:44:31

Judging History

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

  • [2024-06-14 18:44:31]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3584kb
  • [2024-06-14 18:44:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
typedef __int128 i28; 

void print(i28 x) {
    if (x > 9) print(x / 10); 
    cout.put(x % 10 ^ 48); 
}
void solve(void) {
    i64 x; int k; cin >> x >> k; 
    vector<int> a(20); 
    for (int i = 0; i < 18; ++i) a[i] = x % 10, x /= 10; 
    if (k == 0) {
        i28 ans = 1; 
        for (int j = 0; j < 19; ++j, ans *= 10)
            if (a[j] < 9) return print(ans), cout.put('\n'), void(); 
        assert(0); 
        return; 
    }
    i28 ans = 1e20; 
    i28 be = ans; 
    for (int i = 0; i < 1 << 18; ++i) if (__builtin_popcount(i) == k) {
        i28 res = 0, b = 1; 
        bool flg = 0, ok = 1; 
        for (int j = 0; j < 18; ++j, b *= 10) {
            if (a[j] + flg >= 10 && !(i >> j & 1)) { ok = 0; break; }
            if (i >> j & 1) {
                int t = 10 - flg - a[j]; 
                if (t == 10) { ok = 0; break; }
                res = t * b + res; 
                flg = 1; 
            } else {
                flg = 0; 
            }
        }
        if (ok) ans = min(ans, res); 
    }
    if (ans == be) cout << "-1\n"; 
    else print(ans), cout.put('\n'); 
}

int main(void) {
    ios::sync_with_stdio(0); 
    int T = 1; cin >> T; 
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3584kb

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: 15ms
memory: 3536kb

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
10000000001
9999910000
9999901000
9999900100
9999900010
9999900001
9000009999900001
99000009999900001
999000009999900001
-1
1000000000000000000

result:

wrong answer 20th lines differ - expected: '99999999999999999900000000000000000', found: '-1'