#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 |
1 |
Correct |
28 ms |
18048 KB |
Output is correct |
2 |
Correct |
20 ms |
18944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
16376 KB |
Output is correct |
2 |
Correct |
20 ms |
12544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
18944 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
22648 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4352 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
52376 KB |
Output is correct |
2 |
Correct |
103 ms |
72312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
76888 KB |
Output is correct |
2 |
Correct |
143 ms |
62712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
12 ms |
1536 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |