Advertisement
tiom4eg

day 2, C 100

Jan 10th, 2023
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. // tiom4eg's precompiler options
  3. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  4. // IO settings
  5. #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
  6. // Quick types
  7. #define ll long long
  8. #define ld long double
  9. #define ull unsigned long long
  10. #define pii pair <int, int>
  11. #define vi vector <int>
  12. #define mi vector <vector <int>>
  13. // Quick functions
  14. #define endl "\n"
  15. #define F first
  16. #define S second
  17. #define all(a) a.begin(), a.end()
  18. #define sz(a) (int)(a.size())
  19. #define pb push_back
  20. #define mp make_pair
  21. // Quick fors
  22. #define FOR(i, a, b) for (int i = a; i < b; ++i)
  23. #define FORS(i, a, b, c) for (int i = a; i < b; i += c)
  24. #define RFOR(i, a, b) for (int i = a; i >= b; --i)
  25. #define EACH(e, a) for (auto& e : a)
  26. // Pragmas
  27. #ifndef TIOM4EG
  28. #pragma GCC optimize("O3") // let the chaos begin!
  29. #pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
  30. #pragma GCC comment(linker, "/stack:200000000")
  31. #endif
  32. // PBDS
  33. #include <ext/pb_ds/assoc_container.hpp>
  34. #include <ext/pb_ds/tree_policy.hpp>
  35. #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
  36. #define ook order_of_key
  37. #define fbo find_by_order
  38. using namespace __gnu_pbds;
  39. // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
  40. using namespace std;
  41. mt19937 rng(chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count());
  42. //#define int long long
  43. 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;
  44. const ll INFLL = 1e15 + 7;
  45.  
  46. int w[200][200];
  47. vector <array <int, 3>> ans[200][200];
  48.  
  49. signed main() {
  50.     fastIO;
  51.     unordered_map <char, int> sym;
  52.     int n, k, b, mx = 0; cin >> k >> b;
  53.     FOR(i, 0, min(10, b)) sym['0' + i] = i;
  54.     FOR(i, 0, b - 10) sym['A' + i] = 10 + i;
  55.     vi m(k); EACH(e, m) cin >> e, mx = max(mx, e);
  56.     string s;
  57.     getline(cin, s), getline(cin, s), n = sz(s);
  58.     FOR(i, 0, n) FOR(j, i, n) w[i][j] = j - i + 1;
  59.     FOR(i, 0, n) {
  60.         if (s[i] == '0') continue;
  61.         ll x = 0;
  62.         FOR(j, i, n) {
  63.             if (sym.find(s[j]) == sym.end()) break;
  64.             x = b * x + sym[s[j]];
  65.             if (x > mx) break;
  66.             FOR(l, 0, k) if (x <= m[l] && 2 + l < w[i][j]) {
  67.                 w[i][j] = 2 + l, ans[i][j] = {{i, j, l}};
  68.                 break;
  69.             }
  70.         }
  71.     }
  72.     FOR(l, 1, n) FOR(i, 0, n - l) {
  73.         FOR(j, i, i + l) if (w[i][i + l] > w[i][j] + w[j + 1][i + l]) {
  74.             w[i][i + l] = w[i][j] + w[j + 1][i + l];
  75.             ans[i][i + l].clear();
  76.             merge(all(ans[i][j]), all(ans[j + 1][i + l]), back_inserter(ans[i][i + l]));
  77.         }
  78.     }
  79.     vi args;
  80.     int p = 0;
  81.     FOR(i, 0, n) {
  82.         if (p < sz(ans[0][n - 1]) && i == ans[0][n - 1][p][0]) {
  83.             cout << '%';
  84.             FOR(j, 0, ans[0][n - 1][p][2]) cout << 'l';
  85.             cout << 'i';
  86.             int x = 0;
  87.             FOR(j, ans[0][n - 1][p][0], ans[0][n - 1][p][1] + 1) x = b * x + sym[s[j]];
  88.             args.pb(x);
  89.             i = ans[0][n - 1][p][1], ++p;
  90.         }
  91.         else cout << s[i];
  92.     }
  93.     cout << endl;
  94.     EACH(x, args) cout << x << ' ';
  95. }
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement