답안 #41394

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41394 2018-02-17T06:47:03 Z krauch Bali Sculptures (APIO15_sculpture) C++14
46 / 100
88 ms 1708 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair < int, int > PII;

#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define y1 kekek
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)

const ll ool = 1e18 + 9;
const int N = 2e3 + 6, oo = 1e9 + 9, base = 1e9 + 7;

int n, A, B, a[N], d[N][N], d2[55][22][555];
ll ans = ool;
bool bit[22];

void rec(int pos, int cnt) {
    if (cnt > B) return;
    if (pos == n + 1) {
        if (cnt < A) return;
        ll res = 0, sum = 0;
        forn(i, 1, n) {
            if (i > 1 && bit[i] != bit[i - 1]) {
                res |= sum;
                sum = 0;
            }
            sum += a[i];
        }
        res |= sum;

        ans = min(ans, res);
        return;
    }

    bit[pos] = 0;
    rec(pos + 1, cnt + (pos == 1 || bit[pos] != bit[pos - 1]));
    bit[pos] = 1;
    rec(pos + 1, cnt + (pos == 1 || bit[pos] != bit[pos - 1]));
}

int main() {
    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n >> A >> B;
    forn(i, 1, n) {
        cin >> a[i];
    }

    if (n <= 20) {
        rec(1, 0);
        cout << ans << "\n";
        return 0;
    }

    if (A > 1) {
        d2[0][0][0] = 1;
        forn(i, 1, n) {
            forn(j, 1, B) {
                int sum = 0;
                for1(k, i, 1) {
                    sum += a[k];
                    forn(l, 0, 500) {
                        d2[i][j][l | sum] |= d2[k - 1][j - 1][l];
                    }
                }
            }
        }
        int mn = oo;
        forn(i, A, B) {
            forn(j, 0, 500) {
                if (d2[n][i][j]) mn = min(mn, j);
            }
        }

        cout << mn << "\n";

        return 0;
    }

    forn(j, 0, 2000) d[0][j] = oo;
    d[0][0] = 0;

    forn(i, 1, n) {
        int sum = 0;
        forn(j, 0, 2000) d[i][j] = oo;
        for1(j, i, 1) {
            sum += a[j];
            forn(k, 0, 2000) {
                d[i][k | sum] = min(d[i][k | sum], d[j - 1][k] + 1);
            }
        }
    }

    int pos = 2000;
    forn(i, 0, 2000) {
        if (d[n][i] <= B) {
            pos = i;
            break;
        }
    }
    cout << pos << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 1 ms 428 KB Output is correct
6 Correct 4 ms 444 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 516 KB Output is correct
9 Correct 2 ms 516 KB Output is correct
10 Correct 2 ms 548 KB Output is correct
11 Correct 2 ms 548 KB Output is correct
12 Correct 2 ms 548 KB Output is correct
13 Correct 85 ms 600 KB Output is correct
14 Correct 2 ms 600 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 2 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 2 ms 600 KB Output is correct
21 Correct 9 ms 600 KB Output is correct
22 Correct 10 ms 600 KB Output is correct
23 Correct 9 ms 600 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 9 ms 600 KB Output is correct
26 Correct 76 ms 620 KB Output is correct
27 Correct 2 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 2 ms 620 KB Output is correct
30 Correct 2 ms 620 KB Output is correct
31 Correct 8 ms 620 KB Output is correct
32 Correct 2 ms 620 KB Output is correct
33 Correct 76 ms 620 KB Output is correct
34 Correct 82 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 84 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 2 ms 620 KB Output is correct
6 Correct 4 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 2 ms 620 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 83 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 2 ms 620 KB Output is correct
16 Correct 2 ms 620 KB Output is correct
17 Correct 1 ms 620 KB Output is correct
18 Correct 2 ms 620 KB Output is correct
19 Correct 2 ms 620 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 9 ms 620 KB Output is correct
22 Correct 9 ms 620 KB Output is correct
23 Correct 9 ms 620 KB Output is correct
24 Correct 1 ms 620 KB Output is correct
25 Correct 8 ms 620 KB Output is correct
26 Correct 76 ms 620 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 4 ms 748 KB Output is correct
29 Correct 4 ms 876 KB Output is correct
30 Correct 7 ms 876 KB Output is correct
31 Correct 6 ms 920 KB Output is correct
32 Correct 7 ms 1004 KB Output is correct
33 Correct 6 ms 1004 KB Output is correct
34 Correct 6 ms 1004 KB Output is correct
35 Correct 6 ms 1004 KB Output is correct
36 Correct 6 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 2 ms 1004 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 4 ms 1004 KB Output is correct
7 Correct 1 ms 1004 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 1004 KB Output is correct
12 Correct 2 ms 1004 KB Output is correct
13 Correct 82 ms 1004 KB Output is correct
14 Correct 4 ms 1004 KB Output is correct
15 Correct 3 ms 1004 KB Output is correct
16 Correct 4 ms 1004 KB Output is correct
17 Correct 5 ms 1004 KB Output is correct
18 Correct 6 ms 1004 KB Output is correct
19 Correct 7 ms 1004 KB Output is correct
20 Correct 6 ms 1004 KB Output is correct
21 Correct 6 ms 1004 KB Output is correct
22 Correct 7 ms 1004 KB Output is correct
23 Correct 6 ms 1108 KB Output is correct
24 Correct 6 ms 1108 KB Output is correct
25 Correct 9 ms 1132 KB Output is correct
26 Correct 13 ms 1260 KB Output is correct
27 Correct 19 ms 1260 KB Output is correct
28 Correct 24 ms 1388 KB Output is correct
29 Correct 18 ms 1392 KB Output is correct
30 Correct 19 ms 1392 KB Output is correct
31 Correct 19 ms 1392 KB Output is correct
32 Correct 20 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
3 Correct 1 ms 1492 KB Output is correct
4 Correct 2 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 4 ms 1492 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 2 ms 1492 KB Output is correct
9 Correct 2 ms 1492 KB Output is correct
10 Correct 2 ms 1492 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 2 ms 1492 KB Output is correct
13 Correct 88 ms 1492 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
15 Correct 2 ms 1492 KB Output is correct
16 Correct 1 ms 1492 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 1 ms 1492 KB Output is correct
19 Correct 2 ms 1492 KB Output is correct
20 Correct 1 ms 1492 KB Output is correct
21 Correct 9 ms 1492 KB Output is correct
22 Correct 9 ms 1492 KB Output is correct
23 Correct 8 ms 1492 KB Output is correct
24 Correct 2 ms 1492 KB Output is correct
25 Correct 11 ms 1492 KB Output is correct
26 Correct 80 ms 1492 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 2 ms 1492 KB Output is correct
29 Correct 2 ms 1492 KB Output is correct
30 Correct 1 ms 1492 KB Output is correct
31 Correct 11 ms 1492 KB Output is correct
32 Correct 1 ms 1492 KB Output is correct
33 Correct 72 ms 1492 KB Output is correct
34 Correct 80 ms 1492 KB Output is correct
35 Correct 1 ms 1492 KB Output is correct
36 Correct 85 ms 1492 KB Output is correct
37 Correct 2 ms 1492 KB Output is correct
38 Correct 3 ms 1492 KB Output is correct
39 Correct 4 ms 1492 KB Output is correct
40 Correct 5 ms 1492 KB Output is correct
41 Correct 6 ms 1492 KB Output is correct
42 Correct 7 ms 1492 KB Output is correct
43 Correct 6 ms 1492 KB Output is correct
44 Correct 9 ms 1492 KB Output is correct
45 Correct 6 ms 1492 KB Output is correct
46 Correct 7 ms 1492 KB Output is correct
47 Correct 6 ms 1492 KB Output is correct
48 Correct 9 ms 1492 KB Output is correct
49 Correct 18 ms 1492 KB Output is correct
50 Correct 16 ms 1492 KB Output is correct
51 Correct 19 ms 1492 KB Output is correct
52 Correct 18 ms 1492 KB Output is correct
53 Correct 18 ms 1492 KB Output is correct
54 Correct 19 ms 1492 KB Output is correct
55 Correct 19 ms 1492 KB Output is correct
56 Runtime error 3 ms 1492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
3 Correct 2 ms 1492 KB Output is correct
4 Correct 2 ms 1492 KB Output is correct
5 Correct 1 ms 1492 KB Output is correct
6 Correct 3 ms 1492 KB Output is correct
7 Correct 2 ms 1492 KB Output is correct
8 Correct 1 ms 1492 KB Output is correct
9 Correct 1 ms 1492 KB Output is correct
10 Correct 1 ms 1492 KB Output is correct
11 Correct 2 ms 1492 KB Output is correct
12 Correct 1 ms 1492 KB Output is correct
13 Correct 82 ms 1492 KB Output is correct
14 Correct 2 ms 1492 KB Output is correct
15 Correct 2 ms 1492 KB Output is correct
16 Correct 2 ms 1492 KB Output is correct
17 Correct 1 ms 1492 KB Output is correct
18 Correct 8 ms 1492 KB Output is correct
19 Correct 2 ms 1492 KB Output is correct
20 Correct 81 ms 1492 KB Output is correct
21 Correct 81 ms 1492 KB Output is correct
22 Correct 1 ms 1492 KB Output is correct
23 Correct 79 ms 1492 KB Output is correct
24 Correct 2 ms 1492 KB Output is correct
25 Correct 3 ms 1492 KB Output is correct
26 Correct 6 ms 1492 KB Output is correct
27 Correct 5 ms 1492 KB Output is correct
28 Correct 7 ms 1492 KB Output is correct
29 Correct 7 ms 1492 KB Output is correct
30 Correct 6 ms 1492 KB Output is correct
31 Correct 7 ms 1492 KB Output is correct
32 Correct 6 ms 1492 KB Output is correct
33 Correct 8 ms 1492 KB Output is correct
34 Correct 6 ms 1492 KB Output is correct
35 Correct 14 ms 1492 KB Output is correct
36 Correct 14 ms 1492 KB Output is correct
37 Correct 17 ms 1492 KB Output is correct
38 Correct 32 ms 1708 KB Output is correct
39 Correct 18 ms 1708 KB Output is correct
40 Correct 20 ms 1708 KB Output is correct
41 Correct 25 ms 1708 KB Output is correct
42 Correct 20 ms 1708 KB Output is correct
43 Runtime error 3 ms 1708 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Halted 0 ms 0 KB -