제출 #1105874

#제출 시각아이디문제언어결과실행 시간메모리
1105874akamizane은행 (IZhO14_bank)C++17
100 / 100
102 ms8784 KiB
#include<bits/stdc++.h>
 
using namespace std;

#define debug(...) 40

 
using ll = long long;
using pii = pair<int,int>;

#define el cout << '\n'
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
template <class T1, class T2>bool chmax(T1 &a, T2 b){return a < b ? a = b, 1 : 0;}
template <class T1, class T2>bool chmin(T1 &a, T2 b){return a > b ? a = b, 1 : 0;}
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int maxn = 2e5 + 5;

const ll mod = 1e9 + 7;

void solve(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (auto& x : a) cin >> x;
  for (auto& x : b) cin >> x;
  debug(a, b);
  vector<pii> dp(1 << m, {0, 0});
  for (int i = 0; i < (1 << m); i++){
    for (int j = 0; j < m; j++){
      if (i >> j & 1) continue;
      int nxt = i | (1 << j);
      auto [x, y] = dp[i];
      if (y + b[j] < a[x]){
        y += b[j];
      }
      else if (y + b[j] == a[x]){
        x++;
        y = 0;
      }
      pii cur = {x, y};
      chmax(dp[nxt], cur);
      if (x == n){
        cout << "YES";
        return;
      }
    }
  }
  cout << "NO";
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests = 1;
  // cin >> tests;
  for (int _ = 1; _ <= tests; _++){
    solve();
    el;
  }
  return 0;
}

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

bank.cpp: In function 'void solve()':
bank.cpp:5:20: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...) 40
      |                    ^~
bank.cpp:34:3: note: in expansion of macro 'debug'
   34 |   debug(a, b);
      |   ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...