QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56960#3889. Balanced BreakdownMahmoudAtiaAC ✓3ms3728kbC++2.5kb2022-10-22 06:42:592022-10-22 06:43:02

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 06:43:02]
  • Judged
  • Verdict: AC
  • Time: 3ms
  • Memory: 3728kb
  • [2022-10-22 06:42:59]
  • 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];

//#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 (n < 10) {
            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;
        }
        string s = to_string(n);
        if (n == ten[s.length() - 1]) {
            v.push_back(n - 1);
            v.push_back(1);
            break;
        }
        ll cur = 0;
        for (int i = 0; i < s.length() / 2; i++) {
            if (cur + ten[i] * (s[i] - '0') + ten[s.length() - 1 - i] * (s[i] - '0') <= n) {
                cur += ten[i] * (s[i] - '0') + ten[s.length() - 1 - i] * (s[i] - '0');
            } else {
                if (s[i] - '0' > 0)
                    cur += (ten[i] + ten[s.length() - i - 1]) * (s[i] - '0' - 1);
                i++;
                for (; i < s.length() / 2; i++)
                    cur += (ten[i] + ten[s.length() - i - 1]) * 9;
            }
        }
        if (s.length() & 1) {
            for (int i = 9; i >= 1; i--) {
                if (cur + ten[s.length() / 2] * i <= n) {
                    cur += ten[s.length() / 2] * i;
                    break;
                }
            }
        }
        v.push_back(cur);
        n -= cur;
    }
    cout << v.size() << endl;
    for (auto x:v) cout << x << endl;
    return 0;
}

详细

Test #1:

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

input:

1100000

output:

3
1099901
99
0

result:

ok 

Test #2:

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

input:

1000

output:

2
999
1

result:

ok 

Test #3:

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

input:

10

output:

3
9
1
0

result:

ok 

Test #4:

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

input:

11005

output:

3
10901
101
3

result:

ok 

Test #5:

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

input:

100000000000000000

output:

2
99999999999999999
1

result:

ok 

Test #6:

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

input:

21

output:

3
9
1
11

result:

ok 

Test #7:

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

input:

1234567887664321

output:

3
1234567887654321
9999
1

result:

ok 

Test #8:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

690231482249788720

output:

7
690231481184132096
1065555601
100001
1001
9
1
11

result:

ok 

Test #9:

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

input:

319173294485481281

output:

7
319173293392371913
1093003901
104401
1001
9
1
55

result:

ok 

Test #10:

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

input:

761353558778227546

output:

7
761353557755353167
1022772201
101101
1001
9
1
66

result:

ok 

Test #11:

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

input:

947179993313410328

output:

7
947179992299971749
1013333101
104401
1001
9
1
66

result:

ok 

Test #12:

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

input:

171408535476134406

output:

7
171408534435804171
1040220401
108801
1001
9
1
22

result:

ok 

Test #13:

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

input:

896452012199589977

output:

7
896452011110254698
1089229801
104401
1001
9
1
66

result:

ok 

Test #14:

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

input:

970894988875162603

output:

7
970894987789498079
1085555801
107701
1001
9
1
11

result:

ok 

Test #15:

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

input:

200429647731477537

output:

7
200429646646924002
1084444801
107701
1001
9
1
22

result:

ok 

Test #16:

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

input:

960284896260606337

output:

6
960284895598482069
662121266
2992
9
1
0

result:

ok 

Test #17:

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

input:

999999999999999999

output:

1
999999999999999999

result:

ok 

Test #18:

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

input:

1

output:

1
1

result:

ok 

Test #19:

score: 0
Accepted
time: 3ms
memory: 3628kb

input:

7

output:

1
7

result:

ok 

Test #20:

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

input:

487291873378192784

output:

1
487291873378192784

result:

ok 

Test #21:

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

input:

414821987097225805

output:

5
414821986689128414
408090804
6556
22
9

result:

ok 

Test #22:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

418581849637933703

output:

5
418581848848185814
789737987
9889
11
2

result:

ok 

Test #23:

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

input:

607979478938276336

output:

5
607979478874979706
63288236
8338
55
1

result:

ok 

Test #24:

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

input:

471913902748260172

output:

5
471913902209319174
538939835
1111
44
8

result:

ok 

Test #25:

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

input:

1000003

output:

2
1000001
2

result:

ok 

Test #26:

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

input:

123456788654328

output:

3
123456787654321
1000001
6

result:

ok