QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#625782#8932. Bingosupepapupu#WA 231ms3904kbC++202.9kb2024-10-09 21:01:052024-10-09 21:01:06

Judging History

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

  • [2024-10-09 21:01:06]
  • 评测
  • 测评结果:WA
  • 用时:231ms
  • 内存:3904kb
  • [2024-10-09 21:01:05]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;

vector<int> read() {
    vector<int> k;
    char c = getchar();
    while (c < '0' || c > '9') c = getchar();
    while (c >= '0' && c <= '9') {
        k.emplace_back(c - '0');
        c = getchar();
    }
    reverse(k.begin(), k.end());
    return k;
}

void print(vector<int> &a) {
    for (int i = a.size() - 1; i >= 0; --i) putchar('0' + a[i]);
    puts("");
}

int cmp(const vector<int> &a, const vector<int> &b) {
    if (a.size() > b.size()) return 1;
    if (a.size() < b.size()) return -1;
    for (int i = a.size() - 1; i >= 0; --i) {
        if (a[i] > b[i]) return 1;
        if (b[i] > a[i]) return -1;
    }
    return 0;
}

vector<int> mul(const vector<int> &a, ll k) {
    vector<int> res(a.size());
    ll t = 0;
    for (int i = 0; i < a.size(); ++i) {
        t += a[i] * k;
        res[i] = t % 10;
        t /= 10;
    }
    while (t) {
        res.emplace_back(t % 10);
        t /= 10;
    }
    return res;
}

vector<int> add(const vector<int> &a, ll k) {
    ll t = k;
    vector<int> res(a.size());
    for (int i = 0; i < a.size(); ++i) {
        t += a[i];
        res[i] = t % 10;
        t /= 10;
    }
    while (t) {
        res.emplace_back(t % 10);
        t /= 10;
    }
    return res;
}

void shrink(vector<int> &a) {
    while (a.size() > 1 && !a.back()) a.pop_back();
}

vector<int> div(const vector<int> &a, ll k) {
    vector<int> res(a.size());
    ll t = 0;
    for (int i = a.size() - 1; i >= 0; --i) {
        t += a[i];
        res[i] = t / k;
        t %= k;
        t *= 10;
    }
    shrink(res);
    return res;
}

void solve() {
    vector<int> n = read();
    ll m; scanf("%lld", &m);
    vector<int> ans = mul(div(n, m), m);
    ans = add(ans, m);
    n = add(n, 1);
    for (int i = 0; i < n.size(); ++i) {
        int t = m;
        int p = i, ok = 1;
        while (t) {
            if (p >= n.size() || n[p] != t % 10) {
                ok = 0;
                break;
            }
            t /= 10;
            ++p;
        }
        if (ok) return print(n);
    }
    ll pw = 1;
    int p = 0;
    vector<int> tt = n;
    while (pw <= m) {
        pw *= 10;
        if (p < tt.size()) tt[p++] = 0;
    }
    shrink(tt);
    for (int i = 0; i < 20; ++i) {
        auto t = add(tt, m);
        if (cmp(t, n) < 0) t = add(t, pw);
        if (cmp(t, ans) < 0) ans = move(t);
        if (p < tt.size()) tt[p++] = 0, shrink(tt);
        pw *= 10;
        m *= 10;
    }
    print(ans);
}

int main() {
    // ios::sync_with_stdio(0); cin.tie(0);
    int tcase = 1;
    cin >> tcase;
    while (tcase--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 212ms
memory: 3680kb

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
7614814251
2814581097
1075124424
7822266300
1767317769
7189709850
9061337569
6552679238
9946082160
5497675063
7787300365
4310767268
4811342000
3265496131
8294404062
2845521790
1114254674
6442013673
3744046867
3289624375
6477935360
1292587551
5504674689
2898829180
7882736025
2846033387
923...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 231ms
memory: 3904kb

input:

100000
81390699571930639918 18
48435143897560239761 20
51628960043353404809 75
47871552664477358704 12
59273263135375104780 37
76916933870890715781 71
23716799616473386311 99
68152894841119747794 73
87132912926681514765 23
14152130046962902029 76
46737628796812988809 24
40572731276115804589 44
26281...

output:

/408379282588696576
0961635208879144960
-559312997592596480
*748611503717351424
59273263135375104781
76916933870890715782
23716799616473386312
,006057071302148096
12319535557742690304
7559312997592596480
4068147061460041728
1153962250654973952
26281826064684565884
7559312997592596480
,68652151355945...

result:

wrong answer 1st lines differ - expected: '81390699571930639920', found: '/408379282588696576'