Submission #173583

# Submission time Handle Problem Language Result Execution time Memory
173583 2020-01-04T16:43:13 Z tourist Bank (IZhO14_bank) C++14
0 / 100
2 ms 380 KB
#include <iostream>
#include <vector>

using namespace std;

#define ll long long
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define endl "\n"
#define METH ios::sync_with_stdio(0); cin.tie(0);
#define BEGIN cout << "BEGIN" << endl;
#define END cout << "END" << endl;

const int mod = 1e9 + 7;															/// ANOTHER HASH MOD: 228228227
const int prime = 29;																	/// ANOTHER HASH PRIME: 997
const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8);

short n, m;
vector < short > a, b;
bool dp[21][1 << 20];

inline void read() {
	scanf("%d %d", &n, &m);
	a.resize(n);
	b.resize(m);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d", &b[i]);
	}
}

void calc(int used, short cur, short sum) {
	if (dp[cur][used]) {
		return;
	}
	if (cur == n) {
		cout << "YES" << endl;
		exit(0);
	}
	if (sum == a[cur]) {
		calc(used, cur + 1, 0);
		return;
	}
	if (used == (1 << m) - 1) {
		return;
	}
	for (int i = 0; i < m; i++) {
		if (used >> i & 1) {
			continue;
		}
		calc(used | (1 << i), cur, sum + b[i]);
	}
	dp[cur][used] = 1;
}

inline int solve() {
	calc(0, 0, 0);
	cout << "NO" << endl;
}

int main() {
	int t = 1;
	while (t--) {
		read();
		solve();
	}
}

Compilation message

bank.cpp: In function 'void read()':
bank.cpp:23:23: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'short int*' [-Wformat=]
  scanf("%d %d", &n, &m);
                 ~~    ^
bank.cpp:23:23: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'short int*' [-Wformat=]
bank.cpp:27:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<short int> >::value_type* {aka short int*}' [-Wformat=]
   scanf("%d", &a[i]);
                    ^
bank.cpp:30:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<short int> >::value_type* {aka short int*}' [-Wformat=]
   scanf("%d", &b[i]);
                    ^
bank.cpp: In function 'int solve()':
bank.cpp:61:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
bank.cpp: In function 'void read()':
bank.cpp:23: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:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
bank.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &b[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -