Salvens

Untitled

Nov 27th, 2023
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define ld long double
  7.  
  8. #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  9.  
  10. //#include <ext/pb_ds/assoc_container.hpp>
  11. //using namespace __gnu_pbds;
  12. //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  13.  
  14. const int INF = 1e18 + 7;
  15. const ld EPS = 1e-10;
  16. const int MOD = 1e9 + 7;
  17. const int MAXN = 1e4 + 100;
  18.  
  19. vector<string> nums = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"};
  20.  
  21. int get(string& s, int pos) {
  22.     int cnt = 0;
  23.     for (int i = 0; i < 7; ++i) {
  24.         if (s[i] == '1' && nums[pos][i] == '0') {
  25.             return -1;
  26.         }
  27.         if (s[i] != nums[pos][i]) {
  28.             ++cnt;
  29.         }
  30.     }
  31.     return cnt;
  32. }
  33.  
  34. inline void solve() {
  35.     int n, k;
  36.     cin >> n >> k;
  37.     vector<vector<pair<int, int>>> a(n);
  38.     for (int i = 0; i < n; ++i) {
  39.         string s;
  40.         cin >> s;
  41.         for (int j = 0; j < 10; ++j) {
  42.             int cur = get(s, j);
  43.             if (cur != -1) {
  44.                 a[i].emplace_back(cur, j);
  45.             }
  46.         }
  47.     }
  48.  
  49.     vector<string> dp(k + 1, "@");
  50.     dp[0] = string(n, '#');
  51.     for (int i = 0; i < n; ++i) {
  52.         for (auto [cost, num] : a[i]) {
  53.             for (int j = k; j >= cost; --j) {
  54.                 if (dp[j - cost] != "@") {
  55.                     string cur = dp[j - cost];
  56.                     cur[i] = char(num + '0');
  57.                     if (dp[j] == "@" || dp[j] < cur) {
  58.                         dp[j] = cur;
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.     }
  64.  
  65.     if (dp[k].find('#') == string::npos) {
  66.         cout << dp[k] << '\n';
  67.     } else {
  68.         cout << -1 << '\n';
  69.     }
  70. }
  71.  
  72. int32_t main() {
  73.     IOS;
  74.     clock_t tStart = clock();
  75.  
  76.     int tt = 1;
  77. //    cin >> tt;
  78.     while (tt --> 0) {
  79.         solve();
  80.     }
  81. //    cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment