이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using tl = tuple<ll, ll, ll>;
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz(x) ll(x.size())
#define pb emplace_back
#define F first
#define S second
const ll inf = 1e17;
const ll mod = 1e9 + 7;
const ll N = 1e5*5+10;
const ll K = 300;
inline ll add(ll a, ll b){
if(a + b >= mod)
return a + b - mod;
return a + b;
}
void solve() {
ll n, m;
cin >> n >> m;
vector<ll> a(n), b(m);
for(auto &i : a)
cin >> i;
for(auto &i : b)
cin >> i;
vector<vector<bool>> dp(n+1, vector<bool> (1<<m));
ll pr = 0;
dp[0][0]=1;
bool yes = 0;
for(ll i = 0; i < n; i++){
pr += a[i];
for(ll mask = 0; mask < (1<<m); mask++){
if(dp[i][mask] == 0)continue;
ll sum = 0;
for(ll j = 0; j < m; j++)
sum+=((mask>>j)&1)*b[j];
if(sum == pr)
dp[i+1][mask] = 1, yes|=(i == n-1);
for(ll j = 0; j < m; j++){
if((mask>>j)&1)continue;
ll to = (mask|(1<<j));
dp[i][to] = 1;
}
}
}
cout << (yes ? "YES" : "NO") ;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1, i=1;
//cin >> t;
while (t--) {
//cout << "Case " << i++ << ":\n";
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'int main()':
bank.cpp:59:15: warning: unused variable 'i' [-Wunused-variable]
59 | ll t = 1, i=1;
| ^
# | 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... |