이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define LL long long
#define st first
#define nd second
#define endl '\n'
using namespace std;
int vis[1<<20],n,mo,a[21],m[20],val[1<<20],x;
vector<int> v[20005],ans[21];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>mo;
for(int i=1;i<=n;++i) {
cin>>a[i];
a[i]+=a[i-1];
}
for(int i=0;i<mo;++i)
cin>>m[i];
for(int i=0;i<(1<<mo);++i) {
vis[i]=1;
for(int j=0;j<mo;++j)
if((1<<j)&i)
val[i]+=m[j];
v[val[i]].pb(i);
}
for(int i=1;i<=n;++i) {
for(int j=0;j<v[a[i]].size();++j) {
if(vis[v[a[i]][j]])
ans[i].pb(v[a[i]][j]);
}
memset(vis,0,sizeof vis);
queue<int> q;
for(int j=0;j<ans[i].size();++j) {
q.push(ans[i][j]);
vis[ans[i][j]]=1;
}
while(!q.empty()) {
x=q.front();
q.pop();
for(int j=0;j<mo;++j)
if(!(x&(1<<j))&&!vis[x|(1<<j)]) {
q.push(x|(1<<j));
vis[x|(1<<j)]=1;
}
}
}
if(ans[n].size()) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'int main()':
bank.cpp:33:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<v[a[i]].size();++j) {
~^~~~~~~~~~~~~~~
bank.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<ans[i].size();++j) {
~^~~~~~~~~~~~~~
# | 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... |