Submission #227579

# Submission time Handle Problem Language Result Execution time Memory
227579 2020-04-27T22:11:16 Z mohamedsobhi777 Kas (COCI17_kas) C++14
0 / 100
18 ms 2816 KB
#include<bits/stdc++.h>

using namespace std ; 

const int N = 1e2 + 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 Incorrect 6 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 1408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 2816 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 Incorrect 8 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 2304 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -