제출 #1074638

#제출 시각아이디문제언어결과실행 시간메모리
1074638vjudge1은행 (IZhO14_bank)C++17
71 / 100
1062 ms66116 KiB
#include <bits/stdc++.h> #define int long long using namespace std; #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(a) (int)(a).size() #define el '\n' #define F first #define S second #define For(i, a, b) for (int i = (a); i <= (int)(b); i++) #define Rof(i, a, b) for (int i = (a); i >= (int)(b); i--) #define Fore(it, x) for (auto it = (x).begin(); it != (x).end(); ++it) using vb = vector<bool>; using vvb = vector<vb>; using vc = vector<char>; using vvc = vector<vc>; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vii = vector<pii>; //*** START CODING ***// int setBit(int n, int pos) { return n |= (1 << pos); } int clearBit(int n, int pos) { return n &= ~(1 << pos); } int getBit(int n, int pos) { return (n >> pos) & 1; } int toggleBit(int n, int pos) { return n ^= (1 << pos); } const long long oo = 2e18, mod = 1e9 + 7; const int ms = 20 + 5; int n, m; int a[ms], b[ms]; vvi memo; vi maskSum; bool f(int mask, int idx) { if (idx == n) return true; if (memo[mask][idx] != -1) return memo[mask][idx]; bool ans = false; for (int mk = 0; mk < (1LL << m); mk++) { if (mk & mask) continue; if (maskSum[mk] == a[idx]) { // cout << "found" << el; int newMask = mk | mask; ans |= f(newMask, idx + 1); } } return memo[mask][idx] = ans; }; void solve() { cin >> n >> m; For(i, 0, n - 1) cin >> a[i]; For(i, 0, m - 1) cin >> b[i]; memo = vvi(1 << m, vi(n, -1)); maskSum = vi(1 << m, 0); for (int mask = 0; mask < (1LL << m); mask++) { for (int i = 0; i < m; i++) { if (getBit(mask, i)) { maskSum[mask] += b[i]; } // cout << getBit(mask, i) << ""; } // cout << " " << mask << " " << maskSum[mask] << el; } bool ans = f(0, 0); if (ans) cout << "YES" << el; else cout << "NO" << el; // cout << f(0, 0) << el; } int32_t main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'bool f(long long int, long long int)':
bank.cpp:51:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   51 |     return memo[mask][idx] = ans;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...