Submission #790116

# Submission time Handle Problem Language Result Execution time Memory
790116 2023-07-22T10:45:59 Z Anonymous_Guys Bank (IZhO14_bank) C++17
19 / 100
1 ms 340 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;


using namespace __gnu_pbds;

template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define pb push_back
#define ii pair<int, int>
#define lol unsigned long long
#define lll __int128_t
#define fi first
#define se second
#define fou(i, a, b) for (int i = a; i <= b; ++i)
#define all(v) (v).begin(), (v).end()
#define MAX_N 10000000
#define el '\n'
#define BIT(mask, j) ((mask >> j) & 1)
#define MASK(X) (1LL << x)
typedef unsigned long long ll;
const int mxN = 1e4 + 9;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)4e18 + 7LL;

const int dx[] = {0, 1, 0, -1, 3, 0, -3, 0, 2, 2, -2, -2, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 0, 3, 0, -3, 1, -1, 1, -1, 2, -2, 2, -2} ;


int a[mxN], b[mxN];

int dp[mxN], ans[mxN];
int32_t main() {
    if (fopen("bank.in", "r")) {
        freopen("bank.in" ,"r", stdin);
        freopen("bank.out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m; cin >> n >> m;
    map<int, int> mp;
    fou(i, 1, n) cin >> a[i];
    fou(i, 1, m) {
        cin >> b[i];
        mp[b[i]]++;
    }


    bool kt = true;
    fou(i, 1, n) {
        memset(dp, 0, sizeof dp);
        dp[0] = 1; 
        fou(j, 1, m) {
            for (int k = a[i]; k >= b[j]; --k) {
                if (dp[k] == 0 && dp[k - b[j]] == 1) {
                    dp[k] = 1; ans[k] = k - b[j];
                }
            }
        }

        int j = a[i];
        bool ok = true;
        while(j > 0) {
            if (mp[j - ans[j]] == 0) {
                ok = false; break;
            }
            mp[j - ans[j]]--;
            j = ans[j];

        }
        if (!ok) {
            kt = false;
        //    cout << i <<" "; 
            break;
        }
    }
    if (kt) cout << "YES";
    else cout <<"NO";
    return 0 ;
}

Compilation message

bank.cpp: In function 'int32_t main()':
bank.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen("bank.in" ,"r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen("bank.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 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 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Halted 0 ms 0 KB -