제출 #884905

#제출 시각아이디문제언어결과실행 시간메모리
884905xuvxuv은행 (IZhO14_bank)C++14
100 / 100
158 ms16988 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,a,b) for(auto i=a;i<b;i++) #define all(x) x.begin(),x.end() #define vpii vector<pair<int,int>> typedef pair<int,int> pii; typedef vector<int> vi; typedef map<int,int> mii; const int Prime1= 1000000007; const int Prime2= 998244353; long long binpow(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1){ res = res * a % m;} a = a * a % m; b >>= 1; } return res; } vector<int> hp(int n){ vector<int>h(n,0) ; for(int i=2;i<n;i++){ h[i]=i; } for( int i=2;i*i<n;i++){ if(h[i]==i){ for(int j=i;j<n;j+=i){ h[j]=i; } } } return h; } int n,m; int a[21]; int b[21]; int tar; vi v; int dp[1<<21]; bool f(int mask){ int val=0; if(dp[mask]!=-1)return dp[mask]; for(int i=0;i<m;i++){ if(mask&(1<<i)){ val+=b[i]; } } if(val==tar)return 1; auto it = upper_bound(all(v),val); int req= *it-val; bool ans=0; for(int i=0;i<m;i++){ if((mask&(1<<i))==0){ if(b[i]<=req){ ans|=f(mask|(1<<i)); } } } return dp[mask]= ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>m; tar=0; v.clear(); memset(dp,-1,sizeof(dp)); for(int i=0;i<n;i++){ cin>>a[i]; tar+=a[i]; if(i==0){ v.push_back(a[i]); } else { v.push_back(a[i]+v.back()); } } for(int i=0;i<m;i++){ cin>>b[i]; } bool ans= f(0); if(ans){ cout<<"YES\n"; } else { cout<<"NO\n"; } return 0; }

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

bank.cpp: In function 'bool f(long long int)':
bank.cpp:68:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   68 |     return dp[mask]= ans;
      |            ~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...