Submission #765741

#TimeUsernameProblemLanguageResultExecution timeMemory
765741tinhngoVNBank (IZhO14_bank)C++14
0 / 100
15 ms33236 KiB
#include <bits/stdc++.h> #define MAXN 22 using namespace std; int n,m,a[MAXN], b[MAXN]; int amt[1<<MAXN] , cnta[1<<MAXN]; //amt[i] la so tien con lai khi tra luong cho mot so nguoi o trang thai nhung to tien la i //cnta[i] la so nguoi duoc tra luong o trang thai nhung to tien la i void inp() { cin>>n>>m; for (int i=0; i<n; ++i) cin>>a[i]; for (int i=0; i<m; ++i) cin>>b[i]; } void out() { memset(amt , -1 , sizeof(amt)); memset(cnta , -1 , sizeof(cnta)); amt[0]=0; cnta[0]=0; for (int mask=0; mask<(1<<m); ++mask) { for (int i=0; i<m; ++i) { if (mask&(1<<i)) { int pre_mask = mask & ~(1<<i); if(cnta[pre_mask] == -1) continue; //Neu so nguoi o trang thai truoc chua duoc tinh int new_amt = amt[pre_mask] + b[i]; int cur = a[cnta[pre_mask]]; if(new_amt < cur) { cnta[mask] = cnta[pre_mask]; amt[mask] = new_amt; } else if (new_amt==cur) { cnta[mask] = cnta[pre_mask]+1; amt[mask] = 0; } } } if(cnta[mask] == n) { cout<<"YES\n"; return ; } } cout<<"NO\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); freopen("bank.inp" , "r" , stdin); freopen("bank.out" , "w" , stdout); inp(); out(); }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:59:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     freopen("bank.inp" , "r" , stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:60:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |     freopen("bank.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...