Submission #317487

# Submission time Handle Problem Language Result Execution time Memory
317487 2020-10-29T19:17:09 Z Return_0 Bali Sculptures (APIO15_sculpture) C++17
100 / 100
130 ms 4472 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("avx,avx2,fma")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#ifdef LOCAL
#define dbg(x) cout<< #x << " : " << x << endl
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1);
#else
#define dbg(x) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< x << endl, 0
#define cl const ll
#define fr first
#define sc second
#define mid ((l + r) / 2)
#define All(x) (x).begin(), (x).end()

const long long inf = 1e18;
cl mod = 1e9 + 7, MOD = 998244353;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out << '(' << a.first << ", " << a.second << ')';    }
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
    if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 2e3 + 7;

ll a [N], dp1 [N], n, A, B, ans;
bool dp2 [N][N];

bool check () {
    if (A == 1) {
        memset(dp1, 61, sizeof dp1);
		ll sum;
	    dp1[0] = 0;
	    for (ll i = 1; i <= n; i++) {
		    sum = 0;
            for (ll j = i; j; j--) {
			    sum += a[j];
			    if ((sum | ans) == ans) dp1[i] = min(dp1[j-1] + 1, dp1[i]);
	        }
	    }
	    
        return (dp1[n] <= B);
    }

    else {
        memset(dp2, false, sizeof dp2);
        ll sum;
        dp2[0][0] = true;
        
        for (ll j = 1; j <= B; j++) {
            for (ll i = 1; i <= n; i++) {
                sum = 0;
                for (ll k = i; k; k--) {
                    sum += a[k];
                    if ((sum | ans) == ans) dp2[i][j] |= dp2[k-1][j-1];
                }
            }
        }

        for (ll i = A; i <= B; i++) if (dp2[n][i])   return true;
        return false;
    }
}

int main ()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> n >> A >> B;
    input(1, n, a);

    ans = (1LL << 45) - 1LL;
    for (ll i = 44; ~i; i--) {
        ans ^= (1LL << i);
        if (!check())   ans ^= (1LL << i);
    }

    cout<< ans << endl;

    // cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}
/*
6 1 3
8 1 2 1 5 4

*/

Compilation message

sculpture.cpp: In function 'std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)':
sculpture.cpp:39:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   39 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |     ^~
sculpture.cpp:39:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   39 |     if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']';  }
      |                                    ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 9 ms 4224 KB Output is correct
15 Correct 10 ms 4224 KB Output is correct
16 Correct 10 ms 4224 KB Output is correct
17 Correct 9 ms 4224 KB Output is correct
18 Correct 10 ms 4224 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 9 ms 4224 KB Output is correct
21 Correct 10 ms 4224 KB Output is correct
22 Correct 10 ms 4352 KB Output is correct
23 Correct 10 ms 4224 KB Output is correct
24 Correct 10 ms 4224 KB Output is correct
25 Correct 10 ms 4352 KB Output is correct
26 Correct 10 ms 4224 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 10 ms 4224 KB Output is correct
15 Correct 10 ms 4352 KB Output is correct
16 Correct 9 ms 4224 KB Output is correct
17 Correct 10 ms 4352 KB Output is correct
18 Correct 9 ms 4224 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 9 ms 4224 KB Output is correct
21 Correct 10 ms 4224 KB Output is correct
22 Correct 10 ms 4224 KB Output is correct
23 Correct 10 ms 4224 KB Output is correct
24 Correct 9 ms 4224 KB Output is correct
25 Correct 10 ms 4352 KB Output is correct
26 Correct 10 ms 4256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 10 ms 4224 KB Output is correct
15 Correct 9 ms 4224 KB Output is correct
16 Correct 10 ms 4352 KB Output is correct
17 Correct 9 ms 4224 KB Output is correct
18 Correct 9 ms 4352 KB Output is correct
19 Correct 10 ms 4224 KB Output is correct
20 Correct 10 ms 4224 KB Output is correct
21 Correct 10 ms 4352 KB Output is correct
22 Correct 10 ms 4224 KB Output is correct
23 Correct 10 ms 4224 KB Output is correct
24 Correct 10 ms 4224 KB Output is correct
25 Correct 10 ms 4352 KB Output is correct
26 Correct 11 ms 4224 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 512 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Correct 50 ms 4344 KB Output is correct
65 Correct 15 ms 4224 KB Output is correct
66 Correct 15 ms 4352 KB Output is correct
67 Correct 21 ms 4224 KB Output is correct
68 Correct 28 ms 4224 KB Output is correct
69 Correct 50 ms 4224 KB Output is correct
70 Correct 44 ms 4224 KB Output is correct
71 Correct 10 ms 4224 KB Output is correct
72 Correct 52 ms 4224 KB Output is correct
73 Correct 39 ms 4224 KB Output is correct
74 Correct 37 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 384 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 12 ms 384 KB Output is correct
53 Correct 20 ms 384 KB Output is correct
54 Correct 36 ms 384 KB Output is correct
55 Correct 34 ms 384 KB Output is correct
56 Correct 126 ms 504 KB Output is correct
57 Correct 126 ms 384 KB Output is correct
58 Correct 122 ms 384 KB Output is correct
59 Correct 121 ms 504 KB Output is correct
60 Correct 130 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 20 ms 384 KB Output is correct
63 Correct 36 ms 384 KB Output is correct
64 Correct 37 ms 384 KB Output is correct
65 Correct 64 ms 504 KB Output is correct
66 Correct 94 ms 384 KB Output is correct
67 Correct 126 ms 384 KB Output is correct
68 Correct 124 ms 504 KB Output is correct
69 Correct 122 ms 384 KB Output is correct