QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#56949#3889. Balanced BreakdownMahmoudAtia#WA 3ms3640kbC++2.6kb2022-10-22 00:19:462022-10-22 00:19:50

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-22 00:19:50]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 3640kb
  • [2022-10-22 00:19:46]
  • Submitted

answer

#include <bits/stdc++.h>

typedef long double ld;
typedef long long ll;
using namespace std;
int di[] = {1, 0, -1, 0, -1, 1, -1, 1};
int dj[] = {0, 1, 0, -1, -1, 1, 1, -1};
const ll oo = 1e18, MOD = 998244353;
const int N = 500 + 5, M = 1e6 + 5;
const ld PI = acos(-1.0), EPS = 1e-9;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

ll n, m, a[N];

pair<pair<int, int>, int> lst(ll n) {
    int ret = 0, pre = 0, cnt = -1;
    while (n) {
        pre = ret;
        ret = n % 10;
        n /= 10;
        cnt++;
    }
    return {{ret, pre}, cnt};
}

bool pal(ll n) {
    vector<int> v;
    while (n) v.push_back(n % 10), n /= 10;
    for (int i = 0; i < v.size() / 2; i++) if (v[i] != v[v.size() - 1 - i]) return 0;
    return 1;
}

//#define endl '\n'
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //freopen("farm.in", "r", stdin);
    //memset(dp, -1, sizeof dp);
    ll ten[20];
    ten[0] = 1;
    for (int i = 1; i <= 18; i++) ten[i] = ten[i - 1] * 10;
    vector<ll> v;
    cin >> n;
    while (n) {
        if (pal(n)) {
            v.push_back(n);
            break;
        }
        if (n < 100) {
            int d1 = n / 10;
            int d2 = n % 10;
            if (d1 - d2 == 1) {
                v.push_back(9);
                v.push_back(1);
                v.push_back(n - 10);
            } else if (d1 > d2) {
                v.push_back((d1 - 1) * 11);
                n -= (d1 - 1) * 11;
                v.push_back(n);
            } else {
                v.push_back(d1 * 11);
                n -= d1 * 11;
                v.push_back(n);
            }
            break;
        }
        int d1, d2, cnt;
        d1 = lst(n).first.first;
        d2 = lst(n).first.second;
        cnt = lst(n).second;
        ll num = d1 * ten[cnt] + d2 * ten[cnt - 1] + d2 * 10 + d1;
        if (n >= num) {
            v.push_back(num);
            n -= num;
        } else if (n == ten[cnt]) {
            num = 0;
            for (int i = 1; i <= cnt; i++) num = num * 10 + 9;
            v.push_back(num);
            n -= num;
        } else {
            num = d1 * ten[cnt] + d2 * ten[cnt - 1] - 1;
            num -= 9 - d1;
            if (cnt > 2) num -= 90 - (d2 - 1) * 10;
            v.push_back(num);
            n -= num;
        }
    }
    cout << v.size() << endl;
    for (auto x:v) cout << x << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3552kb

input:

1100000

output:

2
1099901
99

result:

ok 

Test #2:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

1000

output:

2
999
1

result:

ok 

Test #3:

score: 0
Accepted
time: 2ms
memory: 3640kb

input:

10

output:

3
9
1
0

result:

ok 

Test #4:

score: 0
Accepted
time: 1ms
memory: 3568kb

input:

11005

output:

3
10901
101
3

result:

ok 

Test #5:

score: 0
Accepted
time: 2ms
memory: 3556kb

input:

100000000000000000

output:

2
99999999999999999
1

result:

ok 

Test #6:

score: 0
Accepted
time: 2ms
memory: 3616kb

input:

21

output:

3
9
1
11

result:

ok 

Test #7:

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

input:

1234567887664321

output:

9
1200000000000021
34000000000043
560000000065
7800000087
87000078
660066
3883
77
1

result:

ok 

Test #8:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

690231482249788720

output:

9
690000000000000096
230000000000032
1400000000041
82000000028
240000042
9700079
88088
303
11

result:

ok 

Test #9:

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

input:

319173294485481281

output:

9
310000000000000013
9100000000000019
73000000000037
290000000092
4400000044
85000058
480084
929
5

result:

ok 

Test #10:

score: -100
Wrong Answer
time: 2ms
memory: 3560kb

input:

761353558778227546

output:

11
760000000000000067
1300000000000031
53000000000035
550000000055
8700000078
78000087
220022
7117
9
1
44

result:

wrong answer Integer parameter [name=k] equals to 11, violates the range [1, 10]