제출 #1039862

#제출 시각아이디문제언어결과실행 시간메모리
1039862lmaobruh은행 (IZhO14_bank)C++14
71 / 100
132 ms175700 KiB
// 027 072 207 270 702 720 #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(x) x.begin(), x.end() #define fo(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i) #define fod(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i) #define rep(i, n) fo(i, 1, n) #define per(i, n) fod(i, n, 1) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) const int N = 1e6+5; int n, m, a[N], b[N], dp[20][1<<20]; void sol() { cin >> n >> m; rep(i, n) cin >> a[i]; fo(i, 0, m-1) cin >> b[i]; memset(dp, -1, sizeof dp); dp[1][0] = 0; for (int i = 1; i <= n; ++i) for (int mask = 0; mask < (1<<m); ++mask) if (dp[i][mask] != -1) { for (int j = 0; j < m; ++j) if (!(mask>>j&1)) { if (dp[i][mask] + b[j] <= a[i]) { dp[i][mask^(1<<j)] = dp[i][mask] + b[j]; // if (mask == 4 && i == 1) dbg(j, b[j], dp[i][mask], mask^(1<<j), dp[i][mask]+b[j]); } if (dp[i][mask] == a[i] && b[j] <= a[i+1]) dp[i+1][mask^(1<<j)] = b[j]; } } for (int mask = 0; mask < (1<<m); ++mask) if (dp[n][mask] == a[n]) return cout << "YES\n", void(); cout << "NO\n"; } signed main() { cin.tie(0) -> sync_with_stdio(0); if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin); // else { // #define task "bank" // freopen(task".in", "r", stdin); // freopen(task".out", "w", stdout); // } int tc = 1, test = 0; // cin >> tc; while (++test <= tc) sol(); }

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

bank.cpp: In function 'int main()':
bank.cpp:43:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...