Submission #684629

#TimeUsernameProblemLanguageResultExecution timeMemory
684629CyberCowBank (IZhO14_bank)C++17
100 / 100
113 ms8544 KiB
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <string> #include <cmath> #include <map> #include <unordered_map> #include <unordered_set> #include <fstream> #include <iomanip> #include <iterator> #include <stack> #include <deque> #define fi first #define se second using namespace std; using ll = long long; vector<int> a, b; void solve() { int n, m, i, j, x, y; cin >> n >> m; for ( i = 0; i < n; i++) { cin >> x; a.push_back(x); } for ( i = 0; i < m; i++) { cin >> x; b.push_back(x); } vector<int> dp(1 << m, -1); vector<int> mnac(1 << m, -1); dp[0] = 0; mnac[0] = 0; for (int mask = 0; mask < (1 << m); mask++) { for ( j = 0; j < m; j++) { if (((1 << j) & mask) == 0) continue; int ent = mask ^ (1 << j); if (dp[ent] == -1) continue; int unem = mnac[ent] + b[j]; if (unem == a[dp[ent]]) { dp[mask] = dp[ent] + 1; mnac[mask] = 0; } else if(unem < a[dp[ent]] && dp[mask] <= dp[ent]) { dp[mask] = dp[ent]; mnac[mask] = unem; } } if (dp[mask] == n) { cout << "YES\n"; return; } } cout << "NO\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int tt = 1; //cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

bank.cpp: In function 'void solve()':
bank.cpp:24:21: warning: unused variable 'y' [-Wunused-variable]
   24 |  int n, m, i, j, x, y;
      |                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...