QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56959#3889. Balanced BreakdownMahmoudAtiaWA 2ms3636kbC++2.4kb2022-10-22 06:40:122022-10-22 06:40:15

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:40:15]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3636kb
  • [2022-10-22 06:40:12]
  • 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);
        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: 0ms
memory: 3636kb

input:

1100000

output:

3
1099901
99
0

result:

ok 

Test #2:

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

input:

1000

output:

4
990
9
1
0

result:

FAIL 990 is not a palindrome!