이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define double long double
#define order_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
///* __ __ __ */
///* ====== _ /| /| __ _ / | | /| | @ | | | | / /| |\ | / | | @ | / */
///* \- || |_| |_ / |/ | | | |_ |- | |--| /-| | | \ \ |==| |- /=| | \ | | |--| | |- */
///* || | | |_ / | |__| _| |_ \__ | | / | |__ | __| | | | \ / | | \| \__ | | | | \ */
///*
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vi> vv;
const int N = 2e5+4, inf = 1e8, mod = 998244353;
void solve(){
int n, m;
cin >> n >> m;
int cnt = 0, us[m]{};
vi b(m);
map<int,int> mp;
for(int i = 0, x; i < n; i++){cin >> x;mp[x]++;}
for(int &i:b)cin >> i;
vector<pair<pii, int> > res;
for(int ms = 1; ms < (1<<m); ms++){
int sum = 0;for(int i = 0; i < m; i++)if((ms>>i)&1)sum+=b[i];
res.pb({{sum , __builtin_popcount(ms)}, ms});
}
sort(rall(res));
for(auto [uk, ms]:res){
int ok = 0, sum = uk.ff;
for(int i = 0; i < m; i++){
if((ms>>i)&1 && us[i])ok = 1;
}
//~ cout << sum << '\n';
if(ok)continue;
if(mp[sum] > 0){
mp[sum]--;
cnt++;
for(int i = 0; i < m; i++){
if((ms >> i)&1)us[i] = 1;
}
}
}
if(cnt == n)cout << "YES\n";
else cout << "NO\n";
}
main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int test = 1;
//~ cin >> test;
while(test--){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
65 | main(){
| ^~~~
# | 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... |