Submission #1370177

#TimeUsernameProblemLanguageResultExecution timeMemory
1370177c12Bank (IZhO14_bank)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>

#define ll long long

using namespace std;

vector<int>people,money;

vector<pair<int,int>>dp;
vector<int>vis;

int n,m;

void printByte(int bit){
    for(int i = m;i >= 0;i--){
        cout << (((bit & (1 << i)) > 0) ? 1 : 0);
    }
    cout << '\n';
}

void recursive(int bit){
    if(vis[bit]) return;
    vis[bit] = 1;
    dp[bit] = {-1,0};
    for(int i = 0;i < m;i++){
        if((1 << i) & bit){
            int nbit = bit xor (1 << i);

            auto npair = dp[nbit];
            if(npair.first == -1) continue;

            if(npair.first == n){
              dp[bit] = {n,0};
              return;
            }
            if(npair.first < n && npair.second - money[i] >= 0){
                npair.second -= money[i];
                if(npair.second == 0){
                    npair.first++;
                    if(npair.first < n){
                        npair.second = people[npair.first];
                    }
                }   
              dp[bit] = max(dp[bit],npair);
            }

        }
    }
} 

int main() {#include <bits/stdc++.h>

#define ll long long

using namespace std;

vector<int>people,money;

vector<pair<int,int>>dp;
vector<int>vis;

int n,m;

void printByte(int bit){
    for(int i = m;i >= 0;i--){
        cout << (((bit & (1 << i)) > 0) ? 1 : 0);
    }
    cout << '\n';
}

void recursive(int bit){
    if(vis[bit]) return;
    vis[bit] = 1;
    dp[bit] = {-1,0};
    for(int i = 0;i < m;i++){
        if((1 << i) & bit){
            int nbit = bit xor (1 << i);

            auto npair = dp[nbit];
            if(npair.first == -1) continue;

            if(npair.first == n){
              dp[bit] = {n,0};
              return;
            }
            if(npair.first < n && npair.second - money[i] >= 0){
                npair.second -= money[i];
                if(npair.second == 0){
                    npair.first++;
                    if(npair.first < n){
                        npair.second = people[npair.first];
                    }
                }   
              dp[bit] = max(dp[bit],npair);
            }

        }
    }
} 

int main() {
    ios::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;

    people = vector<int>(n);
    money = vector<int>(m);

    dp = vector<pair<int,int>>((1 << m) + 1);
    vis = vector<int>((1 << m) + 1);

    for(int i = 0;i < n;i++) cin >> people[i];
    for(int i = 0;i < m;i++) cin >> money[i];

    dp[0] = {0,people[0]};

    for(int i = 1;i < (1 << m);i++){
        recursive(i);
        if(dp[i].first == n){
            cout << "YES";
            return 0;        
        }
    }
    
    cout << "NO";
    
    return 0;
}

    ios::sync_with_stdio(0); cin.tie(0);

    cin >> n >> m;

    people = vector<int>(n);
    money = vector<int>(m);

    dp = vector<pair<int,int>>((1 << m) + 1);
    vis = vector<int>((1 << m) + 1);

    for(int i = 0;i < n;i++) cin >> people[i];
    for(int i = 0;i < m;i++) cin >> money[i];

    dp[0] = {0,people[0]};

    for(int i = 1;i < (1 << m);i++){
        recursive(i);
        if(dp[i].first == n){
            cout << "YES";
            return 0;        
        }
    }
    
    cout << "NO";
    
    return 0;
}

Compilation message (stderr)

bank.cpp:51:13: error: stray '#' in program
   51 | int main() {#include <bits/stdc++.h>
      |             ^
bank.cpp: In function 'int main()':
bank.cpp:51:23: error: 'bits' was not declared in this scope
   51 | int main() {#include <bits/stdc++.h>
      |                       ^~~~
bank.cpp:51:28: error: 'stdc' was not declared in this scope; did you mean 'std'?
   51 | int main() {#include <bits/stdc++.h>
      |                            ^~~~
      |                            std
bank.cpp:51:14: error: 'include' was not declared in this scope
   51 | int main() {#include <bits/stdc++.h>
      |              ^~~~~~~
bank.cpp:55:1: error: expected primary-expression before 'using'
   55 | using namespace std;
      | ^~~~~
bank.cpp:64:24: error: a function-definition is not allowed here before '{' token
   64 | void printByte(int bit){
      |                        ^
bank.cpp:71:24: error: a function-definition is not allowed here before '{' token
   71 | void recursive(int bit){
      |                        ^
bank.cpp:101:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  101 | int main() {
      |         ^~
bank.cpp:101:9: note: remove parentheses to default-initialize a variable
  101 | int main() {
      |         ^~
      |         --
bank.cpp:101:9: note: or replace parentheses with braces to value-initialize a variable
bank.cpp:101:12: error: a function-definition is not allowed here before '{' token
  101 | int main() {
      |            ^