Submission #980941

#TimeUsernameProblemLanguageResultExecution timeMemory
980941khanhtbBank (IZhO14_bank)C++14
0 / 100
8 ms25436 KiB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vll vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 26;
const ll blocksz = 320;
const ll N = 1e6+8;
const ll buff = 2e7+8;
ll n,m,dp[1<<20],a[21],b[21];
vi premask[N];
void solve(){
    cin >> n >> m;
    for(ll i = 0; i < n; i++) cin >> a[i];
    for(ll i = 0; i < m; i++) cin >> b[i];  
    for(ll mask = 1; mask < 1<<m; mask++){
        dp[mask] = -1;
        ll sum = 0;
        for(ll i = 0; i < m; i++){
            if(mask>>i&1) sum += b[i];
        }
        premask[sum].pb(mask);
    }
    for (ll i = 0; i < n; i++) {
		for (ll mask = (1<<m)-1; mask >= 0; mask--) {
			if (dp[mask] != -1) {
				for (ll submask:premask[a[i]]) {
					if (submask&mask) {
						dp[submask|mask] = dp[mask]+1;
						if (dp[submask|mask] == n) {
							cout << "YES";
							return;
						}
					}
				}
			}
		}
	}
	cout << "NO";
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    if(fopen("test.inp","r")){
        freopen("test.inp","r",stdin);
        freopen("test.out","w",stdout);
    }
    int T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << '\n';
    }
}    

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen("test.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("test.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...