QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#607426#8932. Bingoxing4c#WA 1ms3792kbC++143.5kb2024-10-03 14:54:522024-10-03 14:54:52

Judging History

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

  • [2024-10-03 14:54:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3792kb
  • [2024-10-03 14:54:52]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
#define int long long

void out(vector<int> s) {
    for (int i = s.size() - 1; i >= 0; i--)cout << s[i];
    cout << endl;
}

void solve() {
    string n1;
    cin >> n1;
    int m;
    cin >> m;

    reverse(n1.begin(), n1.end());
    int p = 0;
    if (n1.size() <= 18) {
        int mul = 1;
        for (auto e: n1) {
            p += (e - '0') * mul;
            mul *= 10;
        }
        if (p < m) {
            cout << m << endl;
            return;
        }
    }

    vector<int> n;
    for (auto e: n1) {
        n.push_back(e - '0');
    }
    int w = m;
    vector<int> num;
    while (w) {
        num.push_back(w % 10);
        w /= 10;
    }
    int flag1 = 0;

    for (int i = 0; i < n.size(); i++) {
        int flag = i;
        for (int j = 0; j < num.size(); j++) {
            if (i + j >= n.size()) {
                flag = -1;
                break;
            }
            if (n[i + j] != num[j]) {
                break;
                flag = -1;
            }
        }
        if (flag != -1) {
            if (i) {
                n[0] += 1;
                for (int j = 0; j < n.size() - 2; j++) {
                    n[j + 1] += n[j] / 10;
                    n[j] %= 10;
                }
                while (n.back() >= 10) {
                    n.push_back(n.back() / 10);
                    n[n.size() - 2] %= 10;
                }
                out(n);
                return;
            }
        }
    }


    vector<int> ans1(n);
    for (int i = num.size() - 1; i < n.size(); i++) {
        int flag = 0;
        for (int j = 0; j < num.size(); j++) {
            if (num[num.size() - 1 - j] < n[i - j]) {
                flag = 0;
                break;
            }
            if (num[num.size() - 1 - j] > n[i - j]) {
                flag = 1;
                break;
            }
        }
        if (flag) {
            flag1 = 1;
            for (int j = 0; j < num.size(); j++) {
                ans1[i - j] = num[num.size() - 1 - j];
            }
            int k = i - num.size();
            for (int j = 0; j <= k; j++)ans1[j] = 0;
            break;
        }
    }

    int res = 0;
    int mul = 1;
    for (auto e: n) {
        res += (e % m) * (mul % m);
        res %= m;
        mul = (mul * 10) % m;
    }

    vector<int> ans2;
    int gap = m - res;
    for (int i = 0; i < ans1.size(); i++) {
        int val = gap % 10 + n[i];
        gap /= 10;
        ans2.push_back(val);
    }

    for (int i = 0; i < ans2.size() - 1; i++) {
        ans2[i + 1] += ans2[i] / 10;
        ans2[i] %= 10;
    }
    while (ans2.back() >= 10) {
        ans2.push_back(ans2.back() / 10);
        ans2[ans2.size() - 2] %= 10;
    }
    if (p == m)flag1 = 0;
    if (flag1) {
        if (ans1.size() < ans2.size()) {
            out(ans1);
            return;
        }
        int ans = 1;
        for (int i = ans1.size() - 1; i >= 0; i--) {
            if (ans1[i] > ans2[i]) {
                ans = 2;
                break;
            }
            if (ans2[i] > ans1[i]) {
                ans = 1;
                break;
            }
        }
        if (ans == 1) {
            out(ans1);
        } else out(ans2);
    } else out(ans2);
}

signed main() {
  //  freopen("D:\\Development_Software\\CLion\\CLionProjects\\Test\\in", "r", stdin);
    ios::sync_with_stdio(false);
    int T = 1;
    cin >> T;
    while (T--) solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3792kb

input:

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

output:

9
13
10
250
1370
3

result:

wrong answer 4th lines differ - expected: '251', found: '250'