QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#801604#8932. BingoNoobie_99#WA 267ms3588kbC++201.9kb2024-12-07 03:49:152024-12-07 03:49:15

Judging History

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

  • [2024-12-07 03:49:15]
  • 评测
  • 测评结果:WA
  • 用时:267ms
  • 内存:3588kb
  • [2024-12-07 03:49:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) ::begin(x), ::end(x)
void _d(auto... x) { ((cerr << ' ' << x), ...) << endl; }
#define debug(x...) cerr << "["#x"]:", _d(x)

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int T;
    cin >> T;
    while (T--) {
        string a;
        ll m;
        cin >> a >> m;
        string b = to_string(m);
        a = string(100, '0') + a;

        ll rest = 0;
        for (char c : a | views::reverse) {
            rest = (rest*10 + c-'0') % m;
        }
        rest = m - rest;
        ll ans = rest;

        auto add = [&](ll x) {
            ans -= x;
            string y = to_string(x);
            reverse(all(a));
            reverse(all(y));
            ll carry = 0;
            for (int i=0; i<ssize(y) || carry > 0; i++) {
                if (i < ssize(y)) carry += y[i] - '0';
                if (i == ssize(a)) a.push_back('0' + (carry % 10));
                else {
                    carry += a[i] - '0';
                    a[i] = '0' + (carry % 10);
                }
                carry /= 10;
            }
            reverse(all(a));
        };
        add(1);

        ll idk = 1;
        for (int it=0; it<15; it++, idk *= 10) {
            for (int i=0; i+ssize(b)<=ssize(a); i++) {
                if (a.substr(i, ssize(b)) == b) ans = 0;
            }
            ll x = stoll(a.substr(ssize(a)-ssize(b)-it, ssize(b)));
            if (x <= m) {
                ans = min<__int128>(ans, (__int128)(m-x)*idk);
            }
            if (a[ssize(a)-1-it] != '0') {
                x = ('9' - a[ssize(a)-1-it] + 1) * idk;
                if (x < ans) add(x);
                else break;
            }
        }

        add(ans);
        int zero = 0;
        while (a[zero] == '0') zero++;
        a = a.substr(zero);
        cout << a << '\n';
    }
}

详细

Test #1:

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

input:

6
7 3
12 3
9 10
249 51
1369 37
2 1

output:

9
13
10
251
1370
3

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 267ms
memory: 3588kb

input:

100000
3196282243 28
7614814237 33
2814581084 97
1075124401 58
7822266214 100
1767317768 31
7189709841 75
9061337538 69
6552679231 38
9946082148 18
5497675062 54
7787300351 65
4310767261 68
4811341953 100
3265496130 31
8294404054 62
2845521744 90
1114254672 26
6442013672 13
3744046866 40
3289624367 ...

output:

3196282244
7614814245
2814581097
1075124417
7822266314
1767317769
7189709875
9061337569
6552679238
9946082160
5497675063
7787300365
4310767268
4811342053
3265496131
8294404062
2845521774
1114254678
6442013673
3744046867
3289624375
6477935357
1292587539
5504674689
2898829180
7882736025
2846033387
923...

result:

wrong answer 2nd lines differ - expected: '7614814251', found: '7614814245'