제출 #517311

#제출 시각아이디문제언어결과실행 시간메모리
517311zhangjishenBank (IZhO14_bank)C++98
100 / 100
269 ms4436 KiB
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second template<typename T> bool chkmin(T &a, T b){return b < a ? a = b, 1 : 0;} template<typename T> bool chkmax(T &a, T b){return b > a ? a = b, 1 : 0;} typedef long long ll; const int MAXN = 21, MAXS = 11e5; int n, m, a[MAXN], b[MAXN], s[MAXN], f[MAXS]; int sum(int i){ int ans = 0; for(int j = 1; j <= m; j++) if(i & (1 << (j - 1))) ans += b[j]; return ans; } int main(){ // input scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++){ scanf("%d", &a[i]); s[i] = s[i - 1] + a[i]; } for(int i = 1; i <= m; i++) scanf("%d", &b[i]); // dp f[0] = 1; for(int i = 1; i < (1 << m); i++){ int tot = sum(i), k = lower_bound(s + 1, s + 1 + n, tot) - s - 1, d = tot - s[k]; if(tot > s[n]) continue; for(int j = 1; j <= m; j++) if((i & (1 << (j - 1))) && b[j] <= d) f[i] |= f[i ^ (1 << (j - 1))]; } int ans = 0; for(int i = 0; i < (1 << m); i++) if(sum(i) == s[n]) ans |= f[i]; if(ans) printf("YES\n"); else printf("NO\n"); }

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

bank.cpp: In function 'int main()':
bank.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
bank.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%d", &b[i]);
      |   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...