Untitled
unknown
c_cpp
10 months ago
1.6 kB
3
Indexable
#include <iostream>
#include <vector>
#define int long long
using namespace std;
int atoi2(string s) {
int ans = 0, m = 1;
for (int i = s.length() - 1; i >= 0; --i)
ans += ((s[i] - '0') * m), m *= 10;
return ans;
}
int32_t main() {
string s; cin >> s;
int n = s.length(), id = 0;
int res = 0;
for (auto x : s) res += x - '0';
cout << res << endl;
vector<pair<int, int>> f; //, idx
for (int i = 0; i < n; ++i)
if (i % 2)
while (s[i] - '0') s[i]--, f.push_back({ -1, -1 });
else
f.push_back({ id, s[i] - '0' }), id++;
n = f.size();
for (int j = n - 1; j >= 0; --j) {
if (f[j].first <= -1) continue;
bool ok = 0;
for (int i = 0; i < j; ++i) {
if (f[i].first == -1) {
int len = 0, oi = i;
while ((f[i].first == -1) && (i < j)) {
len++;
if (len >= f[j].second) {
for (; oi < i; ++oi) f[oi] = { -2,-2 };
f[i] = f[j];
f[j] = { -1,-1 };
ok = 1;
break;
}
i++;
}
i--;
}
if (ok) break;
}
}
for (auto x : f) {
cout << x.first << " " << x.second << endl;
}
int ans = 0, i = 0;
for (auto x : f)
if (x.first > -1) {
while (x.second--)
ans += (x.first * i), i++;
}
cout << ans;
}
Editor is loading...
Leave a Comment