Submission #920039

#TimeUsernameProblemLanguageResultExecution timeMemory
920039thunoproBank (IZhO14_bank)C++14
52 / 100
1053 ms7256 KiB
#include<bits/stdc++.h> using namespace std ; #define maxn 200009 #define ll long long #define fi first #define se second #define pb push_back #define left id<<1 #define right id<<1|1 #define re exit(0); const int mod = 1e9+7; const int INF = 1e9; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<ll> vl; void add ( int &a , int b ) { a += b ; if ( a > mod ) a -= mod ; if ( a < 0 ) a += mod ; } template <typename T> void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } template <typename T> void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } int _pow ( int a , int n ) { if ( n == 0 ) return 1 ; int res = _pow (a,n/2) ; if ( n % 2 ) return 1ll*res*res%mod*a%mod ; else return 1ll*res*res%mod ; } void rf () { freopen ("bai1.inp","r",stdin) ; } int n , m ; int a [maxn] , b [maxn] ; vi MASK [maxn] ; void prepare () { for ( int mask = 0 ; mask < (1<<m) ; mask ++ ) { int sum = 0 ; for ( int i = 0 ; i < m ; i ++ ) { if ( mask >> i & 1 ) sum += b [i] ; } for ( int i = 0 ; i < n ; i ++ ) if ( sum == a [i] ) MASK [i] . pb (mask) ; } } bool dp [1<<20] , _dp [1<<20]; void solve () { dp [0] = true ; for ( int i = 0 ; i < n ; i ++ ) { for ( int mask = 0 ; mask < (1<<m) ; mask ++ ) { for ( auto x : MASK [i] ) { if ( ((mask&x)==x) && dp[mask^x]==true ) _dp [mask] = true ; } } for ( int mask = 0 ; mask < (1<<m) ; mask ++ ) dp [mask] = _dp [mask] , _dp [mask] = false ; } bool ok = false ; for ( int mask = 0 ; mask < (1<<m) ; mask ++ ) ok |= dp [mask] ; if ( ok ) cout << "YES" ; else cout << "NO" ; } int main () { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // rf () ; cin >> n >> m ; for ( int i = 0 ; i < n ; i ++ ) cin >> a [i] ; for ( int i = 0 ; i < m ; i ++ ) cin >> b [i] ; prepare () ; solve () ; }

Compilation message (stderr)

bank.cpp: In function 'void rf()':
bank.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...