QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56947#3889. Balanced BreakdownMahmoudAtia#WA 2ms3680kbC++2.4kb2022-10-22 00:06:542022-10-22 00:06:57

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:06:57]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 3680kb
  • [2022-10-22 00:06:54]
  • 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) {
                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;
}

詳細信息

Test #1:

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

input:

1100000

output:

2
1099901
99

result:

ok 

Test #2:

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

input:

1000

output:

2
999
1

result:

ok 

Test #3:

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

input:

10

output:

2
0
10

result:

FAIL 10 is not a palindrome!