Submission #475026

# Submission time Handle Problem Language Result Execution time Memory
475026 2021-09-20T15:09:00 Z innocentkitten Bank (IZhO14_bank) C++14
100 / 100
132 ms 8588 KB
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define p push
#define ins insert
#define t top
#define fr front

#define T1 10
#define T2 100
#define T3 1000
#define T4 10000
#define T5 100000
#define T6 1000000

#define H1 11
#define H2 105
#define H3 1010
#define H4 10010
#define H5 100010
#define H6 1000010

#define H H6+H5
#define HH 43

#define woof 31051
#define mod 998244353
#define MOD 1000000007
#define lnf 0
#define inf 1069999999
#define INF 2099999999
#define LNF 1e18

// sacrilege
#define F0(x,n) for(int x = 0; x < n; ++x)
#define FR0(x,L,R) for(int x = L; x < R; ++x)
#define R0(x,n) for(int x = n-1; x >= 0; --x)
#define F1(x,n) for(int x = 1; x <= n; ++x)
#define FR1(x,L,R) for(int x = L; x <= R; ++x)
#define R1(x,n) for(int x = n; x >= 1; --x)
#define RR(x,L,R) for(int x = R; x >= L; --x)
#define FE(x,ls) for(auto x : ls)
#define ub(x,v) upper_bound(x.begin(),x.end(),v)
#define lb(x,v) lower_bound(x.begin(),x.end(),v)


using namespace std;
mt19937 mr(time(0));
typedef long long int ll;
struct LL {

    static const ll m = mod; // set to LNF for nomod
    long long int val;

    LL(ll v) {val=reduce(v);};
    LL(int v) {val=reduce((ll)v);};
    LL() {val=0;};
    ~LL(){};
    LL(const LL& l) {val=l.val;};
    LL& operator=(int l) {val=l; return *this;}
    LL& operator=(ll l) {val=l; return *this;}
    LL& operator=(LL l) {val=l.val; return *this;}

    static long long int reduce(ll x, ll md = m) {
        x %= md;
        while (x >= md) x-=md;
        while (x < 0) x+=md;
        return x;
    }

    bool operator<(const LL& b) { return val<b.val; }
    bool operator<=(const LL& b) { return val<=b.val; }
    bool operator!=(const LL& b) { return val!=b.val; }
    bool operator==(const LL& b) { return val==b.val; }
    bool operator>=(const LL& b) { return val>=b.val; }
    bool operator>(const LL& b) { return val>b.val; }

    LL operator+(const LL& b) { return LL(val+b.val); }
    LL operator+(const ll& b) { return (*this+LL(b)); }
    LL& operator+=(const LL& b) { return (*this=*this+b); }
    LL& operator+=(const ll& b) { return (*this=*this+b); }

    LL operator-(const LL& b) { return LL(val-b.val); }
    LL operator-(const ll& b) { return (*this-LL(b)); }
    LL& operator-=(const LL& b) { return (*this=*this-b); }
    LL& operator-=(const ll& b) { return (*this=*this-b); }

    LL operator*(const LL& b) { return LL(val*b.val); }
    LL operator*(const ll& b) { return (*this*LL(b)); }
    LL& operator*=(const LL& b) { return (*this=*this*b); }
    LL& operator*=(const ll& b) { return (*this=*this*b); }

    static LL exp(const LL& x, const ll& y){
        ll z = y;
        z = reduce(z,m-1);
        LL ret = 1;
        LL w = x;
        while (z) {
            if (z&1) ret *= w;
            z >>= 1; w *= w;
        }
        return ret;
    }
    LL& operator^=(ll y) { return (*this=LL(val^y)); }

