Submission #925765

# Submission time Handle Problem Language Result Execution time Memory
925765 2024-02-12T08:33:38 Z Boycl07 Bali Sculptures (APIO15_sculpture) C++17
100 / 100
72 ms 600 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 1; i <= n; ++i)
#define forn(i, l, r) for(int i = l; i <= r; ++i)
#define ford(i, r, l) for(int i = r; i >= l; --i)
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define FORD(i, n) for(int i = n - 1; i >= 0; --i)
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define endl "\n"
#define task "sculptures"
#define sz(a) int(a.size())
#define C(x, y) make_pair(x, y)
#define all(a) (a).begin(), (a).end()
#define bit(i, mask) (mask >> i & 1)

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

inline int readInt()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();int n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline ll readLong()       {char c;while(c=getchar(),c!='-'&&(c<'0'||c>'9'));bool sign=(c=='-');if(sign)c=getchar();ll  n=c-'0';while(c=getchar(),c>='0'&&c<='9')n=10*n+c-'0';return(!sign)?n:-n;}
inline string readString() {char c;while(c=getchar(),c==' '||c=='\n'||c=='\t');string s({c});while(c=getchar(),c!=EOF&&c!=' '&&c!='\n'&&c!='\t')s+=c;return s;}


const int N =  1e5 + 10;
const int M = 1e3 + 3;
const int N1 = 2e3 + 10;
const int K = 1e2 + 1;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LINF = 1e17 + 2;
const int block_size = 500;
const int LOG = 40;
const int offset = N;
const int LIM = 11 ;
const int AL = 26;

int n, L, R;
int a[N];


bool check(ll res)
{
    if(n <= 100)
    {
        vector<vector<int>> dp(n + 1, vector<int>(n + 1));
        dp[0][0] = 1;
        rep(i, n)
        {

            forn(k, 1, n)
            {
                ll cur = 0;
                ford(j, i, 1)
                {
                    cur += a[j];
                    if((cur & res) == 0)
                        dp[i][k] |= dp[j - 1][k - 1];
                }
            }
        }
        forn(i, L, R) if(dp[n][i]) return 1;
        return 0;
    }
    else
    {
        vector<int> dp(n + 1);
        dp[0] = 0;
        rep(i, n)
        {
            dp[i] = n + 1;
            ll cur = 0;
            ford(j, i, 1)
            {
                cur += a[j];
                if((cur & res) == 0)
                    minimize(dp[i], dp[j - 1] + 1);
            }
        }
        return dp[n] <= R;
    }
}

void solve()
{
    cin >> n >> L >> R;
    rep(i, n) cin >> a[i];
    ll res = 0;

    for(int bit = LOG; bit >= 0; --bit)
    {
        res |= 1ll << bit;
        if(!check(res))
            res ^= 1ll << bit;
    }
    for(int bit = LOG; bit >= 0; --bit) res ^= 1ll << bit;
    cout << res;
}

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

    int TC = 1;

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


    while(TC--)
    {
        solve();
        cout << endl;
    }

    return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 464 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 360 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 456 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 548 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 5 ms 348 KB Output is correct
32 Correct 6 ms 348 KB Output is correct
33 Correct 4 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 5 ms 476 KB Output is correct
36 Correct 5 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 600 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 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 4 ms 348 KB Output is correct
19 Correct 5 ms 460 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 5 ms 348 KB Output is correct
22 Correct 5 ms 348 KB Output is correct
23 Correct 4 ms 348 KB Output is correct
24 Correct 5 ms 348 KB Output is correct
25 Correct 10 ms 480 KB Output is correct
26 Correct 17 ms 348 KB Output is correct
27 Correct 27 ms 492 KB Output is correct
28 Correct 36 ms 512 KB Output is correct
29 Correct 36 ms 348 KB Output is correct
30 Correct 36 ms 348 KB Output is correct
31 Correct 38 ms 592 KB Output is correct
32 Correct 36 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 464 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 464 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 4 ms 480 KB Output is correct
42 Correct 5 ms 356 KB Output is correct
43 Correct 5 ms 344 KB Output is correct
44 Correct 4 ms 348 KB Output is correct
45 Correct 5 ms 472 KB Output is correct
46 Correct 5 ms 480 KB Output is correct
47 Correct 5 ms 348 KB Output is correct
48 Correct 10 ms 348 KB Output is correct
49 Correct 17 ms 496 KB Output is correct
50 Correct 27 ms 348 KB Output is correct
51 Correct 36 ms 348 KB Output is correct
52 Correct 36 ms 348 KB Output is correct
53 Correct 37 ms 512 KB Output is correct
54 Correct 36 ms 348 KB Output is correct
55 Correct 36 ms 344 KB Output is correct
56 Correct 4 ms 468 KB Output is correct
57 Correct 12 ms 492 KB Output is correct
58 Correct 19 ms 348 KB Output is correct
59 Correct 25 ms 344 KB Output is correct
60 Correct 25 ms 344 KB Output is correct
61 Correct 27 ms 508 KB Output is correct
62 Correct 26 ms 348 KB Output is correct
63 Correct 26 ms 344 KB Output is correct
64 Correct 28 ms 344 KB Output is correct
65 Correct 4 ms 344 KB Output is correct
66 Correct 8 ms 344 KB Output is correct
67 Correct 12 ms 348 KB Output is correct
68 Correct 19 ms 500 KB Output is correct
69 Correct 25 ms 344 KB Output is correct
70 Correct 25 ms 504 KB Output is correct
71 Correct 26 ms 508 KB Output is correct
72 Correct 26 ms 344 KB Output is correct
73 Correct 27 ms 348 KB Output is correct
74 Correct 27 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 348 KB Output is correct
28 Correct 4 ms 348 KB Output is correct
29 Correct 5 ms 348 KB Output is correct
30 Correct 4 ms 472 KB Output is correct
31 Correct 5 ms 348 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
33 Correct 5 ms 348 KB Output is correct
34 Correct 5 ms 348 KB Output is correct
35 Correct 10 ms 348 KB Output is correct
36 Correct 17 ms 488 KB Output is correct
37 Correct 31 ms 488 KB Output is correct
38 Correct 37 ms 480 KB Output is correct
39 Correct 36 ms 484 KB Output is correct
40 Correct 36 ms 348 KB Output is correct
41 Correct 36 ms 344 KB Output is correct
42 Correct 36 ms 344 KB Output is correct
43 Correct 4 ms 348 KB Output is correct
44 Correct 12 ms 484 KB Output is correct
45 Correct 19 ms 348 KB Output is correct
46 Correct 25 ms 348 KB Output is correct
47 Correct 24 ms 348 KB Output is correct
48 Correct 25 ms 348 KB Output is correct
49 Correct 26 ms 348 KB Output is correct
50 Correct 26 ms 548 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 5 ms 476 KB Output is correct
53 Correct 8 ms 348 KB Output is correct
54 Correct 16 ms 344 KB Output is correct
55 Correct 14 ms 484 KB Output is correct
56 Correct 72 ms 348 KB Output is correct
57 Correct 53 ms 344 KB Output is correct
58 Correct 55 ms 476 KB Output is correct
59 Correct 53 ms 344 KB Output is correct
60 Correct 57 ms 344 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 8 ms 476 KB Output is correct
63 Correct 17 ms 348 KB Output is correct
64 Correct 14 ms 492 KB Output is correct
65 Correct 27 ms 480 KB Output is correct
66 Correct 40 ms 348 KB Output is correct
67 Correct 53 ms 344 KB Output is correct
68 Correct 58 ms 348 KB Output is correct
69 Correct 59 ms 348 KB Output is correct