Submission #1085775

#TimeUsernameProblemLanguageResultExecution timeMemory
1085775Sunbae은행 (IZhO14_bank)C++17
71 / 100
1040 ms8604 KiB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int dp[1<<20], s[1<<20];
int a[20], b[20];
vector<int> M[20];
signed main(){
	int n, m; 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);
	int lim = 1<<m;
	for(int mk = 0; mk<lim; ++mk){
		for(int j = 0; j<m; ++j) s[mk] += (mk>>j&1) * b[j];
		dp[mk] |= (s[mk] == a[0]);
		for(int i = 1; i<n; ++i) if(s[mk] == a[i]) M[i].push_back(mk);
	} 	
	for(int i = 1; i<n; ++i){
		for(int mk = lim-1; mk>=0; --mk){
			dp[mk] = 0;
			for(int k : M[i]) if((mk & k) == k) dp[mk] |= dp[mk ^ k];
		}	
	}
	(*max_element(dp, dp+lim)) ? puts("YES") : puts("NO");
}

Compilation message (stderr)

bank.cpp: In function 'int main()':
bank.cpp:9:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |  int n, m; scanf("%d %d", &n, &m);
      |            ~~~~~^~~~~~~~~~~~~~~~~
bank.cpp:10:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  for(int i = 0; i<n; ++i) scanf("%d", a+i);
      |                           ~~~~~^~~~~~~~~~~
bank.cpp:11:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  for(int i = 0; i<m; ++i) scanf("%d", b+i);
      |                           ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...