QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#617962#8932. BingoLegend_dy#WA 81ms3768kbC++202.0kb2024-10-06 17:53:572024-10-06 17:53:57

Judging History

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

  • [2024-10-06 17:53:57]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:3768kb
  • [2024-10-06 17:53:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

constexpr int inf = 1e9;

void fix(string &a) {
    reverse(a.begin(), a.end());
    while (a.size() > 1 && a.back() == '0') {
        a.pop_back();
    }
    reverse(a.begin(), a.end());
}
string add(string a, string b) {
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    int n = a.size();
    int m = b.size();
    string c(max(n, m), '0');
    int t = 0;
    for (int i = 0; i < max(n, m); i++) {
        int x = (i < n ? a[i] - '0' : 0);
        int y = (i < m ? b[i] - '0' : 0);
        c[i] = char((t + x + y) % 10 + '0');
        t = (t + x + y) / 10;
    }
    if (t) c += char(t + '0');
    reverse(c.begin(), c.end());
    fix(c);
    return c;
}


void solve() {
    string ns;
    int m;
    cin >> ns >> m;
    for (int i = 0; i < 15; i++) ns = '0' + ns;
    string ms = to_string(m);

    int r = 0;
    for (int i = ns.size() - 1; i >= 0; i--) {
        r = (10ll * r + (ns[i] - '0')) % m;
    }
    string ans1 = add(ns, to_string(m - r));
    fix(ans1);
    
    tuple<int, int, int> mx{-1, 0, 0};
    
    for (int i = 0; i + ms.size() - 1 < ns.size(); i++) {
        for (int j = 0; j < ms.size(); j++) {
            if (ns[i] > ms[j]) break;
            if (ns[i] < ms[j]) {
                mx = max(mx, {i + j, -(ms[j] - '0'), i});
                break;
            }
        }
    }
    string ans2 = ns;
    int d = get<2>(mx);
    for (int j = 0; j < ms.size(); j++) {
        ans2[j + d] = ms[j];
    }
    for (int j = ms.size(); j + d < ns.size(); j++) {
        ans2[j + d] = '0';
    }
    fix(ans2);

    string ans;
    if (ans1.size() == ans2.size()) {
        ans = min(ans1, ans2);
    }else {
        ans = (ans1.size() > ans2.size() ? ans2 : ans1);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

詳細信息

Test #1:

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

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: 81ms
memory: 3768kb

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:

3196282259
7614814251
2814581097
1075124449
7822266314
1767317774
7189709875
9061337553
6552679238
9946082160
5497675092
7787300365
4310767268
4811342053
3265496150
8294404058
2845521774
1114254696
6442013000
3744046906
3289624375
6477935363
1292587536
5504674689
2898829180
7882736025
2846033373
923...

result:

wrong answer 1st lines differ - expected: '3196282244', found: '3196282259'