Submission #1300496

#TimeUsernameProblemLanguageResultExecution timeMemory
1300496dhuyyyyBank (IZhO14_bank)C++20
100 / 100
113 ms41632 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)

bank.cpp: In function 'int main()':
bank.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bank.cpp:42:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...