Submission #786952

#TimeUsernameProblemLanguageResultExecution timeMemory
786952ChiroTruongBank (IZhO14_bank)C++14
100 / 100
90 ms8532 KiB
#include <set>
#include <vector>
#include <utility>
#include <cstring>
#include <iostream>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

using namespace std;
template<typename... Args>
void print(Args&&... args){
(cout << ... << args);}
template<typename... Args>
void scan(Args&... args){
((cin >> args), ...);}
typedef long long ll;

#define X first
#define Y second
#define lenarr 1'000'000
#define inf 1'000'000'007
#define REP(x, a, b) for ( int x = a; x < b; ++x )
#define RED(x, a, b) for ( int x = a; x > b; --x )
#define FOR(x, a, b) for ( int x = a; x <= b; ++x )
#define FOD(x, a, b) for ( int x = a; x >= b; --x )
#define swap(x, y) { string _temp = x; x = y; y = _temp; }

int const MAXN = (1 << 20) + 1;
int n, m, i, j, k, Target[21], Value[21];
pair<int, int> DP[MAXN];

int main(void){
    //freopen("INP.INP", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    scan(n, m);
    REP(i, 1, 1 << m)
        DP[i] = {-1, 0};
    DP[0] = {1, 0};
    FOR(i, 1, n)
        scan(Target[i]);
    FOR(i, 1, m)
        scan(Value[i]);
    REP(i, 1, 1 << m)
        DP[i] = {0, 0};
    DP[i] = {1, 0};
    REP(i, 1, 1 << m){
        FOR(j, 1, m)
            if (i&(1<<(m-j))){ // Check bit i th 
                int before = i&~(1<<(m-j));
                if ( DP[before].X ){
                    pair<int, int> temp = DP[before];
                    temp.Y += Value[j];
                    if ( temp.Y == Target[temp.X] )
                        DP[i].X = temp.X + 1, DP[i].Y = 0;
                    else
                        if ( temp.Y < Target[temp.X] )
                            DP[i] = temp;        
                }
            }
        if ( DP[i].X == n + 1 ){
            print("YES"); return 0;
        }
    } print("NO");
    return 0;
}

Compilation message (stderr)

bank.cpp: In function 'void print(Args&& ...)':
bank.cpp:15:17: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17'
   15 | (cout << ... << args);}
      |                 ^~~~
bank.cpp: In function 'void scan(Args& ...)':
bank.cpp:18:17: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17'
   18 | ((cin >> args), ...);}
      |                 ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...