Submission #69842

# Submission time Handle Problem Language Result Execution time Memory
69842 2018-08-21T15:34:28 Z chpipis Bali Sculptures (APIO15_sculpture) C++11
100 / 100
143 ms 1428 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int LOGV = 45;
const int MAXN = 2005;
const int INF = 1e9;

int n, a, b;
int dp[MAXN];
bool can[MAXN][MAXN];
ll p[MAXN];

bool check(ll mask) {
    if (n <= 100) {
        can[0][0] = true;
        for (int k = 1; k <= b; k++) {
            for (int i = 0; i <= n; i++) {
                can[k][i] = false;
                if (i < k)
                    continue;
                for (int j = 0; j < i; j++)
                    if ((mask | (p[i] - p[j])) == mask && can[k - 1][j])
                        can[k][i] = true;
            }
            if (k >= a && can[k][n])
                return true;
        }
        return false;
    } else {
        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            dp[i] = INF;
            for (int j = 0; j < i; j++)
                if ((mask | (p[i] - p[j])) == mask)
                    dp[i] = min(dp[i], dp[j] + 1);
        }
        return dp[n] >= a && dp[n] <= b;
    }
}

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    scanf("%d %d %d", &n, &a, &b);
    for (int i= 1; i <= n; i++) {
        int x; scanf("%d", &x);
        p[i] = p[i - 1] + x;
    }
    ll ans = (1LL << LOGV) - 1;
    for (int i = LOGV - 1; i >= 0; i--) {
        if (check(ans - (1LL << i)))
            ans -= 1LL << i;
    }
    printf("%lld\n", ans);
    return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:97:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &a, &b);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:99:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int x; scanf("%d", &x);
                ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 572 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 3 ms 588 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 3 ms 592 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 2 ms 632 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 632 KB Output is correct
