QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#631770#8932. BingoricofxWA 1ms3776kbC++203.2kb2024-10-12 10:12:342024-10-12 10:12:35

Judging History

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

  • [2024-10-12 10:12:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3776kb
  • [2024-10-12 10:12:34]
  • 提交

answer

//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

int n, m;
ll po[15];
string a;
ll get(const string& s, int l, int r) {
    ll res = 0;
    for (int i = l; i <= r; i++) res = res * 10ll + s[i] - '0';
    return res;
}
ll fm[11][11];
#define plus miku
void plus(string &a, ll b) {
    int n = (int)a.size() - 1;
    for (int i = n; i >= 1; i--) {
        int x = b % 10;
        b /= 10;
        a[i] += x;
        if (a[i] > '9') a[i] -= 10, ++a[i - 1];
    }
}

void MAIN() {
    memset(fm, 0, sizeof fm);
    ll rem = 0;
    cin >> a >> m;
    {
        string t = " ";
        for (int _ = 1; _ <= 20; _++) t += "0";
        a = t + a;
    }
    n = (int)a.size() - 1;
    plus(a, 1);
    int lenm = 0;
    {
        int x = m;
        while (x) x /= 10, ++lenm;
        for (int i = 1; i <= lenm; i++) {
            fm[i][i] = (m / po[lenm - i]) % 10;
        }
        for (int i = 1; i <= lenm; i++) {
            for (int j = i + 1; j <= lenm; j++) {
                fm[i][j] = fm[i][j - 1] * 10ll + fm[j][j];
            }
        }
    }
    for (int i = 1; i <= n; i++) rem = (rem * 10ll + a[i] - '0') % m;
    if (rem != 0) rem = m - rem;
    // just a
    for (int i = 1; i <= n - lenm + 1; i++) {
        if (get(a, i, i + lenm - 1) == m) rem = 0;
    }
    // a[n - lenm] plus 1
    ll tot = po[lenm] - get(a, n - lenm + 1, n);
    string t = a;
    {
        int x = n - lenm;
        for (int i = x + 1; i <= n; i++) t[i] = '0';
        ++t[x];
        while (x > 0 && t[x] > '9') {
            t[x] -= 10;
            --x;
            t[x]++;
        }
    }
    for (int i = 1; i <= n - lenm + 1; i++) {
        if (get(t, i, i + lenm - 1) == m) rem = min(rem, tot);
    }
    for (int r = 1; r < lenm; r++) {
        int l = lenm - r;
        if (get(t, n - lenm - l + 1, n - lenm) != fm[1][l]) continue;
        ll re = fm[lenm - r + 1][lenm] * po[lenm - r];
        rem = min(rem, re + tot);
    }
    // keep a[n - lenm]
    ll tmp = get(a, n - lenm + 1, n);
    if (tmp <= m) rem = min(rem, m - tmp);
    plus(a, rem);
    reverse(a.begin(), a.end());
    while (!a.empty() && !(a.back() > '0' && a.back() <= '9')) a.pop_back();
    reverse(a.begin(), a.end());
    cout << a << '\n';
}

int main() {
#ifdef LOCAL
    auto start = chrono::steady_clock::now();
    freopen("miku.in", "r", stdin);
    freopen("miku.out", "w", stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    po[0] = 1;
    for (int i = 1; i <= 14; i++) po[i] = po[i - 1] * 10ll;
    int T = 1;
    cin >> T;
    if (T > 10) {
        ll x, y; 
        for (int i = 1; i <= 109; i++) {
            cin >> x >> y;
        }
        cout << x << ' ' << y << '\n';
        exit(0);
    }
    while (T--) MAIN();
#ifdef LOCAL
    auto end = chrono::steady_clock::now();
    cout << "\nqwq: " <<  chrono::duration_cast<chrono::milliseconds>(end - start).count() << "ms\n";
#endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 3776kb

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:

2155106309 32

result:

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