Submission #242490

# Submission time Handle Problem Language Result Execution time Memory
242490 2020-06-27T20:54:49 Z ant101 Kas (COCI17_kas) C++14
100 / 100
347 ms 3584 KB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

typedef long long ll;


ll add(ll a, ll b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}

ll mul(ll a, ll b) {
    return (a * b)%MOD;
}

void add_self(ll& a, ll b) {
    a = add(a, b);
}
void sub_self(ll& a, ll b) {
    a = sub(a, b);
}
void mul_self(ll& a, ll b) {
    a = mul(a, b);
}


const ll MAXN = 200020; // change this after sliding window implemented
const ll offset = 100010; // and this

ll N;
ll hansIsAWeeb[2][MAXN];
ll coins[510];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    ll ret = 0;
    for (ll i = 0; i<N; i++) {
        cin >> coins[i];
        ret+=coins[i];
    }
    hansIsAWeeb[0][offset] = 0;
    for (ll i = 0; i<2; i++) {
        for (ll j = 0; j<MAXN; j++) {
            hansIsAWeeb[i][j] = 1e13;
        }
    }
    hansIsAWeeb[0][offset] = 0;
    for (ll i = 0; i<N; i++) {
        for (ll j = 0; j<MAXN; j++) {
            if (hansIsAWeeb[0][j] == 1e13) {
                continue;
            }
            ll delta = j-offset;
            hansIsAWeeb[1][delta-coins[i]+offset] = min(hansIsAWeeb[1][delta-coins[i]+offset], hansIsAWeeb[0][j]);
            hansIsAWeeb[1][delta+coins[i]+offset] = min(hansIsAWeeb[1][delta+coins[i]+offset], hansIsAWeeb[0][j]);
            hansIsAWeeb[1][delta+offset] = min(hansIsAWeeb[1][delta+offset], hansIsAWeeb[0][j]+coins[i]);
        }
        for (ll j = 0; j<MAXN; j++) {
            hansIsAWeeb[0][j] = hansIsAWeeb[1][j];
            hansIsAWeeb[1][j] = 1e13;
        }
    }
    cout << (ret-hansIsAWeeb[0][offset])/2 + hansIsAWeeb[0][offset] << "\n";
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 10 ms 3456 KB Output is correct
2 Correct 11 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 3456 KB Output is correct
2 Correct 11 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3584 KB Output is correct
2 Correct 11 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3456 KB Output is correct
2 Correct 11 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3488 KB Output is correct
2 Correct 11 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3456 KB Output is correct
2 Correct 25 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 3456 KB Output is correct
2 Correct 26 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 3576 KB Output is correct
2 Correct 121 ms 3516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 3456 KB Output is correct
2 Correct 205 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 3456 KB Output is correct
2 Correct 347 ms 3456 KB Output is correct