Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define ld long double
- #define ull unsigned long long
- #define pii pair <int, int>
- #define vi vector <int>
- #define mi vector <vector <int>>
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) (int)(a.size())
- #define pb push_back
- #define mp make_pair
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- #define EACH(e, a) for (auto& e : a)
- // Pragmas
- #ifndef TIOM4EG
- #pragma GCC optimize("O3") // let the chaos begin!
- #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- #endif
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- using namespace __gnu_pbds;
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
- //#define int long long
- const int INF = 1e9 + 7, MD = 998244353, MAX = 200, R = 1 << 19, MOD1 = 1e9 + 7, MOD2 = 1e9 + 9, MOD12 = MOD1 * MOD1, MOD22 = MOD2 * MOD2, LG = 20, B1 = 103, B2 = 107, S = 10008;
- const ll INFLL = 1e15 + 7;
- int w[200][200];
- vector <array <int, 3>> ans[200][200];
- signed main() {
- fastIO;
- unordered_map <char, int> sym;
- int n, k, b, mx = 0; cin >> k >> b;
- FOR(i, 0, min(10, b)) sym['0' + i] = i;
- FOR(i, 0, b - 10) sym['A' + i] = 10 + i;
- vi m(k); EACH(e, m) cin >> e, mx = max(mx, e);
- string s;
- getline(cin, s), getline(cin, s), n = sz(s);
- FOR(i, 0, n) FOR(j, i, n) w[i][j] = j - i + 1;
- FOR(i, 0, n) {
- if (s[i] == '0') continue;
- ll x = 0;
- FOR(j, i, n) {
- if (sym.find(s[j]) == sym.end()) break;
- x = b * x + sym[s[j]];
- if (x > mx) break;
- FOR(l, 0, k) if (x <= m[l] && 2 + l < w[i][j]) {
- w[i][j] = 2 + l, ans[i][j] = {{i, j, l}};
- break;
- }
- }
- }
- FOR(l, 1, n) FOR(i, 0, n - l) {
- FOR(j, i, i + l) if (w[i][i + l] > w[i][j] + w[j + 1][i + l]) {
- w[i][i + l] = w[i][j] + w[j + 1][i + l];
- ans[i][i + l].clear();
- merge(all(ans[i][j]), all(ans[j + 1][i + l]), back_inserter(ans[i][i + l]));
- }
- }
- vi args;
- int p = 0;
- FOR(i, 0, n) {
- if (p < sz(ans[0][n - 1]) && i == ans[0][n - 1][p][0]) {
- cout << '%';
- FOR(j, 0, ans[0][n - 1][p][2]) cout << 'l';
- cout << 'i';
- int x = 0;
- FOR(j, ans[0][n - 1][p][0], ans[0][n - 1][p][1] + 1) x = b * x + sym[s[j]];
- args.pb(x);
- i = ans[0][n - 1][p][1], ++p;
- }
- else cout << s[i];
- }
- cout << endl;
- EACH(x, args) cout << x << ' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement