답안 #41490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41490 2018-02-17T09:43:36 Z krauch Bali Sculptures (APIO15_sculpture) C++14
71 / 100
1000 ms 3052 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];

bool check(ll mask1, ll mask2, int pos) {
    mask1 >>= 1ll * pos;
    mask2 >>= 1ll * pos;
    return ((mask1 | mask2) == mask1);
}

bool calc(ll mask, int pos) {
    d[0][0] = 1;
    forn(i, 1, n) {
        forn(j, 1, B) {
            d[i][j] = 0;
            ll sum = 0;
            for1(k, i, 1) {
                sum += a[k];
//            if (pos == 35 && i == 1 && j == 1) cerr << mask << " " << sum << " " << check(mask, sum, pos) << "\n";
                if (!check(mask, sum, pos)) continue;
                d[i][j] |= d[k - 1][j - 1];
            }
        }
    }
    forn(i, A, B) {
        if (d[n][i]) return 1;
    }
    return 0;
}

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

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

    if (A) {
        ll ans = 0;
        for1(i, 41, 0) {
            ans |= (1ll << i);
            bool res = calc(ans, i);
            ans ^= (1ll << i);
            if (!res) ans |= (1ll << (i + 1));
        }
        if (!calc(ans, 0)) ans++;

        cout << ans << "\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 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 424 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 548 KB Output is correct
9 Correct 2 ms 548 KB Output is correct
10 Correct 2 ms 548 KB Output is correct
11 Correct 1 ms 548 KB Output is correct
12 Correct 2 ms 548 KB Output is correct
13 Correct 2 ms 548 KB Output is correct
14 Correct 1 ms 548 KB Output is correct
15 Correct 2 ms 548 KB Output is correct
16 Correct 2 ms 548 KB Output is correct
17 Correct 2 ms 548 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 620 KB Output is correct
21 Correct 2 ms 620 KB Output is correct
22 Correct 2 ms 656 KB Output is correct
23 Correct 3 ms 656 KB Output is correct
24 Correct 2 ms 656 KB Output is correct
25 Correct 2 ms 656 KB Output is correct
26 Correct 2 ms 656 KB Output is correct
27 Correct 2 ms 656 KB Output is correct
28 Correct 2 ms 656 KB Output is correct
29 Correct 2 ms 656 KB Output is correct
30 Correct 2 ms 656 KB Output is correct
31 Correct 2 ms 664 KB Output is correct
32 Correct 2 ms 664 KB Output is correct
33 Correct 2 ms 664 KB Output is correct
34 Correct 3 ms 664 KB Output is correct
35 Correct 2 ms 664 KB Output is correct
36 Correct 2 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 664 KB Output is correct
2 Correct 2 ms 664 KB Output is correct
3 Correct 2 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
8 Correct 2 ms 664 KB Output is correct
9 Correct 2 ms 664 KB Output is correct
10 Correct 2 ms 664 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 2 ms 664 KB Output is correct
14 Correct 2 ms 664 KB Output is correct
15 Correct 1 ms 664 KB Output is correct
16 Correct 1 ms 664 KB Output is correct
17 Correct 1 ms 664 KB Output is correct
18 Correct 2 ms 664 KB Output is correct
19 Correct 2 ms 664 KB Output is correct
20 Correct 2 ms 664 KB Output is correct
21 Correct 2 ms 664 KB Output is correct
22 Correct 2 ms 664 KB Output is correct
23 Correct 2 ms 664 KB Output is correct
24 Correct 2 ms 664 KB Output is correct
25 Correct 2 ms 664 KB Output is correct
26 Correct 2 ms 664 KB Output is correct
27 Correct 2 ms 692 KB Output is correct
28 Correct 2 ms 692 KB Output is correct
29 Correct 2 ms 764 KB Output is correct
30 Correct 4 ms 764 KB Output is correct
31 Correct 5 ms 764 KB Output is correct
32 Correct 5 ms 876 KB Output is correct
33 Correct 2 ms 876 KB Output is correct
34 Correct 5 ms 876 KB Output is correct
35 Correct 4 ms 876 KB Output is correct
36 Correct 4 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 876 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 2 ms 876 KB Output is correct
4 Correct 2 ms 876 KB Output is correct
5 Correct 2 ms 876 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 2 ms 876 KB Output is correct
13 Correct 2 ms 876 KB Output is correct
14 Correct 2 ms 876 KB Output is correct
15 Correct 2 ms 876 KB Output is correct
16 Correct 2 ms 876 KB Output is correct
17 Correct 3 ms 876 KB Output is correct
18 Correct 5 ms 876 KB Output is correct
19 Correct 5 ms 876 KB Output is correct
20 Correct 2 ms 876 KB Output is correct
21 Correct 5 ms 876 KB Output is correct
22 Correct 4 ms 876 KB Output is correct
23 Correct 3 ms 876 KB Output is correct
24 Correct 5 ms 876 KB Output is correct
25 Correct 4 ms 876 KB Output is correct
26 Correct 10 ms 876 KB Output is correct
27 Correct 29 ms 884 KB Output is correct
28 Correct 60 ms 1132 KB Output is correct
29 Correct 58 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 29 ms 1132 KB Output is correct
32 Correct 44 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
3 Correct 2 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 2 ms 1132 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 1 ms 1132 KB Output is correct
15 Correct 2 ms 1132 KB Output is correct
16 Correct 2 ms 1132 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 2 ms 1132 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1132 KB Output is correct
21 Correct 2 ms 1132 KB Output is correct
22 Correct 2 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 2 ms 1132 KB Output is correct
27 Correct 2 ms 1132 KB Output is correct
28 Correct 1 ms 1132 KB Output is correct
29 Correct 2 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 2 ms 1132 KB Output is correct
32 Correct 1 ms 1132 KB Output is correct
33 Correct 2 ms 1132 KB Output is correct
34 Correct 3 ms 1132 KB Output is correct
35 Correct 2 ms 1132 KB Output is correct
36 Correct 2 ms 1132 KB Output is correct
37 Correct 2 ms 1132 KB Output is correct
38 Correct 2 ms 1132 KB Output is correct
39 Correct 2 ms 1132 KB Output is correct
40 Correct 3 ms 1132 KB Output is correct
41 Correct 4 ms 1132 KB Output is correct
42 Correct 4 ms 1132 KB Output is correct
43 Correct 2 ms 1132 KB Output is correct
44 Correct 5 ms 1132 KB Output is correct
45 Correct 4 ms 1132 KB Output is correct
46 Correct 3 ms 1132 KB Output is correct
47 Correct 5 ms 1132 KB Output is correct
48 Correct 4 ms 1132 KB Output is correct
49 Correct 10 ms 1132 KB Output is correct
50 Correct 28 ms 1132 KB Output is correct
51 Correct 59 ms 1132 KB Output is correct
52 Correct 59 ms 1132 KB Output is correct
53 Correct 2 ms 1132 KB Output is correct
54 Correct 28 ms 1132 KB Output is correct
55 Correct 43 ms 1132 KB Output is correct
56 Correct 4 ms 1132 KB Output is correct
57 Correct 10 ms 1132 KB Output is correct
58 Correct 23 ms 1132 KB Output is correct
59 Correct 49 ms 1132 KB Output is correct
60 Correct 48 ms 1132 KB Output is correct
61 Correct 2 ms 1132 KB Output is correct
62 Correct 51 ms 1132 KB Output is correct
63 Correct 49 ms 1132 KB Output is correct
64 Correct 45 ms 1132 KB Output is correct
65 Correct 4 ms 1132 KB Output is correct
66 Correct 4 ms 1132 KB Output is correct
67 Correct 9 ms 1132 KB Output is correct
68 Correct 23 ms 1132 KB Output is correct
69 Correct 49 ms 1132 KB Output is correct
70 Correct 50 ms 1132 KB Output is correct
71 Correct 4 ms 1132 KB Output is correct
72 Correct 49 ms 1132 KB Output is correct
73 Correct 37 ms 1132 KB Output is correct
74 Correct 33 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1132 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
3 Correct 2 ms 1132 KB Output is correct
4 Correct 2 ms 1132 KB Output is correct
5 Correct 2 ms 1132 KB Output is correct
6 Correct 2 ms 1132 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 2 ms 1132 KB Output is correct
9 Correct 2 ms 1132 KB Output is correct
10 Correct 2 ms 1132 KB Output is correct
11 Correct 2 ms 1132 KB Output is correct
12 Correct 2 ms 1132 KB Output is correct
13 Correct 2 ms 1132 KB Output is correct
14 Correct 2 ms 1132 KB Output is correct
15 Correct 2 ms 1132 KB Output is correct
16 Correct 2 ms 1132 KB Output is correct
17 Correct 2 ms 1132 KB Output is correct
18 Correct 2 ms 1132 KB Output is correct
19 Correct 2 ms 1132 KB Output is correct
20 Correct 2 ms 1132 KB Output is correct
21 Correct 2 ms 1132 KB Output is correct
22 Correct 2 ms 1132 KB Output is correct
23 Correct 2 ms 1132 KB Output is correct
24 Correct 2 ms 1132 KB Output is correct
25 Correct 2 ms 1132 KB Output is correct
26 Correct 2 ms 1132 KB Output is correct
27 Correct 4 ms 1132 KB Output is correct
28 Correct 4 ms 1132 KB Output is correct
29 Correct 5 ms 1132 KB Output is correct
30 Correct 2 ms 1132 KB Output is correct
31 Correct 5 ms 1132 KB Output is correct
32 Correct 4 ms 1132 KB Output is correct
33 Correct 3 ms 1132 KB Output is correct
34 Correct 5 ms 1132 KB Output is correct
35 Correct 4 ms 1132 KB Output is correct
36 Correct 10 ms 1132 KB Output is correct
37 Correct 29 ms 1132 KB Output is correct
38 Correct 60 ms 1132 KB Output is correct
39 Correct 59 ms 1132 KB Output is correct
40 Correct 2 ms 1132 KB Output is correct
41 Correct 36 ms 1132 KB Output is correct
42 Correct 48 ms 1132 KB Output is correct
43 Correct 4 ms 1132 KB Output is correct
44 Correct 10 ms 1132 KB Output is correct
45 Correct 24 ms 1132 KB Output is correct
46 Correct 47 ms 1132 KB Output is correct
47 Correct 61 ms 1132 KB Output is correct
48 Correct 2 ms 1132 KB Output is correct
49 Correct 52 ms 1132 KB Output is correct
50 Correct 50 ms 1132 KB Output is correct
51 Correct 12 ms 1132 KB Output is correct
52 Execution timed out 1078 ms 3052 KB Time limit exceeded
53 Halted 0 ms 0 KB -