제출 #723480

#제출 시각아이디문제언어결과실행 시간메모리
723480PanosPaskBank (IZhO14_bank)C++14
71 / 100
1078 ms1004 KiB
#include <bits/stdc++.h> #define MAXN 20 #define CHECK_BIT(var, pos) (var & (1 << pos)) using namespace std; int n, m; // dp[i]: Contains all of the possible remaining sets of banknotes after serving the first i customers unordered_set<int> dp[MAXN + 2]; vector<int> accept_by[MAXN + 2]; int notes[MAXN + 2]; int reqs[MAXN + 2]; int calc_sum_by_subset(int s) { int ans = 0; for (int i = 0; i < m; i++) if (CHECK_BIT(s, i)) ans += notes[i]; return ans; } int main(void) { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &reqs[i]); for (int j = 0; j < m; j++) scanf("%d", &notes[j]); int start = 0; // No notes used dp[0].insert(start); // For each customer, calculate all the acceptable sets of notes that would equate to their salary for (int i = 1; i <= n; i++) { for (int s = 0; s < (1<<m); s++) { if (calc_sum_by_subset(s) == reqs[i]) accept_by[i].push_back(s); } } // See if there are any distinct subsets for (int i = 1; i <= n; i++) { for (auto to_add : accept_by[i]) for (auto have_used : dp[i-1]) { // Check if any note is already used if ((to_add ^ have_used) != to_add + have_used) continue; // Add the current combination of notes dp[i].insert(to_add ^ have_used); } } bool ans = !dp[n].empty(); if (ans) printf("YES\n"); else printf("NO\n"); return 0; }

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

bank.cpp: In function 'int main()':
bank.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%d", &reqs[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~
bank.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d", &notes[j]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...