이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define ii pair<int, int>
#define lol unsigned long long
#define lll __int128_t
#define fi first
#define se second
#define fou(i, a, b) for (int i = a; i <= b; ++i)
#define all(v) (v).begin(), (v).end()
#define MAX_N 10000000
#define el '\n'
#define BIT(mask, j) ((mask >> j) & 1)
#define MASK(X) (1LL << x)
typedef unsigned long long ll;
const int mxN = 1e4 + 9;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)4e18 + 7LL;
const int dx[] = {0, 1, 0, -1, 3, 0, -3, 0, 2, 2, -2, -2, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 0, 3, 0, -3, 1, -1, 1, -1, 2, -2, 2, -2} ;
int a[mxN], b[mxN];
int dp[mxN], ans[mxN];
int32_t main() {
if (fopen("bank.in", "r")) {
freopen("bank.in" ,"r", stdin);
freopen("bank.out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin >> n >> m;
map<int, int> mp;
fou(i, 1, n) cin >> a[i];
fou(i, 1, m) {
cin >> b[i];
mp[b[i]]++;
}
bool kt = true;
fou(i, 1, n) {
memset(dp, 0, sizeof dp);
dp[0] = 1;
fou(j, 1, m) {
for (int k = a[i]; k >= b[j]; --k) {
if (dp[k] == 0 && dp[k - b[j]] == 1) {
dp[k] = 1; ans[k] = k - b[j];
}
}
}
int j = a[i];
bool ok = true;
while(j > 0) {
if (mp[j - ans[j]] == 0) {
ok = false; break;
}
mp[j - ans[j]]--;
j = ans[j];
}
if (!ok) {
kt = false;
// cout << i <<" ";
break;
}
}
if (kt) cout << "YES";
else cout <<"NO";
return 0 ;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'int32_t main()':
bank.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | freopen("bank.in" ,"r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
bank.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | freopen("bank.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |