Submission #92435

# Submission time Handle Problem Language Result Execution time Memory
92435 2019-01-02T20:44:21 Z wolf Kas (COCI17_kas) C++14
0 / 100
2 ms 380 KB
#include <bits/stdc++.h>

using namespace std;

using vi = vector<int> ;
using ll = long long;

#define pb push_back
#define inf 0x3f3f3f3f
#define all(v) (v).begin() , (v).end()
#define ones(n) __builtin_popcount(n)

const int N = 505 , M = 1e5 + 5;
int n;
int arr[N] , memo[N][M];

int solve (int i , int d) {
    if (i == n)
        return d == M ? 0 : inf;
    int &ret = memo[i][d];
    if (~ret)
        return ret;
    return ret = min(min(solve(i + 1 , d - arr[i]) , solve(i + 1 , d + arr[i])) , solve(i + 1 , d) + arr[i]);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    int sum = 0;
    scanf("%d" , &n);
    for (int i = 0 ;i < n ;i++) {
        scanf("%d"  , arr + i);
        sum += arr[i];
    }

    int mnrem = solve(0 , M);
    int ans = (sum - mnrem) / 2 + mnrem;
    printf("%d\n" , ans);
}

Compilation message

kas.cpp: In function 'int main()':
kas.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("input.in", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kas.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d" , &n);
     ~~~~~^~~~~~~~~~~
kas.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d"  , arr + i);
         ~~~~~^~~~~~~~~~~~~~~~~
kas.cpp:20:25: warning: array subscript is above array bounds [-Warray-bounds]
     int &ret = memo[i][d];
                ~~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -