Advertisement
clown1337

Untitled

Jan 23rd, 2024
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <algorithm>
  2. #include <bitset>
  3. #include <cassert>
  4. #include <cmath>
  5. #include <cstdint>
  6. #include <cstring>
  7. #include <deque>
  8. #include <fstream>
  9. #include <iomanip>
  10. #include <iostream>
  11. #include <limits>
  12. #include <map>
  13. #include <numeric>
  14. #include <ostream>
  15. #include <queue>
  16. #include <random>
  17. #include <set>
  18. #include <sstream>
  19. #include <stack>
  20. #include <string>
  21. #include <unordered_map>
  22. #include <unordered_set>
  23. #include <vector>
  24.  
  25. using namespace std;
  26. /// Pragmas ///
  27. /// define ///
  28. #define pii pair<int, int>
  29. #define pll pair<ll, ll>
  30. #define V vector
  31. #define MP make_pair
  32. #define vi vector<int>
  33. #define ff first
  34. #define ss second
  35. #define vl vector<long long>
  36. /// typedef ///
  37. typedef long long ll;
  38. typedef long double ld;
  39. typedef unsigned long long ull;
  40.  
  41. /// solve ///
  42. // consts
  43. const double PI = acos(-1);
  44. const ll MOD = 1000000007;
  45. const ll MOD2 = 1000000009;
  46. // const int p = 239;
  47. const ll p = 1'000'000;
  48. string inf;
  49. const int N = 150000 + 5000;
  50. const double eps = 1e-18;
  51. int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  52. int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
  53. #define int long long
  54. ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
  55.  
  56. ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
  57.  
  58. vl x = {6, 2, 3, 2, 4, 5, 4, 7};
  59. vl y = {0, 1, 1, 2, 0, 0, 1, 0};
  60. vl xy = {0, 1, 2, 3, 4, 5, 6, 8};
  61.  
  62. void solve() {
  63.   ull a, b;
  64.   cin >> a >> b;
  65.   inf = "";
  66.   for (size_t i = 0; i < 352; i++) {
  67.     inf += '9';
  68.   }
  69.   V<V<string>> dp(a + 30, V<string>(b + 30, inf));
  70.   // baza база base
  71.   for (size_t i = 1; i < x.size(); i++) {
  72.     dp[x[i]][y[i]] = '0' + xy[i];
  73.   }
  74.   for (ll aa = 0; aa <= a; aa++) {
  75.     for (ll bb = 0; bb <= b; bb++) {
  76.       for (ll i = 0; i < x.size(); i++) {
  77.         if (aa - x[i] < 0 || bb - y[i] < 0)
  78.           continue;
  79.         string temp = (dp[aa - x[i]][bb - y[i]]);
  80.         temp += ('0' + xy[i]);
  81.         if (temp.size() < dp[aa][bb].size()) {
  82.           dp[aa][bb] = temp;
  83.         } else if (temp.size() > dp[aa][bb].size()) {
  84.           continue;
  85.         } else {
  86.           dp[aa][bb] = min(dp[aa][bb], temp);
  87.         }
  88.       }
  89.     }
  90.   }
  91.   if (dp[a][b] == inf) {
  92.     cout << "Wrong" << '\n';
  93.   } else {
  94.     cout << dp[a][b] << '\n';
  95.   }
  96. }
  97. //
  98. signed main() {
  99.   ios_base::sync_with_stdio(false);
  100.   cin.tie(NULL);
  101.   cout.tie(NULL);
  102.   freopen("input.txt", "r", stdin);
  103.   freopen("output.txt", "w", stdout);
  104.   int t = 1;
  105.   // cin >> t;
  106.   while (t--)
  107.     solve();
  108.   return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement