Submission #68480

# Submission time Handle Problem Language Result Execution time Memory
68480 2018-08-17T08:08:24 Z MrTEK Bank (IZhO14_bank) C++14
0 / 100
37 ms 16888 KB
#include <bits/stdc++.h>
 
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define cout maltahsin
#define left ind + ind
#define right ind + ind + 1
#define mid (l + r) / 2 
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define FAST_IO ios_base::sync_with_stdio(false);
#define endl '\n'
 
const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9 + 5;
const int N = 20;
const int M = (2 << 20) + 5;
const int K = 1e3 + 5;
const int SQ = 350;
const int MOD = 998244353;
 
typedef pair <int,int> pii;

vector <int> S[K];

int n,m,dp[2][M],a[N],b[N];

void brute(int cur,int sum,int mask) {
	if (cur == m) {
		if (sum <= 1e3) S[sum].push_back(mask);
		return;
	}
	brute(cur + 1,sum,mask);
	brute(cur + 1,sum + b[cur],mask + (1 << cur));
}

int main() {

	scanf("%d %d",&n,&m);

	for (int i = 0 ; i < n ; i++) scanf("%d",&a[i]);
	for (int i = 0 ; i < m ; i++) scanf("%d",&b[i]);

	brute(0,0,0);

	dp[0][0] = 1;

	int cur = 0, nxt = 1;
	
	for (int i = 0 ; i < n ; i++) {
		for (int j = 0 ; j < M ; j++) {
			if (!dp[cur][j]) continue;
			for (auto it : S[i]) {
				if ((j & it) == 0) {
					dp[nxt][j + it] |= dp[cur][j];
				}
			}
		}
		for (int j = 0 ; j < M ; j++) dp[cur][j] = 0;
		swap(cur,nxt);
	}
	int ans = 0;
	for (int i = 0 ; i < M ; i++) ans |= dp[cur][i];
	printf(ans ? "YES\n" : "NO\n");
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
bank.cpp:48:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0 ; i < n ; i++) scanf("%d",&a[i]);
                                ~~~~~^~~~~~~~~~~~
bank.cpp:49:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0 ; i < m ; i++) scanf("%d",&b[i]);
                                ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8568 KB Output is correct
2 Incorrect 14 ms 8700 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 16832 KB Output is correct
2 Incorrect 26 ms 16848 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 16888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 8568 KB Output is correct
2 Incorrect 14 ms 8700 KB Output isn't correct
3 Halted 0 ms 0 KB -