This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std ;
const int N = 1e3 + 7 ;
int n ;
int a[N] ;
int sum ;
bool dp[52][N][N] ;
bool vis[52][N][N] ;
bool solve(int i , int kna1 ,int kna2){
if(kna1 < 0 || kna2 < 0)return 0 ;
if(vis[i][kna1][kna2])return dp[i][kna1][kna2] ;
vis[i][kna1][kna2] = 1 ;
if(i==n){
return dp[i][kna1][kna2] = (!kna1 && !kna2) ;
}
bool ret = 0 ;
ret|=solve(i+1 , kna1 - a[i] , kna2) ;
ret|=solve(i+1 , kna1 , kna2-a[i]) ;
ret|=solve(i+1 , kna1 , kna2) ;
return dp[i][kna1][kna2] = ret ;
}
int main(){
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
//freopen("in.in" ,"r" , stdin) ;
cin>>n ;
for(int i = 0 ;i < n;i++){
cin>>a[i];
sum+=a[i] ;
}
for(int i = 0 ;i <=sum ;i++){
if( (sum - i)%2 )
continue ;
if(solve(0 , i , (sum - i)/2 ))
return cout<<i + (sum-i)/2 , 0;
}
return 0 ;
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |