QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#540012#8932. Bingoucup-team055#WA 47ms3588kbC++201.8kb2024-08-31 16:14:532024-08-31 16:14:54

Judging History

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

  • [2024-08-31 16:14:54]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:3588kb
  • [2024-08-31 16:14:53]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define all(p) p.begin(),p.end()
using ll = long long;
template<class T> bool chmin(T &a, T b){return (a > b ? a = b, 1 : 0);}
template<class T> bool chmax(T &a, T b){return (a < b ? a = b, 1 : 0);}

void solve(){
    const ll lim = (1ll << 30);
    string S;
    ll M;
    cin >> S >> M;
    int N = S.size();
    int len = max(N + 1, 11);
    vector<ll> p(len);
    ll X = 1;
    rep(i, 0, N){
        X *= 10;
        X += S[i] -'0';
        X %= M;
    }
    reverse(all(S));
    rep(i, 0, N){
        p[i] = S[i] - '0';
    }
    p[0]++;
    rep(i, 0, N){
        if (p[i] == 10){
            p[i] = 0;
            p[i + 1]++;
        }
        else break;
    }
    ll ans = (M - X) % M;
    ll rem = 0;
    ll T = 1;
    ll ten = 1, D = 0;
    while (ten <= M) ten *= 10, D++;
    rep(i, 0, len - D + 1){
        ll S = 0;
        for (int j = i + D - 1; j >= i; j--){
            S *= 10;
            S += p[j];
        }
        if (M == S){
            ans = 0;
            break;
        }
        //cout << i << " " << M << " " << S << " " << rem << endl;
        S = (M - S - 1 + ten) % ten;
        chmin(S, lim);
        chmin(ans, rem + S * T + 1);
        rem = max(rem, (9 - p[i]) * T);
        chmin(rem, lim);
        T = min(T * 10, lim);
    }

    p[0] += ans;
    rep(i, 0, len - 1){
        p[i + 1] += p[i] / 10;
        p[i] %= 10;
    }
    while (p.back() == 0) p.pop_back();
    reverse(all(p));
    for (auto x : p) cout << x;
    cout << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) solve();
}
/*
test
6
7 3
12 3
9 10
249 51
1369 37
2 1
 */

詳細信息

Test #1:

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

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: 47ms
memory: 3548kb

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
1075124419
7822266301
1767317769
7189709875
9061337562
6552679237
9946082151
5497675063
7787300365
4310767268
4811342001
3265496131
8294404062
2845521790
1114254685
6442013673
3744046867
3289624375
6477935371
1292587536
5504674689
2898829180
7882736025
2846033373
923...

result:

wrong answer 4th lines differ - expected: '1075124424', found: '1075124419'