# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
757061 |
2023-06-12T13:30:51 Z |
amine_aroua |
Bank (IZhO14_bank) |
C++17 |
|
161 ms |
11120 KB |
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define vll vector<pair<long long,long long>>
#define pb push_back
#define ll long long
#define ld long double
#define nl '\n'
#define boost ios::sync_with_stdio(false)
#define mp make_pair
#define se second
#define fi first
#define fore(i, y) for(ll i = 0; i < y; i++)
#define forr(i,x,y) for(int i = x;i<=y;i++)
#define forn(i,y,x) for(ll i = y; i >= x; i--)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define clr(v,k) memset(v,k,sizeof(v))
#define rall(v) v.rbegin() , v.rend()
#define pii pair<int,int>
#define pll pair<ll , ll>
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 1;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD)
ll lcm(ll a , ll b) {return a * (b / gcd(a , b));} // least common multiple (PPCM)
// HERE IS THE SOLUTION
int n;
vi pref;
map<int , vi> values;
vector<vi> dp;
bool solve(int i , int mask)
{
if(i == n)return 1;
int ans = dp[i][mask];
if(ans != -1)return ans;
ans = 0;
for(auto msk : values[pref[i]])
{
if((msk & mask) == mask)
ans|=solve(i + 1 , (msk|mask));
}
return ans;
}
int main()
{
cin.tie(0);
cout.tie(0);
boost;
int m;
cin>>n>>m;
vi bank(m) ;
dp.assign(n , vi((1<<m) , -1));
vi salary(n);
pref.assign(n , 0);
fore(i , n)
{
cin>>salary[i];
if(i == 0)pref[i] = salary[i];
else pref[i] = pref[i - 1] + salary[i];
}
fore(i , m)
{
cin>>bank[i];
}
fore(mask , (1<<m) - 1)
{
int sum = 0;
fore(i , m)
{
if((1<<i)&mask)
{
sum+=bank[i];
}
}
values[sum].pb(mask);
}
bool ans = solve(0 , 0);
if(ans)cout<<"YES"<<nl;
else cout<<"NO"<<nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
660 KB |
Output is correct |
5 |
Correct |
161 ms |
11120 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
144 ms |
9852 KB |
Output is correct |
9 |
Correct |
143 ms |
10280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
660 KB |
Output is correct |
5 |
Correct |
161 ms |
11120 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
144 ms |
9852 KB |
Output is correct |
9 |
Correct |
143 ms |
10280 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |