답안 #1101099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101099 2024-10-15T13:54:31 Z Zero_OP Bali Sculptures (APIO15_sculpture) C++14
100 / 100
95 ms 600 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i)
#define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)
#define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i)
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define sz(v) (int)v.size()
#define dbg(x) "[" #x " = " << (x) << "]"

template<typename T>
bool minimize(T& a, const T& b){
    if(a > b) return a = b, true; return false;
}

template<typename T>
bool maximize(T& a, const T& b){
    if(a < b) return a = b, true; return false;
}

using ll = long long;
using ld = long double;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); }
template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); }

const int MAX = 2e3 + 5;

int n, A, B, a[MAX];
ll pref[MAX];

ll sum(int l, int r){
    return pref[r] - pref[l - 1];
}

namespace subtask4{
    bool dp[105][105];
    void solve(){
        ll ans = (1LL << 60) - 1;
        for(int bit = 59; bit >= 0; --bit){
            ans ^= (1LL << bit); //try to erase largest bit

            memset(dp, false, sizeof(dp));
            dp[0][0] = true;
            for(int s = 1; s <= B; ++s){
                for(int i = 1; i <= n; ++i){
                    for(int j = 1; j <= i; ++j){
                        if((sum(j, i) | ans) == ans){
                            dp[s][i] |= dp[s - 1][j - 1];
                        }
                    }
                }
            }

            bool ok = false;
            for(int s = A; s <= B; ++s){
                ok |= dp[s][n];
            }

            if(!ok) ans ^= (1LL << bit); //cant
        }

        cout << ans << '\n';
    }
}

namespace subtask5{
    int dp[MAX];
    void solve(){
        ll ans = (1LL << 60) - 1;
        for(int bit = 59; bit >= 0; --bit){
            ans ^= (1LL << bit); //try to erase largest bit

            memset(dp, 0x3f, sizeof(dp));
            dp[0] = 0;
            for(int i = 1; i <= n; ++i){
                for(int j = 1; j <= i; ++j){
                    if((sum(j, i)| ans) == ans){
                        dp[i] = min(dp[i], dp[j - 1] + 1);
                    }
                }
            }

            if(dp[n] > B) ans ^= (1LL << bit); //cant
        }

        cout << ans << '\n';
    }
}

void testcase(){
    cin >> n >> A >> B;
    FOR(i, 1, n) cin >> a[i], pref[i] = pref[i - 1] + a[i];

    if(n <= 100)
        subtask4::solve();
    else
        subtask5::solve();
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    #define filename "task"
    if(fopen(filename".inp", "r")){
        freopen(filename".inp", "r", stdin);
        freopen(filename".out", "w", stdout);
    }

    int T = 1; //cin >> T;
    while(T--) testcase();

    return 0;
}

Compilation message

sculpture.cpp: In function 'bool minimize(T&, const T&)':
sculpture.cpp:15:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   15 |     if(a > b) return a = b, true; return false;
      |     ^~
sculpture.cpp:15:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   15 |     if(a > b) return a = b, true; return false;
      |                                   ^~~~~~
sculpture.cpp: In function 'bool maximize(T&, const T&)':
sculpture.cpp:20:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   20 |     if(a < b) return a = b, true; return false;
      |     ^~
sculpture.cpp:20:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   20 |     if(a < b) return a = b, true; return false;
      |                                   ^~~~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:110:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  110 |         freopen(filename".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:111:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |         freopen(filename".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 504 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 472 KB Output is correct
9 Correct 1 ms 424 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 352 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 1 ms 352 KB Output is correct
28 Correct 1 ms 352 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 504 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 1 ms 352 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 472 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 3 ms 484 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 520 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 3 ms 500 KB Output is correct
25 Correct 3 ms 352 KB Output is correct
26 Correct 7 ms 352 KB Output is correct
27 Correct 23 ms 504 KB Output is correct
28 Correct 47 ms 352 KB Output is correct
29 Correct 46 ms 352 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 22 ms 508 KB Output is correct
32 Correct 35 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 356 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 472 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 352 KB Output is correct
21 Correct 1 ms 352 KB Output is correct
22 Correct 1 ms 352 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 1 ms 352 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 504 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 428 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 3 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 3 ms 340 KB Output is correct
45 Correct 2 ms 488 KB Output is correct
46 Correct 2 ms 508 KB Output is correct
47 Correct 3 ms 388 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 7 ms 492 KB Output is correct
50 Correct 22 ms 340 KB Output is correct
51 Correct 48 ms 340 KB Output is correct
52 Correct 46 ms 480 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 22 ms 340 KB Output is correct
55 Correct 35 ms 340 KB Output is correct
56 Correct 3 ms 340 KB Output is correct
57 Correct 6 ms 492 KB Output is correct
58 Correct 17 ms 496 KB Output is correct
59 Correct 37 ms 340 KB Output is correct
60 Correct 35 ms 340 KB Output is correct
61 Correct 1 ms 464 KB Output is correct
62 Correct 38 ms 340 KB Output is correct
63 Correct 38 ms 340 KB Output is correct
64 Correct 35 ms 504 KB Output is correct
65 Correct 3 ms 340 KB Output is correct
66 Correct 2 ms 512 KB Output is correct
67 Correct 6 ms 512 KB Output is correct
68 Correct 17 ms 340 KB Output is correct
69 Correct 36 ms 340 KB Output is correct
70 Correct 35 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 37 ms 340 KB Output is correct
73 Correct 28 ms 340 KB Output is correct
74 Correct 25 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 516 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 504 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 588 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 1 ms 596 KB Output is correct
31 Correct 3 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 3 ms 340 KB Output is correct
35 Correct 3 ms 508 KB Output is correct
36 Correct 7 ms 340 KB Output is correct
37 Correct 21 ms 340 KB Output is correct
38 Correct 48 ms 504 KB Output is correct
39 Correct 47 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 22 ms 492 KB Output is correct
42 Correct 35 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 6 ms 340 KB Output is correct
45 Correct 17 ms 340 KB Output is correct
46 Correct 36 ms 340 KB Output is correct
47 Correct 35 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 39 ms 484 KB Output is correct
50 Correct 37 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 9 ms 496 KB Output is correct
53 Correct 13 ms 504 KB Output is correct
54 Correct 25 ms 340 KB Output is correct
55 Correct 24 ms 504 KB Output is correct
56 Correct 92 ms 340 KB Output is correct
57 Correct 91 ms 340 KB Output is correct
58 Correct 91 ms 340 KB Output is correct
59 Correct 89 ms 508 KB Output is correct
60 Correct 94 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 14 ms 340 KB Output is correct
63 Correct 27 ms 508 KB Output is correct
64 Correct 31 ms 508 KB Output is correct
65 Correct 45 ms 508 KB Output is correct
66 Correct 68 ms 504 KB Output is correct
67 Correct 94 ms 504 KB Output is correct
68 Correct 95 ms 508 KB Output is correct
69 Correct 90 ms 516 KB Output is correct