이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+5;
bool check(vector<int> x,vector<int> y,int s,int k,vector<int> left,vector<int> right)
{
if(s < 0)return 0;
if(s == 0)
{
if(x.size() == 1)return 1;
int suma = 0;
for(int i = 0;i < x.size()/2;i++)suma += x[i];
vector<int> tp;
for(int i = 0;i < x.size()/2;i++)tp.push_back(x[i]);
if(check(tp,left,suma,0,vector<int>(),vector<int>()))
{
tp.clear();
suma = 0;
for(int i = x.size()/2;i < x.size();i++)suma += x[i];
for(int i = x.size()/2;i < x.size();i++)tp.push_back(x[i]);
if(check(tp,right,suma,0,vector<int>(),vector<int>()))return 1;
}
return 0;
}
for(int i = k;i < y.size();i++)
{
if(i > k && y[i] == y[i-1]){right.push_back(y[i]);continue;}
left.push_back(y[i]);
if(check(x,y,s-y[i],i+1,left,right))return 1;
left.pop_back();
right.push_back(y[i]);
}
return 0;
}
int n,m;
vector<int> v,a,b;
bool sum(int s,int k)
{
if(s < 0)return 0;
if(s == 0)
{
int suma = 0;
for(int i = 0;i < a.size()/2;i++)suma += a[i];
if(check(a,v,suma,0,vector<int>(),vector<int>()))return 1;
return 0;
}
for(int i = k;i < m;i++)
{
if(i > k && b[i] == b[i-1])continue;
v.push_back(b[i]);
if(sum(s-b[i],i+1))return 1;
v.pop_back();
}
return 0;
}
int main()
{
cin>>n>>m;
a.resize(n);
b.resize(m);
for(int i = 0;i < n;i++)cin>>a[i];
for(int i = 0;i < m;i++)cin>>b[i];
sort(a.begin(),a.end());
sort(b.begin(),b.end());
a.push_back(0);
int s = 0;
for(int i = 0;i < n;i++)s += a[i];
if(sum(s,0))cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool check(std::vector<int>, std::vector<int>, int, int, std::vector<int>, std::vector<int>)':
bank.cpp:13:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i = 0;i < x.size()/2;i++)suma += x[i];
| ~~^~~~~~~~~~~~
bank.cpp:15:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i = 0;i < x.size()/2;i++)tp.push_back(x[i]);
| ~~^~~~~~~~~~~~
bank.cpp:20:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i = x.size()/2;i < x.size();i++)suma += x[i];
| ~~^~~~~~~~~~
bank.cpp:21:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = x.size()/2;i < x.size();i++)tp.push_back(x[i]);
| ~~^~~~~~~~~~
bank.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(int i = k;i < y.size();i++)
| ~~^~~~~~~~~~
bank.cpp: In function 'bool sum(int, int)':
bank.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0;i < a.size()/2;i++)suma += a[i];
| ~~^~~~~~~~~~~~
# | 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... |