| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1300496 | dhuyyyy | Bank (IZhO14_bank) | C++20 | 113 ms | 41632 KiB |
//https://cses.fi/problemset/task/1653/
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define dbg(x) "[" #x << " = " << x << "]"
using namespace std;
using ll = long long;
using ii = pair<int,int>;
using aa = array<int,3>;
bool maximize(int& a,int b){
if (a > b) return 0;
a = b;
return 1;
}
bool minimize(int &a,int b){
if (a <= b) return 0;
a = b;
return 1;
}
const int N = 25;
const int INF = 1e18;
const int MOD = 1e9+7;
int n, m;
int a[N], b[N], dp[(1 << 22)], pre[(1 << 22)], num[(1 << 22)];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
#define name "main"
if (fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
memset(pre,-1,sizeof pre);
pre[0] = 0;
for (int mask = 0; mask < (1 << m); mask++){
for (int j = 0; j < m; j++){
if (mask >> j & 1){
int before = mask ^ (1 << j);
if (pre[before] == -1) continue;
int cur = b[j] + num[before];
if (cur < a[pre[before]]){
pre[mask] = pre[before];
num[mask] = cur;
} else if (cur == a[pre[before]]) pre[mask] = pre[before] + 1;
}
}
if (pre[mask] == n) return cout << "YES",0;
}
cout << "NO";
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
