Submission #5016

# Submission time Handle Problem Language Result Execution time Memory
5016 2014-01-27T15:46:35 Z tncks0121 Bank (IZhO14_bank) C++
0 / 100
3 ms 576 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;

int N, M, A[20], B[20];
bool S[20][1<<20];
bool Table[20][1<<20];

int main() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);

	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);

	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(A[i] == sum) S[i][state] = 1;
	}

	// Table[i][state]: A[1..i] 지불, 현재 state만큼의 수표 사용
	for(int state = 0; state < (1<<M); state++) Table[0][state] = S[0][state];
	for(int i = 1; i < N; i++) {
		for(int state = 0; state < (1<<M); state++) {
			for(int p = 0; p < (1<<M) && Table[i][state]; p++) {
				if(S[i][p] && ((p & state) == p) && Table[i-1][p^state]) Table[i][state] = 1;
			}
		}
	}

	for(int state = 0; state < (1<<M); state++) if(Table[N-1][state]) return puts("YES"), 0;
	puts("NO");
	return 0;
}

Compilation message

bank.cpp: In function 'int main()':
bank.cpp:36:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("input.txt", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:37:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("output.txt", "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:39: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:40:34: 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:41:34: 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 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -