답안 #337884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337884 2020-12-22T04:36:19 Z kutbilim_one 은행 (IZhO14_bank) C++14
100 / 100
566 ms 86800 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define all(x) x.begin(), x.end()

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie();

	int n, m;
    cin >> n >> m;

    vector<int> a(n), b(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int j = 0; j < m; j++) cin >> b[j];

    int maxx = *max_element(all(a));
    vector<int> pass[1 + maxx];
    for(int bin = 1; bin < (1 << m); bin++){
    	int i = 0, sum = 0, temp = bin;
    	while(temp){
    		if(temp & 1) sum += b[i];
    		temp >>= 1;
    		i++;
    	}
    	if(sum <= maxx) pass[sum].push_back(bin);
    }

    vector< vector<int> > dp(n, vector<int> (1 << m, false));

    for(int i = 0; i < pass[a[0]].size(); i++){
    	dp[0][pass[a[0]][i]] = true;
    }

    for(int i = 1; i < n; i++){
    	int good = 0;
    	for(int bin = 0; bin < (1 << m); bin++){
    		if(!dp[i-1][bin]) continue;
    		for(auto last : pass[a[i]])
    			if(!(last & bin)) dp[i][last|bin] = good = true;
    	}
    	if(!good) break;
    }

    bool ans = false;
    for(int i = 0; !ans && i < (1 << m); i++){
    	if(dp[n-1][i]) ans = true;
    }

    if(ans) cout << "YES";
    else cout << "NO";


	return 0;
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i = 0; i < pass[a[0]].size(); i++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 78 ms 8556 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 78 ms 11372 KB Output is correct
9 Correct 85 ms 14700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 396 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 2 ms 620 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 2 ms 1260 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 748 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 2 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 78 ms 8556 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 78 ms 11372 KB Output is correct
9 Correct 85 ms 14700 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 396 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 2 ms 876 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 2 ms 1004 KB Output is correct
23 Correct 2 ms 1260 KB Output is correct
24 Correct 2 ms 1004 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 640 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 876 KB Output is correct
29 Correct 2 ms 876 KB Output is correct
30 Correct 2 ms 1388 KB Output is correct
31 Correct 85 ms 17004 KB Output is correct
32 Correct 173 ms 19180 KB Output is correct
33 Correct 98 ms 33280 KB Output is correct
34 Correct 106 ms 45548 KB Output is correct
35 Correct 109 ms 49644 KB Output is correct
36 Correct 137 ms 86636 KB Output is correct
37 Correct 83 ms 12780 KB Output is correct
38 Correct 87 ms 20844 KB Output is correct
39 Correct 117 ms 37356 KB Output is correct
40 Correct 102 ms 45548 KB Output is correct
41 Correct 125 ms 86800 KB Output is correct
42 Correct 96 ms 25204 KB Output is correct
43 Correct 99 ms 37356 KB Output is correct
44 Correct 115 ms 66028 KB Output is correct
45 Correct 85 ms 16876 KB Output is correct
46 Correct 94 ms 29292 KB Output is correct
47 Correct 124 ms 66028 KB Output is correct
48 Correct 78 ms 9452 KB Output is correct
49 Correct 78 ms 8684 KB Output is correct
50 Correct 233 ms 86764 KB Output is correct
51 Correct 107 ms 47084 KB Output is correct
52 Correct 113 ms 45548 KB Output is correct
53 Correct 566 ms 45548 KB Output is correct
54 Correct 256 ms 86636 KB Output is correct
55 Correct 230 ms 86636 KB Output is correct
56 Correct 231 ms 86636 KB Output is correct
57 Correct 230 ms 86636 KB Output is correct
58 Correct 231 ms 82540 KB Output is correct