Submission #376145

#TimeUsernameProblemLanguageResultExecution timeMemory
376145pandaBank (IZhO14_bank)C++14
100 / 100
963 ms86784 KiB
#include <iostream> #include <vector> #include <stack> #include <queue> #include <map> #include <unordered_map> #include <set> #include <assert.h> #include <algorithm> using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vpi; const int MX = 20; const int MOD = 1e9 + 7; const int INF = 2e9; #define F0R(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define pb push_back #define mp make_pair #define f first #define s second #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)x.size() #define len(x) (int)x.length() #define rsz resize #define lb lower_bound #define ub upper_bound void setIn(string s) { freopen(s.c_str(),"r",stdin); } void setOut(string s) { freopen(s.c_str(),"w",stdout); } void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } } int N, M, A[MX + 5], B[MX + 5]; int dp[MX + 5][(1 << MX)]; int main() { F0R(i, MX + 1) F0R(j, (1 << MX)) dp[i][j] = -1; cin >> N >> M; FOR(i, 1, N + 1) cin >> A[i]; FOR(i, 1, M + 1) cin >> B[i]; dp[0][0] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j < (1 << M); j++) if (dp[i - 1][j] == 0) dp[i][j] = dp[i - 1][j] + A[i]; for (int j = 1; j <= M; j++) { for (int k = 0; k < (1 << M); k++) { //cout << "on bitmask: " << k << " for " << i << "\n"; if (dp[i][k] != -1 && !(k & (1 << (j - 1))) && dp[i][k] - B[j] >= 0) { //cout << "Passed bitmask: " << k << "\n"; dp[i][k | (1 << (j - 1))] = dp[i][k] - B[j]; //cout << i << ", " << (k | (1 << (j - 1))) << " has the value: " << dp[i][k | (1 << (j - 1))] << "\n"; } } } } bool good = 0; F0R(i, (1 << MX)) if (dp[N][i] == 0) { good = 1; //cout << N << " with bitmask " << i << "\n"; //cout << "We've used the notes: \n"; //for (int k = 1; k <= M; k++) if (i & (1 << (k - 1))) cout << k << " "; //cout << "\n"; } cout << (good ? "YES\n" : "NO\n"); }

Compilation message (stderr)

bank.cpp: In function 'void setIn(std::string)':
bank.cpp:35:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 | void setIn(string s) { freopen(s.c_str(),"r",stdin); }
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bank.cpp: In function 'void setOut(std::string)':
bank.cpp:36:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   36 | void setOut(string s) { freopen(s.c_str(),"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...