제출 #681911

#제출 시각아이디문제언어결과실행 시간메모리
681911asteilind은행 (IZhO14_bank)C++17
100 / 100
137 ms8652 KiB
#include <iostream> #include <vector> #include <queue> #include <string> #include <stack> #include <unordered_map> #include <map> #include <unordered_set> #include <cmath> #include <algorithm> #include <sstream> #include <set> #include <numeric> #include <bitset> #include <climits> #define forn(i, n) for (int i = 0; i < int(n); i++) #define ll long long //#define MOD 1000000007 using namespace std; void setIO(string name = "") { // name is nonempty for USACO file I/O ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output if(name.length()){ freopen((name+".in").c_str(), "r", stdin); // see Input & Output freopen((name+".out").c_str(), "w", stdout); } } bool solve() { int n,m; cin >> n >> m; vector<int> cash(n); forn(i,n) cin >> cash[i]; vector<int> bn(m); forn(i,m) cin >> bn[i]; vector<int> dp((1<<m),0); vector<int> l_o((1<<m),0); for (int s=0 ; (1<<m)>s ; s++) { for (int i=0 ; m>i ; i++) { if ((s & (1 << i)) != 0 || dp[s | (1<<i)]-1 >= dp[s]) continue; int tot = l_o[s]+bn[i]; if (tot == cash[dp[s]]) { dp[s | (1 << i)] = dp[s]+1; if (dp[s]+1 == n) return true; l_o[s | (1 << i)] = 0; } else if(tot < cash[dp[s]]) { dp[s | (1 << i)] = dp[s]; l_o[s | (1 << i)] = tot; } } } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if (solve()) cout << "YES" << endl; else cout << "NO" << endl; }

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

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