Submission #674734

# Submission time Handle Problem Language Result Execution time Memory
674734 2022-12-26T05:18:59 Z MinhOnePunch Bank (IZhO14_bank) C++17
19 / 100
78 ms 8424 KB
#include <bits/stdc++.h>
#define time_run cerr << 1.0*clock()/CLOCKS_PER_SEC << "\n"
#define fdto(i, a, b) for(int i = (int)a; i >= (int)b; --i)
#define fto(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define all(x) x.begin(), x.end()
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
using namespace std;
using db = double;
using ll = long long;
using ii = pair<int, int>;
using llll = pair<ll, ll>;
const long long ooo = (ll)1e18 + 7;
const int mod = (int)1e9 + 7, oo = (int)1e9 + 7;
#define name "cpp"
#define maxM (int)1e + 5
#define maxN (int)2e1 + 5
int n, m, a[maxN], b[maxN];
ii f[(1 << 20) + 5];

bool cmp(int a, int b){
    return (a > b);
}

int main(){
  //  freopen(name".in", "r", stdin); freopen(name".out", "w", stdout);
    ios::sync_with_stdio(false), cin.tie(nullptr);

    // Like Elevator Rides

    cin >> n >> m;
    fto(i, 1, n) cin >> a[i];
    fto(i, 0, m-1) cin >> b[i];

    sort(a + 1, a + 1 + n, cmp);

    f[0] = {1, a[1]};
    fto(mask, 1, (1 << m)-1){
        f[mask] = {oo, oo};
        fto(bit, 0, m-1){
            if (mask >> bit & 1){
                int pre = mask ^ (1 << bit);

                if (f[pre].ss - b[bit] >= 0){
                    if (f[pre].ff < f[mask].ff){
                        f[mask] = {f[pre].ff, f[pre].ss - b[bit]};
                    } else
                    if (f[pre].ff == f[mask].ff){
                        f[mask] = {f[mask].ff, max(f[mask].ss, f[pre].ss - b[bit])};
                    }
                } else
                if (a[f[pre].ff+1] - b[bit] >= 0){
                    if (f[pre].ff + 1 < f[mask].ff){
                        f[mask] = {f[pre].ff + 1, max(f[pre].ss, a[f[pre].ff+1] - b[bit])};
                    }
                }
            }
        }

        if (f[mask].ff == n && f[mask].ss == 0){
//            int msk = mask;
//            fto(mask, 0, msk){
//                cout << mask << " "; fto(bit, 0, m-1) cout << (mask >> bit & 1);
//                cout << endl;
//                cout << f[mask].ff << " " << f[mask].ss << endl;
//            }
            cout << "YES" << endl;
            return 0;
        }
    }

//    fto(mask, 0, (1 << m)-1){
//        cout << mask << " "; fto(bit, 0, m-1) cout << (mask >> bit & 1);
//        cout << endl;
//        cout << f[mask].ff << " " << f[mask].ss << endl;
//    }

    cout << "NO" << endl;
    return (0-0); // winhonepunch <3s
    /*
    bài thang máy nhưng mà thang máy này mỗi lần đi là sẽ thày đổi giá trị cân nặng

    random_shuffle(v.begin(), v.end()): shuffles the order of the elements
    bitset<10^9 + 1> vẫn hợp lệ do mỗi bit chỉ chiếm 1 bit => 128 MB
    struct cmp{ // cmp for set
       bool operator()(const type& x, const type& y) const {
           return x. < y.;
       }
    };
    __builtin_popcount(x) đếm số bit 1 trong x O(1)
    bitset.to_ulong() chuyển từ bitset sang số
    map should use for(const auto& it: map)
    a += b better than a = a + b;
    1 hour -> tags -> each hint -> code
    */
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 71 ms 8396 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 78 ms 8424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Incorrect 0 ms 212 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 71 ms 8396 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 78 ms 8424 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Incorrect 0 ms 212 KB Output isn't correct
18 Halted 0 ms 0 KB -