Submission #1151070

#TimeUsernameProblemLanguageResultExecution timeMemory
1151070hungandhimselfBank (IZhO14_bank)C++17
0 / 100
4 ms8844 KiB
    #include <bits/stdc++.h>
using namespace std;
 #define int long long
#define ll long long
#define lint long long int
#define debugi(i, f) cerr << "i = " << i << " : f[i] = " << f[i] << "\n";
#define debugii(i, j, f) cerr << "i = " << i << " and j = " << j << " : f[i][j] = " << f[i][j] << "\n";
#define debugiii(i, j, k, f) cerr << "i = " << i << " and j = " << j << " and k = " << k << " : f[i][j][k] = " << f[i][j][k] << "\n";
#define vc vector
#define pr pair
#define ii pair<int, int>
#define iii pair<int, ii>
#define fi first
#define se second
#define Pi 3.1415926535897932384
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll mod = 1e9 + 7;
const int MOD = 2e9 + 33;
const int N = 5e5 + 2;
const int modd = 998244353;
const int inf = (int)1e18;
string decToBinary(int n, int sz) {
    string bin = "";
    if (!n) bin.push_back('0');
    while (n > 0) {
        int bit = n%2;
          bin.push_back('0' + bit);
        n /= 2;
    }

    for (int i = bin.size() - 1; i < sz; i++) {
        bin.push_back('0');
    }

    reverse(bin.begin(), bin.end());
    return bin;
}

string decToBinary2(int n) {
    string bin = "";

    while (n > 0) {
        int bit = n%2;
          bin.push_back('0' + bit);
        n /= 2;
    }

    reverse(bin.begin(), bin.end());
    return bin;
}

int n, m;
int a[22], b[22], dp[22][(1 << 20) + 2];
bool mark[1002];
vc<int> subset[1002];
void runcase (int test) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        mark[a[i]] = true;
    }

    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }

    for (int s = 0; s < (1 << m); s++) {
        int sum = 0;
        for (int mask = 0; mask < m; mask++) {
            if (s & (1 << mask)) {
                sum += b[mask + 1];
            }
        }

        if (mark[sum])
            subset[sum].push_back(s);
    }

    for (int i = 1; i <= n; i++) {
//                cout << "hi\n";
//        cout << "a[i] == " << a[i] << '\n';
        for (int x : subset[a[i]]) {
            cout << decToBinary(x, m - 1) << '\n';
        }
    }

    memset(dp[1], true, sizeof dp[1]);
    dp[1][0] = false;
    for (int i = 1; i <= n; i++) {
//        cout << "i = " << i << " : \n";
        for (int s = 0; s < (1 << m); s++) {
            if (dp[i][s] == false) continue;
//            cout << "s = " << decToBinary(s, m - 1) << " : \n";
            for (int x : subset[a[i]]) {
                if (s > x && ((s & x) == x)) {
//                    cout << "  x = " << decToBinary(x, m - 1) << '\n';
                    dp[i + 1][s ^ x] = true;
                }
            }

//            cout << '\n';
        }
    }

    for (int s = 0; s < (1 << m); s++) {
        if (dp[n + 1][s] == true)
            return void(cout << "YES\n");
    }

    cout << "NO\n";
}

/**
    B1 : kiểm tra lại code templete, code đã học thuộc
    đọc kĩ đề
    nháp chưa
    kiểm tra lại code, đặc biệt là những chỗ đã học thuộc (nhiều khi sai ở đó)
**/
signed main () {
    ios_base::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    #ifndef ONLINE_JUDGE
//        freopen ("movie.in", "r", stdin);
//        freopen ("movie.out", "w", stdout);
    #else // online submission
    #endif
/// i have a contest soon and i need to learn a much as possible
/// so let become familiar with a bunch of different problems and solution ideas
    // stop learning useless algorithm (with you) and solve more problems
    //Cứ 7 lần nộp thì chỉ được 1 lần sai

    int test = 1;
//    cin >> test;
    while (test--) runcase(test);
    // return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...