Submission #1039861

#TimeUsernameProblemLanguageResultExecution timeMemory
1039861lmaobruhBank (IZhO14_bank)C++14
0 / 100
17 ms82524 KiB
// 027 072 207 270 702 720 #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(x) x.begin(), x.end() #define fo(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i) #define fod(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i) #define rep(i, n) fo(i, 1, n) #define per(i, n) fod(i, n, 1) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) const int N = 1e6+5; int n, m, a[N], b[N], dp[20][1<<20]; void sol() { cin >> n >> m; rep(i, n) cin >> a[i]; fo(i, 0, m-1) cin >> b[i]; memset(dp, -1, sizeof dp); dp[1][0] = 0; for (int i = 1; i <= n; ++i) for (int mask = 0; mask < (1<<m); ++mask) if (dp[i][mask] != -1) { for (int j = 0; j < m; ++j) if (!(mask>>j&1)) { if (dp[i][mask] + b[j] <= a[i]) { dp[i][mask^(1<<j)] = dp[i][mask] + b[j]; // if (mask == 4 && i == 1) dbg(j, b[j], dp[i][mask], mask^(1<<j), dp[i][mask]+b[j]); } if (dp[i][mask] == a[i] && b[j] <= a[i+1]) dp[i+1][mask^(1<<j)] = b[j]; } } for (int mask = 0; mask < (1<<m); ++mask) if (dp[n][mask] == a[n]) return cout << "YES\n", void(); cout << "NO\n"; } signed main() { cin.tie(0) -> sync_with_stdio(0); if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin); else { #define task "bank" freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } int tc = 1, test = 0; // cin >> tc; while (++test <= tc) sol(); }

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:43:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp:46:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |    freopen(task".in", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:47:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |    freopen(task".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...