제출 #835274

#제출 시각아이디문제언어결과실행 시간메모리
835274Anthony_Liu은행 (IZhO14_bank)C++11
100 / 100
91 ms8540 KiB
#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC optimization ("unroll-loops")
#define f first
#define s second
#define ll long long
#define pb push_back
#define pi pair <int,int>
#define vi vector <int>
#define size(x) (int)(x).size()
#define all(x) x.begin(), x.end()
void setIO(string name = "") {
	cin.tie(0)->sync_with_stdio(0);
	if (size(name)) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

int N, M;
vi a, b;

int main()
{
	//setIO();
	cin >> N >> M;
	a.resize(N);
	b.resize(M);
	for (auto &ww : a) cin >> ww;
	for (auto &ww : b) cin >> ww;
	
	vector <pi> dp(1 << M, make_pair(INT_MAX, 0)); 
	//on '.f' th person, that person already paid '.s'
	dp[0] = {0, 0};
	
	for (int mask = 0; mask < (1 << M); mask++) {
		for (int i = 0; i < M; i++) {
			if (mask & (1 << i)) continue;
			int newmask = mask | (1 << i);
			
			int nf = dp[mask].f;
			if (nf == INT_MAX) continue;
			int ns = dp[mask].s + b[i];
			
			if (ns > a[nf]) continue;
			if (ns == a[nf]) {
				nf++;
				if (nf == N) {
					cout << "YES\n";
					return 0;
				}
				ns = 0;
			}
			
			if (make_pair(nf, ns) < dp[newmask]) 
				dp[newmask] = {nf, ns};
		}
	}
	
	cout << "NO\n";
	return 0;
}

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

bank.cpp: In function 'void setIO(std::string)':
bank.cpp:17:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   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...