QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#539923#8932. Bingoucup-team037#WA 112ms3588kbC++203.4kb2024-08-31 16:02:292024-08-31 16:02:30

Judging History

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

  • [2024-08-31 16:02:30]
  • 评测
  • 测评结果:WA
  • 用时:112ms
  • 内存:3588kb
  • [2024-08-31 16:02:29]
  • 提交

answer


// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h> 
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return b < a ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;

#ifndef DEBUG
#define cerr if (0) cerr
#endif

const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;

int t;
string sn, sm;
int m;

int main() {
#ifndef DEBUG
    ios::sync_with_stdio(0), cin.tie(0);
#endif
    cin >> t;
    while (t--) {
        cin >> sn >> m;
        sn = "0" + sn;
        while (SZ(sn) <= 30) {
            sn = "0" + sn;
        }
        RREP (j, SZ(sn) - 1, 0) {
            if (sn[j] < '9') {
                sn[j]++;
                break;
            } else {
                sn[j] = '0';
            }
        }
        sm = to_string(m);
        bool perfect = 0;
        ll remain = 0;
        REP (i, 0, SZ(sn) - SZ(sm) + 1) {
            remain = (remain * 10 + (sn[i] - '0')) % m;
            bool same = 1;
            REP (j, 0, SZ(sm)) {
                if (sn[i + j] != sm[j]) {
                    same = 0;
                    break;
                }
            }
            if (same) {
                perfect = 1;
                break;
            }
        }
        string ans;
        if (perfect || remain == 0) {
            ans = sn;
        } else {
            ans = sn;
            ans[0] = '9';
            RREP (i, SZ(sn) - SZ(sm), SZ(sn) - 2 * SZ(sm) - 5) {
                string t = sn;
                REP (j, 0, SZ(sm)) {
                    t[i + j] = sm[j];
                }
                if (t < sn) {
                    RREP (j, i - 1, 0) {
                        if (t[j] < '9') {
                            t[j]++;
                            break;
                        } else {
                            t[j] = '0';
                        }
                    }
                }
                REP (j, i + SZ(sm), SZ(sn)) {
                    t[j] = '0';
                }
                mnto(ans, t);
            }
            string t = sn;
            remain = m - remain;
            REP (_, 0, SZ(sm)) {
                int d = remain % 10;
                RREP (i, SZ(sn) - 1, 0) {
                    int nd = t[i] - '0' + d;
                    t[i] = nd % 10 + '0';
                    d = nd / 10;
                    if (d == 0) {
                        break;
                    }
                }
                remain /= 10;
                if (remain == 0) {
                    break;
                }
            }
            mnto(ans, t);
        }
        bool zero = 1;
        REP (i, 0, SZ(ans)) {
            if (zero && ans[i] == '0') {
                continue;
            }
            zero = 0;
            cout << ans[i];
        }
        cout << '\n';
    }
    return 0;
}

详细

Test #1:

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

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: 112ms
memory: 3588kb

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
7614814241
2814581087
1075124407
7822266226
1767317769
7189709849
9061337547
6552679234
9946082151
5497675063
7787300358
4310767268
4811341963
3265496131
8294404062
2845521752
1114254676
6442013673
3744046867
3289624373
6477935357
1292587539
5504674686
2898829158
7882736019
2846033376
923...

result:

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