QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556183#8932. Bingoucup-team3519#WA 62ms3624kbC++202.0kb2024-09-10 15:38:552024-09-10 15:38:55

Judging History

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

  • [2024-09-10 15:38:55]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:3624kb
  • [2024-09-10 15:38:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define V vector
#define pb push_back
#define all1(x) (x).begin() + 1, (x).end()
#define all0(x) (x).begin(), (x).end()
typedef long long LL;
const LL INF = 1e10;

void solve() {
    string n; cin >> n;
    int m; cin >> m;
    string sm = to_string(m);
    string sm1 = to_string(m - 1);
    reverse(all0(sm));
    reverse(all0(sm1));
    LL res = 0;
    reverse(all0(n));
    LL ten = 1;
    for(int i = 0; i < n.size(); i++) {
        res += ten * (n[i] - '0');
        res %= m;
        ten = ten * 10 % m;
    }
    LL ans = m - res;

    // cout << "a1 : " << ans << endl;

    bool add = 0;
    LL carry = 0;
    ten = 1;

    for(int i = 0; i < n.size(); i++) {
        if(i + sm1.size() <= n.size()) {
            if(n.substr(i, sm1.size()) == sm1) {
                ans = min(ans, carry + 1);
            }
        }
        if(i + sm.size() <= n.size()) {
            if(add) ans = 1;
        }
        if(n[i] != '9') add = 1;
        carry += ('9' - n[i]) * ten;
        carry = min(INF, carry);
        ten *= 10;
        ten = min(ten, INF);
    }
    ten = 1;

    for(int i = 0; i <= 8; i++) {
        LL aim = ten * m;
        LL now = 0;
        LL cur = 1;
        for(int j = 0; j < min(i + sm.size(), n.size()); j++) {
            now += cur * (n[j] - '0');
            cur *= 10;
        }
        if(now < aim) ans = min(ans, aim - now);

    }
    // cout << ans << endl;

    V<int> bit(n.size());
    for(int i = 0; i < n.size(); i++) {
        bit[i] = n[i] - '0';
    }
    bit[0] += ans;
    int now = 0;
    while(bit[now] >= 10) {
        if(now == bit.size() - 1) {
            bit.pb(0);
        }
        bit[now + 1] += bit[now] / 10;
        bit[now] %= 10;
        now++;
    }
    for(int i = bit.size() - 1; i >= 0; i--) cout << bit[i];
    cout << endl;
}

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

詳細信息

Test #1:

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

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: 62ms
memory: 3572kb

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
7614814238
2814581085
1075124402
7822266215
1767317769
7189709842
9061337539
6552679232
9946082149
5497675063
7787300352
4310767262
4811341954
3265496131
8294404055
2845521745
1114254673
6442013673
3744046867
3289624368
6477935356
1292587533
5504674679
2898829148
7882736013
2846033369
923...

result:

wrong answer 2nd lines differ - expected: '7614814251', found: '7614814238'