제출 #547952

#제출 시각아이디문제언어결과실행 시간메모리
547952mgl_diamond은행 (IZhO14_bank)C++14
52 / 100
1084 ms10980 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pd = pair<double, double>;

#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << "\n"
#define all(x) x.begin(), x.end()

template<class T> bool umax(T &a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool umin(T &a, T b) { if (a>b) { a=b; return 1; } return 0; }

void setIO(string name="") {
	ios_base::sync_with_stdio(0); cin.tie(0);
	if (name.size()) freopen((name+".inp").c_str(),"r",stdin);
	if (name.size()) freopen((name+".out").c_str(),"w",stdout);
}

int n, m;
vector<int> a, b;
vector<vector<int>> dp;
int f[2][1<<20];

int main() {
	setIO("");
	cin >> n >> m;
	a.resize(n); for(int &x: a) cin >> x;
	b.resize(m); for(int &x: b) cin >> x;

	///*
	dp.resize(1001, vector<int>());
	for(int i=0; i<1<<m; ++i) {
		int sum=0;
		for(int j=0; j<m; ++j) if (i>>j&1)
			sum+=b[j];
		if (sum<=1000) 
			dp[sum].push_back(i);
	}

	f[1][0]=1;
	for(int k=0; k<n; ++k) {
		bool cur=k&1;
		memset(f[cur], 0, sizeof(f[cur]));
		
		for(int i=0; i<1<<m; ++i)
			for(int j: dp[a[k]]) if ((j&i)==j)
				f[cur][i]+=f[1-cur][i-j];
	}

	for(int i=0; i<1<<m; ++i) if (f[(n-1)&1][i]>0) {
		cout << "YES\n";
		return 0;
	}

	cout << "NO\n";
}

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'void setIO(std::string)':
bank.cpp:17:26: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  if (name.size()) freopen((name+".inp").c_str(),"r",stdin);
      |                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:18:26: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  if (name.size()) freopen((name+".out").c_str(),"w",stdout);
      |                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...