15 Correct 2 ms 664 KB Output is correct
16 Correct 2 ms 796 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 796 KB Output is correct
19 Correct 3 ms 796 KB Output is correct
20 Correct 2 ms 796 KB Output is correct
21 Correct 3 ms 796 KB Output is correct
22 Correct 2 ms 796 KB Output is correct
23 Correct 2 ms 796 KB Output is correct
24 Correct 3 ms 796 KB Output is correct
25 Correct 2 ms 796 KB Output is correct
26 Correct 3 ms 796 KB Output is correct
27 Correct 3 ms 796 KB Output is correct
28 Correct 2 ms 796 KB Output is correct
29 Correct 2 ms 796 KB Output is correct
30 Correct 2 ms 796 KB Output is correct
31 Correct 3 ms 796 KB Output is correct
32 Correct 2 ms 800 KB Output is correct
33 Correct 3 ms 804 KB Output is correct
34 Correct 2 ms 808 KB Output is correct
35 Correct 2 ms 812 KB Output is correct
36 Correct 3 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 820 KB Output is correct
2 Correct 3 ms 820 KB Output is correct
3 Correct 2 ms 820 KB Output is correct
4 Correct 2 ms 820 KB Output is correct
5 Correct 2 ms 820 KB Output is correct
6 Correct 3 ms 820 KB Output is correct
7 Correct 3 ms 820 KB Output is correct
8 Correct 2 ms 820 KB Output is correct
9 Correct 2 ms 820 KB Output is correct
10 Correct 2 ms 820 KB Output is correct
11 Correct 2 ms 820 KB Output is correct
12 Correct 2 ms 820 KB Output is correct
13 Correct 2 ms 820 KB Output is correct
14 Correct 2 ms 820 KB Output is correct
15 Correct 2 ms 820 KB Output is correct
16 Correct 2 ms 824 KB Output is correct
17 Correct 2 ms 940 KB Output is correct
18 Correct 2 ms 940 KB Output is correct
19 Correct 2 ms 960 KB Output is correct
20 Correct 3 ms 960 KB Output is correct
21 Correct 3 ms 960 KB Output is correct
22 Correct 2 ms 960 KB Output is correct
23 Correct 2 ms 960 KB Output is correct
24 Correct 2 ms 960 KB Output is correct
25 Correct 2 ms 960 KB Output is correct
26 Correct 2 ms 960 KB Output is correct
27 Correct 2 ms 960 KB Output is correct
28 Correct 1 ms 960 KB Output is correct
29 Correct 3 ms 960 KB Output is correct
30 Correct 3 ms 960 KB Output is correct
31 Correct 3 ms 960 KB Output is correct
32 Correct 3 ms 960 KB Output is correct
33 Correct 3 ms 960 KB Output is correct
34 Correct 3 ms 960 KB Output is correct
35 Correct 4 ms 960 KB Output is correct
36 Correct 5 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 960 KB Output is correct
2 Correct 3 ms 960 KB Output is correct
3 Correct 2 ms 960 KB Output is correct
4 Correct 2 ms 960 KB Output is correct
5 Correct 2 ms 960 KB Output is correct
6 Correct 3 ms 960 KB Output is correct
7 Correct 3 ms 960 KB Output is correct
8 Correct 3 ms 960 KB Output is correct
9 Correct 2 ms 960 KB Output is correct
10 Correct 2 ms 960 KB Output is correct
11 Correct 2 ms 960 KB Output is correct
12 Correct 3 ms 960 KB Output is correct
13 Correct 2 ms 960 KB Output is correct
14 Correct 2 ms 960 KB Output is correct
15 Correct 2 ms 960 KB Output is correct
16 Correct 2 ms 960 KB Output is correct
17 Correct 3 ms 960 KB Output is correct
18 Correct 3 ms 960 KB Output is correct
19 Correct 3 ms 960 KB Output is correct
20 Correct 2 ms 960 KB Output is correct
21 Correct 3 ms 960 KB Output is correct
22 Correct 4 ms 960 KB Output is correct
23 Correct 3 ms 960 KB Output is correct
24 Correct 4 ms 960 KB Output is correct
25 Correct 3 ms 960 KB Output is correct
26 Correct 4 ms 960 KB Output is correct
27 Correct 6 ms 960 KB Output is correct
28 Correct 6 ms 1068 KB Output is correct
29 Correct 7 ms 1068 KB Output is correct
30 Correct 3 ms 1068 KB Output is correct
31 Correct 5 ms 1068 KB Output is correct
32 Correct 6 ms 1068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1068 KB Output is correct
2 Correct 2 ms 1068 KB Output is correct
3 Correct 2 ms 1068 KB Output is correct
4 Correct 2 ms 1068 KB Output is correct
5 Correct 2 ms 1068 KB Output is correct
6 Correct 2 ms 1068 KB Output is correct
7 Correct 2 ms 1068 KB Output is correct
8 Correct 3 ms 1068 KB Output is correct
9 Correct 3 ms 1068 KB Output is correct
10 Correct 2 ms 1068 KB Output is correct
11 Correct 2 ms 1068 KB Output is correct
12 Correct 2 ms 1068 KB Output is correct
13 Correct 2 ms 1068 KB Output is correct
14 Correct 2 ms 1068 KB Output is correct
15 Correct 3 ms 1068 KB Output is correct
16 Correct 3 ms 1068 KB Output is correct
17 Correct 3 ms 1068 KB Output is correct
18 Correct 3 ms 1068 KB Output is correct
19 Correct 3 ms 1068 KB Output is correct
20 Correct 3 ms 1068 KB Output is correct
21 Correct 3 ms 1068 KB Output is correct
22 Correct 2 ms 1068 KB Output is correct
23 Correct 4 ms 1068 KB Output is correct
24 Correct 2 ms 1068 KB Output is correct
25 Correct 3 ms 1068 KB Output is correct
26 Correct 3 ms 1068 KB Output is correct
27 Correct 3 ms 1068 KB Output is correct
28 Correct 2 ms 1088 KB Output is correct
29 Correct 2 ms 1088 KB Output is correct
30 Correct 2 ms 1088 KB Output is correct
31 Correct 2 ms 1088 KB Output is correct
32 Correct 2 ms 1088 KB Output is correct
33 Correct 2 ms 1088 KB Output is correct
34 Correct 2 ms 1088 KB Output is correct
35 Correct 3 ms 1088 KB Output is correct
36 Correct 3 ms 1088 KB Output is correct
37 Correct 2 ms 1088 KB Output is correct
38 Correct 3 ms 1088 KB Output is correct
39 Correct 3 ms 1088 KB Output is correct
40 Correct 2 ms 1088 KB Output is correct
41 Correct 2 ms 1088 KB Output is correct
42 Correct 3 ms 1088 KB Output is correct
43 Correct 3 ms 1088 KB Output is correct
44 Correct 3 ms 1088 KB Output is correct
45 Correct 4 ms 1164 KB Output is correct
46 Correct 3 ms 1164 KB Output is correct
47 Correct 3 ms 1164 KB Output is correct
48 Correct 4 ms 1164 KB Output is correct
49 Correct 4 ms 1164 KB Output is correct
50 Correct 5 ms 1164 KB Output is correct
51 Correct 6 ms 1220 KB Output is correct
52 Correct 6 ms 1276 KB Output is correct
53 Correct 5 ms 1276 KB Output is correct
54 Correct 5 ms 1276 KB Output is correct
55 Correct 6 ms 1276 KB Output is correct
56 Correct 5 ms 1276 KB Output is correct
57 Correct 8 ms 1276 KB Output is correct
58 Correct 11 ms 1276 KB Output is correct
59 Correct 17 ms 1276 KB Output is correct
60 Correct 24 ms 1276 KB Output is correct
61 Correct 3 ms 1276 KB Output is correct
62 Correct 20 ms 1276 KB Output is correct
63 Correct 21 ms 1276 KB Output is correct
64 Correct 15 ms 1276 KB Output is correct
65 Correct 4 ms 1276 KB Output is correct
66 Correct 4 ms 1276 KB Output is correct
67 Correct 7 ms 1276 KB Output is correct
68 Correct 13 ms 1276 KB Output is correct
69 Correct 24 ms 1424 KB Output is correct
70 Correct 21 ms 1428 KB Output is correct
71 Correct 4 ms 1428 KB Output is correct
72 Correct 20 ms 1428 KB Output is correct
73 Correct 30 ms 1428 KB Output is correct
74 Correct 25 ms 1428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1428 KB Output is correct
2 Correct 2 ms 1428 KB Output is correct
3 Correct 3 ms 1428 KB Output is correct
4 Correct 2 ms 1428 KB Output is correct
5 Correct 2 ms 1428 KB Output is correct
6 Correct 2 ms 1428 KB Output is correct
7 Correct 2 ms 1428 KB Output is correct
8 Correct 3 ms 1428 KB Output is correct
9 Correct 2 ms 1428 KB Output is correct
10 Correct 2 ms 1428 KB Output is correct
11 Correct 3 ms 1428 KB Output is correct
12 Correct 2 ms 1428 KB Output is correct
13 Correct 2 ms 1428 KB Output is correct
14 Correct 2 ms 1428 KB Output is correct
15 Correct 2 ms 1428 KB Output is correct
16 Correct 2 ms 1428 KB Output is correct
17 Correct 2 ms 1428 KB Output is correct
18 Correct 3 ms 1428 KB Output is correct
19 Correct 2 ms 1428 KB Output is correct
20 Correct 3 ms 1428 KB Output is correct
21 Correct 3 ms 1428 KB Output is correct
22 Correct 2 ms 1428 KB Output is correct
23 Correct 2 ms 1428 KB Output is correct
24 Correct 2 ms 1428 KB Output is correct
25 Correct 2 ms 1428 KB Output is correct
26 Correct 3 ms 1428 KB Output is correct
27 Correct 2 ms 1428 KB Output is correct
28 Correct 2 ms 1428 KB Output is correct
29 Correct 3 ms 1428 KB Output is correct
30 Correct 3 ms 1428 KB Output is correct
31 Correct 3 ms 1428 KB Output is correct
32 Correct 3 ms 1428 KB Output is correct
33 Correct 5 ms 1428 KB Output is correct
34 Correct 3 ms 1428 KB Output is correct
35 Correct 3 ms 1428 KB Output is correct
36 Correct 4 ms 1428 KB Output is correct
37 Correct 5 ms 1428 KB Output is correct
38 Correct 6 ms 1428 KB Output is correct
39 Correct 6 ms 1428 KB Output is correct
40 Correct 3 ms 1428 KB Output is correct
41 Correct 6 ms 1428 KB Output is correct
42 Correct 6 ms 1428 KB Output is correct
43 Correct 5 ms 1428 KB Output is correct
44 Correct 6 ms 1428 KB Output is correct
45 Correct 12 ms 1428 KB Output is correct
46 Correct 17 ms 1428 KB Output is correct
47 Correct 19 ms 1428 KB Output is correct
48 Correct 3 ms 1428 KB Output is correct
49 Correct 19 ms 1428 KB Output is correct
50 Correct 21 ms 1428 KB Output is correct
51 Correct 3 ms 1428 KB Output is correct
52 Correct 13 ms 1428 KB Output is correct
53 Correct 20 ms 1428 KB Output is correct
54 Correct 41 ms 1428 KB Output is correct
55 Correct 35 ms 1428 KB Output is correct
56 Correct 121 ms 1428 KB Output is correct
57 Correct 118 ms 1428 KB Output is correct
58 Correct 114 ms 1428 KB Output is correct
59 Correct 114 ms 1428 KB Output is correct
60 Correct 143 ms 1428 KB Output is correct
61 Correct 3 ms 1428 KB Output is correct
62 Correct 22 ms 1428 KB Output is correct
63 Correct 38 ms 1428 KB Output is correct
64 Correct 31 ms 1428 KB Output is correct
65 Correct 58 ms 1428 KB Output is correct
66 Correct 98 ms 1428 KB Output is correct
67 Correct 117 ms 1428 KB Output is correct
68 Correct 123 ms 1428 KB Output is correct
69 Correct 124 ms 1428 KB Output is correct