# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1129209 | wafaa_s_473 | 은행 (IZhO14_bank) | C++20 | 2 ms | 324 KiB |
#include <bits/stdc++.h>
#define el <<'\n' ;
#define Lol ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) v.begin() , v.end()
#define rall(v) v.rbegin() , v.rend()
#define sz(s) (int)s.size()
#define int long long
/*
* ياا مسهل الاحوال
*/
using namespace std;
void _3K_W_RABK_YFK(){
int n , m; cin>>n>>m ;
vector<int>a(n) , b(m) , pre(1);
for( auto &i:a ) cin>>i , pre.push_back(pre.back() + i);
for( auto &i:b ) cin>>i ;
vector<int>dp(1 << m) ;
dp[0] = 0 ;
int idx = 0 ;
for( int msk = 1 ; msk < (1 << m) ; ++msk ){
int sum = 0 ;
for( int i = 0 ; i < m ; ++i )
if( msk & (1 << i) )
sum += b[i] ;
for( int i = 0 ; i < m ; ++i ){
if( msk & (1 << i) ){
int prv = dp[msk ^ (1 << i)] ;
dp[msk] = max(dp[msk] , prv) ;
if( prv < n and a[prv] == sum - pre[prv] )
dp[msk] = max(dp[msk] , prv + 1) ;
}
}
idx = max(idx, dp[msk]) ;
// cout<<msk<<' '<<dp[msk]<<endl;
}
cout<<(idx == n ? "YES" : "NO") ;
}
int32_t main()
{
Lol
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t=1 ;// cin>>t ;
for( int i=1; i<=t; ++i ){
_3K_W_RABK_YFK();
}
return 0;
}
/* practice makes PERFECT */
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |