Submission #674749

#TimeUsernameProblemLanguageResultExecution timeMemory
674749MinhOnePunchBank (IZhO14_bank)C++17
100 / 100
103 ms8532 KiB
#include <bits/stdc++.h> #define time_run cerr << 1.0*clock()/CLOCKS_PER_SEC << "\n" #define fdto(i, a, b) for(int i = (int)a; i >= (int)b; --i) #define fto(i, a, b) for(int i = (int)a; i <= (int)b; ++i) #define all(x) x.begin(), x.end() #define pb push_back #define ss second #define ff first #define endl '\n' using namespace std; using db = double; using ll = long long; using ii = pair<int, int>; using llll = pair<ll, ll>; const long long ooo = (ll)1e18 + 7; const int mod = (int)1e9 + 7, oo = (int)1e9 + 7; #define name "cpp" #define maxM (int)1e + 5 #define maxN (int)2e1 + 5 int n, m, a[maxN], b[maxN]; ii f[(1 << 20) + 5]; bool cmp(int a, int b){ return (a > b); } int main(){ // freopen(name".in", "r", stdin); freopen(name".out", "w", stdout); ios::sync_with_stdio(false), cin.tie(nullptr); // Like Elevator Rides cin >> n >> m; fto(i, 1, n) cin >> a[i]; fto(i, 0, m-1) cin >> b[i]; fto(mask, 1, (1 << m)-1) f[mask] = {-1, -1}; f[0] = {1, a[1]}; fto(mask, 1, (1 << m)-1){ fto(bit, 0, m-1){ if (mask >> bit & 1){ int pre = mask^(1 << bit); if (f[pre].ff != -1){ if (f[pre].ss - b[bit] == 0){ f[mask] = {f[pre] .ff+ 1, a[f[pre].ff+1]}; } else if (f[pre].ss - b[bit] > 0){ f[mask] = {f[pre].ff, f[pre].ss - b[bit]}; } } } } if (f[mask].ff == n + 1){ cout << "YES" << endl; return 0; } } cout << "NO" << endl; return (0-0); // winhonepunch <3s /* bài thang máy nhưng mà thang máy này mỗi lần đi là sẽ thày đổi giá trị cân nặng random_shuffle(v.begin(), v.end()): shuffles the order of the elements bitset<10^9 + 1> vẫn hợp lệ do mỗi bit chỉ chiếm 1 bit => 128 MB struct cmp{ // cmp for set bool operator()(const type& x, const type& y) const { return x. < y.; } }; __builtin_popcount(x) đếm số bit 1 trong x O(1) bitset.to_ulong() chuyển từ bitset sang số map should use for(const auto& it: map) a += b better than a = a + b; 1 hour -> tags -> each hint -> code */ }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...