답안 #304803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
304803 2020-09-21T22:29:42 Z NaimSS 은행 (IZhO14_bank) C++14
100 / 100
539 ms 15608 KB
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
//#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
#define left sefude
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl; 
#define prl cerr<<"called: "<< __LINE__ << endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}




const int N = 20;
int a[N],b[N];
vi here[N];

bool good[N][(1<<N) + 1];

int32_t main(){
  fastio;
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<m;i++)cin >> b[i];
  
  for(int msk=1;msk<(1<<m);msk++){
    int tot=0;
    for(int j=0;j<m;j++)if((1<<j)&msk){
      tot+=b[j];
    }
    for(int i=0;i<n;i++)if(a[i] == tot){
      here[i].pb(msk);
    }

  }

  for(int i=0;i<n;i++){
    
    for(int j=0;j<(1<<m);j++){
      if((i == 0 and j == 0) || (i!=0 and good[i-1][j])){

      }else continue;
      for(auto v : here[i]){

        if((v&j) == 0){
            good[i][j^v]=1;
        }
      }

    }
  }
  
  bool ok = 0;
  for(int j=0;j<(1<<m);j++)ok|=good[n-1][j];
  cout << (ok ? "YES" : "NO")<<endl;


  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 75 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 75 ms 1400 KB Output is correct
9 Correct 77 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 404 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 75 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 75 ms 1400 KB Output is correct
9 Correct 77 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 404 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 82 ms 1144 KB Output is correct
32 Correct 168 ms 2552 KB Output is correct
33 Correct 91 ms 1656 KB Output is correct
34 Correct 97 ms 504 KB Output is correct
35 Correct 99 ms 504 KB Output is correct
36 Correct 116 ms 384 KB Output is correct
37 Correct 78 ms 392 KB Output is correct
38 Correct 86 ms 384 KB Output is correct
39 Correct 110 ms 5496 KB Output is correct
40 Correct 97 ms 384 KB Output is correct
41 Correct 119 ms 504 KB Output is correct
42 Correct 93 ms 3832 KB Output is correct
43 Correct 92 ms 1016 KB Output is correct
44 Correct 108 ms 384 KB Output is correct
45 Correct 84 ms 2936 KB Output is correct
46 Correct 88 ms 2424 KB Output is correct
47 Correct 107 ms 384 KB Output is correct
48 Correct 75 ms 1400 KB Output is correct
49 Correct 74 ms 384 KB Output is correct
50 Correct 214 ms 15480 KB Output is correct
51 Correct 98 ms 632 KB Output is correct
52 Correct 103 ms 3448 KB Output is correct
53 Correct 539 ms 8312 KB Output is correct
54 Correct 240 ms 15096 KB Output is correct
55 Correct 207 ms 15608 KB Output is correct
56 Correct 207 ms 15608 KB Output is correct
57 Correct 210 ms 14456 KB Output is correct
58 Correct 208 ms 14468 KB Output is correct