Submission #704011

#TimeUsernameProblemLanguageResultExecution timeMemory
704011vjudge1Bank (IZhO14_bank)C++17
71 / 100
1074 ms400 KiB
// Problem: Elevator Rides #include <bits/stdc++.h> using namespace std ; #define ff first #define ss second #define ll long long #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define ones(x) __builtin_popcount(x) #define remove(v) v.erase(unique(all(v)), v.end()) #define rep(i, a, b) for(int i = a; i <= b; i++) #define per(i, a, b) for(int i = a; i >= b; i--) #ifdef local #include "C:\debug.h" #else #define dbg(x...) 42 #endif const int N = 2e6 + 2 ; int n , m , a[21] , b[21] ; vector<int> cur[21] ; void go(int i , int mask) { if(i > n) { cout << "YES\n" ; exit(0) ; } for(auto& x : cur[i]) { bool ok = 1 ; rep(i , 0 , 32) { if((mask >> i & 1) == 1 && (x >> i & 1) == 1) { ok = 0 ; break ; } } if(ok) { go(i + 1 , (mask | x)) ; } } } void solve(){ cin >> n >> m ; rep(i , 1 , n) cin >> a[i] ; rep(i , 0 , m - 1) cin >> b[i] ; if(n == 1) { vector<vector<int>> dp(m + 1 , vector<int>(a[1] + 1 , 0)) ; rep(i , 0 , m) dp[i][0] = 1 ; rep(i , 1 , m) { rep(j , 1 , a[1]) { dp[i][j] = dp[i - 1][j] ; if(j - b[i - 1] >= 0) { dp[i][j] |= dp[i - 1][j - b[i - 1]] ; } } } cout << ((dp[m][a[1]]) ? "YES" : "NO") ; return ; } rep(i , 1 , n) { rep(j , 1 , (1 << m) - 1) { int curr = 0 ; rep(mask , 0 , m) { if((j >> mask & 1)) { curr += b[mask] ; } } if(curr == a[i]) { cur[i].pb(j) ; } } } go(1 , 0) ; cout << "NO" ; } int main () { ios::sync_with_stdio(false) ; cin.tie(0) ; int test = 1 ; // cin >> test ; for(int i = 1 ; i <= test ; i++) { solve() ; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...