Submission #245381

# Submission time Handle Problem Language Result Execution time Memory
245381 2020-07-06T08:17:14 Z kartel Kas (COCI17_kas) C++14
60 / 100
2000 ms 760 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#define F first
#define S second
#define pb push_back
#define N +100500
#define M ll(1e9 + 7)
#define sz(x) (int)x.size()
#define re return
#define oo ll(1e9)
#define el '\n'
//#define el endl
#define pii pair <int, int>
#define err ld(1e-9)
#define last(x) x.back()
#define all(x) (x).begin(), (x).end()
#define arr_all(x, n) (x + 1), (x + 1 + n)
using namespace std;
//using namespace __gnu_pbds;
//typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;

int sum, fsum, nsum, i, f[N][2], F[N], a[N], n, ans;
bool mrk[N];

int main()
{
    srand(time(0));
    ios_base::sync_with_stdio(0);
    iostream::sync_with_stdio(0);
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
//
//    in("input.txt");
//    out("output.txt");

    cin >> n;
    for (i = 1; i <= n; i++) cin >> a[i], fsum += a[i];

    for (sum = 0; sum <= 1000; sum++) f[sum][0] = -1;
    f[0][0] = 1;
    f[0][1] = -1;

    for (sum = 0; sum <= fsum; sum++)
    {
        if (f[sum][0] == -1) continue;

        for (i = 1; i <= n; i++) mrk[i] = 0;

        nsum = sum;
        while (nsum != -1)
        {
            mrk[f[nsum][0] - 1] = 1;
            nsum = f[nsum][1];
        }

        for (i = f[sum][0]; i <= n; i++)
        {
            if (f[sum + a[i]][0] == -1)
                 f[sum + a[i]][0] = i + 1, f[sum + a[i]][1] = sum;
            else if (f[sum + a[i]][0] > i + 1)
                 f[sum + a[i]][0] = i + 1, f[sum + a[i]][1] = sum;
        }

        for (nsum = 0; nsum <= 1000; nsum++) F[nsum] = -1;

        F[0] = 1;

        for (nsum = 0; nsum <= sum; nsum++)
        {
            if (F[nsum] == -1) continue;

//            if (sum == 94)
//                cerr << nsum << " " << F[nsum] << el;

            for (i = F[nsum]; i <= n; i++)
            {
                if (mrk[i]) continue;

                if (F[nsum + a[i]] == -1)
                     F[nsum + a[i]] = i + 1;
                else F[nsum + a[i]] = min(i + 1, F[nsum + a[i]]);
            }
        }
//        for (i = 1; i <= n; i++) cerr << mrk[i] << " ";
//        cerr << el;
//
//        cerr << sum << " " << F[sum] << el;

        if (F[sum] != -1) ans = max(ans, sum);
    }

    cout << fsum - ans;
}

//
//00000
//00110
//00111
//00011
//00000
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2067 ms 512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2096 ms 428 KB Time limit exceeded
2 Halted 0 ms 0 KB -