Submission #227580

#TimeUsernameProblemLanguageResultExecution timeMemory
227580mohamedsobhi777Kas (COCI17_kas)C++14
70 / 100
177 ms76888 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...