QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56946 | #3889. Balanced Breakdown | MahmoudAtia# | WA | 2ms | 3556kb | C++ | 2.3kb | 2022-10-22 00:00:40 | 2022-10-22 00:00:41 |
Judging History
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 {
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() << '\n';
for (auto x:v) cout << x << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3540kb
input:
1100000
output:
2 1099901 99
result:
ok
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3556kb
input:
1000
output:
3 891 101 8
result:
FAIL 891 is not a palindrome!