# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
705354 |
2023-03-04T06:12:45 Z |
vjudge1 |
Bank (IZhO14_bank) |
C++17 |
|
185 ms |
8404 KB |
// Problem: X - Bank
#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 rall(x) x.rbegin(), x.rend()
#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
#define int ll
const int N = 1e5 + 2 ;
const int P = 29 ;
const int MOD = 1e9 + 7 ;
int n , m , a[21] , b[21] , pref[21] , dp[(1 << 20) + 1];
int go(int i , int mask , int cur) {
if(cur == pref[i]) {
dbg(mask , pref[i]) ;
dp[mask] = 1 ;
i++ ;
}
if(i > n) {
cout << "YES\n" ;
exit(0) ;
}
if(~dp[mask]) return dp[mask] ;
int ans = 0 ;
rep(j , 0 , m - 1) {
if(!(mask >> j & 1)) {
ans |= go(i , mask ^ (1 << j) , cur + b[j + 1]) ;
}
}
dp[mask] = ans ;
return ans ;
}
void solve(){
memset(dp, -1, sizeof(dp)) ;
cin >> n >> m ;
rep(i , 1 , n) cin >> a[i] ;
rep(i , 1 , n) pref[i] = pref[i - 1] + a[i] ;
rep(i , 1 , m) cin >> b[i] ;
int ok = go(1, 0, 0) ;
// if(go(1, 0, 0)) {
// cout << "YES\n" ;
// }else{
cout << "NO\n" ;
// }
}
signed main () {
// freopen(".in","r",stdin) ;
// freopen(".out","w",stdout) ;
ios::sync_with_stdio(false) ;
cin.tie(0) ;
int test = 1 ;
// cin >> test ;
for(int i = 1 ; i <= test ; i++) {
solve() ;
}
}
Compilation message
bank.cpp: In function 'long long int go(long long int, long long int, long long int)':
bank.cpp:23:19: warning: statement has no effect [-Wunused-value]
23 | #define dbg(x...) 42
| ^~
bank.cpp:36:9: note: in expansion of macro 'dbg'
36 | dbg(mask , pref[i]) ;
| ^~~
bank.cpp: In function 'void solve()':
bank.cpp:61:9: warning: unused variable 'ok' [-Wunused-variable]
61 | int ok = go(1, 0, 0) ;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8404 KB |
Output is correct |
2 |
Correct |
4 ms |
8404 KB |
Output is correct |
3 |
Correct |
3 ms |
8404 KB |
Output is correct |
4 |
Correct |
4 ms |
8404 KB |
Output is correct |
5 |
Correct |
179 ms |
8404 KB |
Output is correct |
6 |
Correct |
3 ms |
8404 KB |
Output is correct |
7 |
Correct |
4 ms |
8404 KB |
Output is correct |
8 |
Correct |
6 ms |
8404 KB |
Output is correct |
9 |
Correct |
185 ms |
8404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
8404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
8404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8404 KB |
Output is correct |
2 |
Correct |
4 ms |
8404 KB |
Output is correct |
3 |
Correct |
3 ms |
8404 KB |
Output is correct |
4 |
Correct |
4 ms |
8404 KB |
Output is correct |
5 |
Correct |
179 ms |
8404 KB |
Output is correct |
6 |
Correct |
3 ms |
8404 KB |
Output is correct |
7 |
Correct |
4 ms |
8404 KB |
Output is correct |
8 |
Correct |
6 ms |
8404 KB |
Output is correct |
9 |
Correct |
185 ms |
8404 KB |
Output is correct |
10 |
Incorrect |
4 ms |
8404 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |