제출 #519698

#제출 시각아이디문제언어결과실행 시간메모리
519698aadit_ambadkar은행 (IZhO14_bank)C++17
44 / 100
2 ms3148 KiB
/* This code belongs to Aadit Ambadkar Date: 2022-01-25 21:41:41 Problem: bank */ #include <bits/stdc++.h> using namespace::std; typedef long long ll; #define F0R(i, n) for (int i = 0; i < n; i++) #define R0F(i, n) for (int i = n-1; i >= 0; i--) #define FOR(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define fastio ios::sync_with_stdio(0); cin.tie(0) #define MOD 1000000007 #define FF first #define SS second vector<int> a; vector<int> b; int n, m; bool works = false; vector<vector<bool>> vis(21, vector<bool>(1048577, false)); vector<pair<int, int>> cr; void recur(int ly, int cmsk) { vis[ly][cmsk]=true; cr.clear(); F0R(i, m) { if ((cmsk & (1 << i))==0) { // sm+=b[i]; cr.pb({b[i], i}); } } // for (auto i : cr) { // cout << i.FF << " " << i.SS << " "; // } // cout << "\n"; for (int kmsk = 1; kmsk <= (1 << (cr.size()+1)); kmsk++) { int sum = 0; F0R(i, cr.size()) { if (kmsk & (1<<i)) { sum+=cr[i].FF; } // if (sum > a[ly]) break; } if (sum==a[ly]) { int msk = cmsk; F0R(i, (cr.size()+1)) { if (kmsk & (1<<i)) { msk|=(1<<(cr[i].SS)); } } // cout << ly << " " << cmsk << " " << msk << "\n"; if (ly==n-1) { cout << "YES\n"; exit(EXIT_SUCCESS); } if (!vis[ly+1][msk]) recur(ly+1, msk); } } // for (int msk = cmsk+1; msk < (1<<m); msk++) { // if ((cmsk & msk) == cmsk) { // learned by thinking // int tmsk = msk ^ cmsk; // int sum = 0; // F0R(i, m) { // if (tmsk & (1<<i)) { // sum+=b[i]; // } // if (sum > a[ly]) break; // } // if (sum==a[ly]) { // if (ly == n-1) { // cout << "YES\n"; // exit(EXIT_SUCCESS); // } else { // if (!vis[ly+1][msk]) { // recur(ly+1, msk); // } // } // } // } // } } int main() { fastio; cin >> n >> m; if (n==1) { int k; cin >> k; vector<int> arr(m, 0); F0R(i, m) cin >> arr[i]; sort(arr.begin(), arr.end()); set<int> psbl; psbl.insert(0); F0R(i, m) for (auto it = psbl.rbegin(); it != psbl.rend(); it++) { psbl.insert((*it)+arr[i]); } if (psbl.count(k)) { cout << "YES\n"; } else { cout << "NO\n"; } } else { int x; F0R(i, n) { cin >> x; a.pb(x); } F0R(i, m) { cin >> x; b.pb(x); } recur(0, 0); cout << "NO\n"; } }

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

bank.cpp: In function 'void recur(int, int)':
bank.cpp:10:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define F0R(i, n) for (int i = 0; i < n; i++)
......
   40 |         F0R(i, cr.size()) {
      |             ~~~~~~~~~~~~             
bank.cpp:40:9: note: in expansion of macro 'F0R'
   40 |         F0R(i, cr.size()) {
      |         ^~~
bank.cpp:10:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 | #define F0R(i, n) for (int i = 0; i < n; i++)
......
   48 |             F0R(i, (cr.size()+1)) {
      |                 ~~~~~~~~~~~~~~~~     
bank.cpp:48:13: note: in expansion of macro 'F0R'
   48 |             F0R(i, (cr.size()+1)) {
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...