Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define ld long double
- #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
- //#include <ext/pb_ds/assoc_container.hpp>
- //using namespace __gnu_pbds;
- //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
- const int INF = 1e18 + 7;
- const ld EPS = 1e-10;
- const int MOD = 1e9 + 7;
- const int MAXN = 1e4 + 100;
- vector<string> nums = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"};
- int get(string& s, int pos) {
- int cnt = 0;
- for (int i = 0; i < 7; ++i) {
- if (s[i] == '1' && nums[pos][i] == '0') {
- return -1;
- }
- if (s[i] != nums[pos][i]) {
- ++cnt;
- }
- }
- return cnt;
- }
- inline void solve() {
- int n, k;
- cin >> n >> k;
- vector<vector<pair<int, int>>> a(n);
- for (int i = 0; i < n; ++i) {
- string s;
- cin >> s;
- for (int j = 0; j < 10; ++j) {
- int cur = get(s, j);
- if (cur != -1) {
- a[i].emplace_back(cur, j);
- }
- }
- }
- vector<string> dp(k + 1, "@");
- dp[0] = string(n, '#');
- for (int i = 0; i < n; ++i) {
- for (auto [cost, num] : a[i]) {
- for (int j = k; j >= cost; --j) {
- if (dp[j - cost] != "@") {
- string cur = dp[j - cost];
- cur[i] = char(num + '0');
- if (dp[j] == "@" || dp[j] < cur) {
- dp[j] = cur;
- }
- }
- }
- }
- }
- if (dp[k].find('#') == string::npos) {
- cout << dp[k] << '\n';
- } else {
- cout << -1 << '\n';
- }
- }
- int32_t main() {
- IOS;
- clock_t tStart = clock();
- int tt = 1;
- // cin >> tt;
- while (tt --> 0) {
- solve();
- }
- // cerr << "Runtime is:" << (long double) (clock() - tStart) / CLOCKS_PER_SEC << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment