제출 #721572

#제출 시각아이디문제언어결과실행 시간메모리
721572ovidiush11은행 (IZhO14_bank)C++14
44 / 100
34 ms304 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e3+5; vector<int> v; int st[N] = {0}; bool check(vector<int> a,int k,int s) { if(s < 0)return 0; if(s == 0) { if(k == a.size())return 1; else return check(a,k+1,a[k+1]); } for(int i = 0;i < v.size();i++) { if(st[i])continue; st[i] = 1; if(check(a,k,s-v[i]))return 1; st[i] = 0; } return 0; } bool sum(vector<int> a,vector<int> b,int s,int k) { if(s < 0)return 0; if(s == 0)return check(a,0,a[0]); for(int i = k;i < b.size();i++) { if(i > k && b[i] == b[i-1])continue; v.push_back(b[i]); if(sum(a,b,s-b[i],i+1))return 1; v.pop_back(); } return 0; } int main() { int n,m; cin>>n>>m; vector<int> a(n),b(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()); int s = 0; for(int i = 0;i < n;i++)s += a[i]; if(sum(a,b,s,0))cout<<"YES"<<endl; else cout<<"NO"<<endl; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

bank.cpp: In function 'bool check(std::vector<int>, int, int)':
bank.cpp:14:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         if(k == a.size())return 1;
      |            ~~^~~~~~~~~~~
bank.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 0;i < v.size();i++)
      |                   ~~^~~~~~~~~~
bank.cpp: In function 'bool sum(std::vector<int>, std::vector<int>, int, int)':
bank.cpp:31:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = k;i < b.size();i++)
      |                   ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...