Submission #698117

#TimeUsernameProblemLanguageResultExecution timeMemory
698117ToroTNBank (IZhO14_bank)C++14
100 / 100
85 ms9036 KiB
#include<bits/stdc++.h> using namespace std; #define X first #define Y second int n,m,a[25],b[25],pre; pair<int,int> dp[1100005]; int main() { ios_base::sync_with_stdio(0),cin.tie(0); for(int i=0;i<=1100005;i++) { dp[i]={-1e9,-1e9}; } dp[0]={0,0}; cin >> n >> m; for(int i=1;i<=n;i++)cin >> a[i]; for(int i=1;i<=m;i++)cin >> b[i-1]; for(int i=0;i<(1<<m);i++) { for(int j=0;j<m;j++) { if((i&(1<<j))==0)continue; pre=(i^(1<<j)); if(dp[pre].Y+b[j]==a[dp[pre].X+1]) { if(dp[pre].X+1>dp[i].X) { dp[i]={dp[pre].X+1,0}; } }else { if(dp[pre].X>dp[i].X) { dp[i]={dp[pre].X,dp[pre].Y+b[j]}; } } } } // for(int i=0;i<(1<<m);i++) // { // printf("%d %d %d\n",i,dp[i].X,dp[i].Y); // } if(dp[(1<<m)-1].X==n) { printf("YES\n"); }else { printf("NO\n"); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...