Submission #930911

#TimeUsernameProblemLanguageResultExecution timeMemory
930911AtabayRajabliBank (IZhO14_bank)C++17
100 / 100
152 ms9044 KiB
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; // author : a1abay // (a / b) % c = (a * b ^ (mod - 2)) % c; #define pb push_back #define pii pair<int, int> #define all(v) v.begin(), v.end() #define se second #define fi first #define int ll #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a*b / (__gcd(a, b))) #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> typedef long long ll; const int inf = 1e9 + 7; const int inff = 1e18 + 7; const int sz = 25; using namespace std; void open(string s, string f) { freopen((s + ".txt").c_str(), "r", stdin); freopen((f + ".txt").c_str(), "w", stdout); } int n, k, a[sz], b[sz], dp[(1 << sz) + 5], p[sz]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // open("in", "out"); cin >> n >> k; for(int i = 1; i <= n; i++)cin >> a[i], p[i] = p[i - 1] + a[i]; for(int i = 1; i <= k; i++)cin >> b[i]; for(int i = 1; i < (1 << k); i++) { int cur = 0; for(int j = 0; j < k; j++) { if(i & (1 << j))cur += b[j + 1]; } for(int j = 0; j < k; j++) { if(i & (1 << j)) { int x = (i ^ (1 << j)); dp[i] = max(dp[i], dp[x] + (p[dp[x] + 1] == cur)); } } } if(dp[(1 << k) - 1] != n)cout << "NO"; else cout << "YES"; }

Compilation message (stderr)

bank.cpp: In function 'void open(std::string, std::string)':
bank.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((s + ".txt").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen((f + ".txt").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...