Submission #13510

# Submission time Handle Problem Language Result Execution time Memory
13510 2015-02-22T13:26:30 Z tncks0121 Bank (IZhO14_bank) C++14
19 / 100
74 ms 596 KB
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h> 
#include <time.h>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;

const int Z = 20;
int N, M, A[Z], B[Z];
bool visited[Z][1 << Z];
vector<int> S[Z];

void backtrack(int i, int state) {
	if (visited[i][state]) return;
	visited[i][state] = true;

	if (i == N) {
		puts("YES");
		exit(0);
	}

	for (int e = 0; e < S[i].size(); e++) {
		int s = S[i][e];
		if (state & s) continue;
		backtrack(i + 1, state | s);
	}
}
int main() {

	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) scanf("%d", A + i);
	for (int j = 0; j < M; j++) scanf("%d", B + j);

	for (int state = 0; state < (1 << M); state++) {
		int sum = 0;
		for (int i = 0; i < M; i++) if (state & (1 << i)) sum += B[i];
		for (int i = 0; i < N; i++) if (sum == A[i]) S[i].push_back(sum);
	}

	backtrack(0, 0);

	puts("NO");

	return 0;
}

Compilation message

bank.cpp: In function 'void backtrack(int, int)':
bank.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int e = 0; e < S[i].size(); e++) {
                  ~~^~~~~~~~~~~~~
bank.cpp: In function 'int main()':
bank.cpp:53: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:54:35: 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:55:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int j = 0; j < M; j++) scanf("%d", B + j);
                              ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 392 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 73 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 74 ms 596 KB Output is correct
9 Correct 73 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 392 KB Output is correct
3 Correct 2 ms 596 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 73 ms 596 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 74 ms 596 KB Output is correct
9 Correct 73 ms 596 KB Output is correct
10 Incorrect 2 ms 596 KB Output isn't correct
11 Halted 0 ms 0 KB -