    LL operator/(const LL& b) { return ((*this)*exp(b,-1)); }
    LL operator/(const ll& b) { return (*this/LL(b)); }
    LL operator/=(const LL& b) { return ((*this)*=exp(b,-1)); }
    LL& operator/=(const ll& b) { return (*this=*this/LL(b)); }

}; ostream& operator<<(ostream& os, const LL& obj) { return os << obj.val; }
typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<int,LL> piL;
typedef pair<ll,ll> pll;
typedef pair<LL,LL> pLL;
typedef pair<pll,ll> tri;
typedef pair<LL,pLL> TRI;
using namespace std;

ll cases,N,M,Q,K,X,Y;

ll rd() {ll x;cin>>x; return x;}
void fl() {cout.flush();}

void panic(ll out) {
    cout << out << endl;
    exit(0);
}


pii DP[H];
int A[25];
int B[25];
void read() {
    N=rd();M=rd();
    F0(i,N) A[i]=rd(); A[N]=69696969;
    F0(i,M) B[i]=rd();
    DP[0]={0,0};
    F1(i,(1<<M)-1) {
        DP[i]={0,0};
        F0(j,M) {
            if (i&(1<<j)) {
                pii k = DP[i^(1<<j)];
                if (B[j]+k.s==A[k.f]) k={k.f+1,0};
                else k.s+=B[j];
                if (k>DP[i]) DP[i]=k;
            }
        }
    }
    cout << ((DP[(1<<M)-1].f==N)?"YES":"NO") << endl;
}

int main() {

    bool trials = 0;
    bool interactive = 0;

    if (!interactive) {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
    }

    if (trials) cases=rd();
    else cases=1;
    while (cases--) {
        read();
    }

}

Compilation message

bank.cpp: In function 'void read()':
bank.cpp:37:17: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   37 | #define F0(x,n) for(int x = 0; x < n; ++x)
      |                 ^~~
bank.cpp:139:5: note: in expansion of macro 'F0'
  139 |     F0(i,N) A[i]=rd(); A[N]=69696969;
      |     ^~
bank.cpp:139:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  139 |     F0(i,N) A[i]=rd(); A[N]=69696969;
      |                        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 93 ms 8484 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 130 ms 8516 KB Output is correct
9 Correct 97 ms 8524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 456 KB Output is correct
11 Correct 2 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 93 ms 8484 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 130 ms 8516 KB Output is correct
9 Correct 97 ms 8524 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 2 ms 460 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 2 ms 332 KB Output is correct
29 Correct 2 ms 456 KB Output is correct
30 Correct 2 ms 388 KB Output is correct
31 Correct 106 ms 8520 KB Output is correct
32 Correct 113 ms 8404 KB Output is correct
33 Correct 122 ms 8508 KB Output is correct
34 Correct 100 ms 8416 KB Output is correct
35 Correct 107 ms 8480 KB Output is correct
36 Correct 97 ms 8468 KB Output is correct
37 Correct 100 ms 8516 KB Output is correct
38 Correct 94 ms 8528 KB Output is correct
39 Correct 96 ms 8480 KB Output is correct
40 Correct 102 ms 8488 KB Output is correct
41 Correct 95 ms 8508 KB Output is correct
42 Correct 132 ms 8472 KB Output is correct
43 Correct 116 ms 8588 KB Output is correct
44 Correct 95 ms 8516 KB Output is correct
45 Correct 124 ms 8476 KB Output is correct
46 Correct 116 ms 8516 KB Output is correct
47 Correct 101 ms 8460 KB Output is correct
48 Correct 126 ms 8524 KB Output is correct
49 Correct 94 ms 8516 KB Output is correct
50 Correct 110 ms 8400 KB Output is correct
51 Correct 102 ms 8408 KB Output is correct
52 Correct 98 ms 8516 KB Output is correct
53 Correct 122 ms 8496 KB Output is correct
54 Correct 109 ms 8460 KB Output is correct
55 Correct 106 ms 8468 KB Output is correct
56 Correct 103 ms 8516 KB Output is correct
57 Correct 91 ms 8508 KB Output is correct
58 Correct 101 ms 8420 KB Output is correct