Submission #861337

# Submission time Handle Problem Language Result Execution time Memory
861337 2023-10-16T03:08:07 Z onepunchac168 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
63 ms 604 KB
//------------------------------------\\
//   ------------------------------   \\
//  |  created by Dinh Manh Hung   |  \\
//  |      tht.onepunchac168       |  \\
//  |     THPT CHUYEN HA TINH      |  \\
//  |      HA TINH, VIET NAM       |  \\
//  |           Siuuu              |  \\
//   ------------------------------   \\
//------------------------------------\\

#include <bits/stdc++.h>
using namespace std;

#define            task     ""
#define       file(name)    if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define             ldb     long double
#define              pb     push_back
#define              eb     emplace_back
#define              fi     first
#define              se     second
#define           all(x)    begin(x),end(x)
#define       uniquev(v)    v.resize(unique(all(v))-v.begin())
#define       rep(i,a,b)    for (int i=a;i<=b;i++)
#define        cntbit(v)    __builtin_popcountll(v)
#define         gcd(a,b)    __gcd(a,b)
#define         lcm(a,b)    ((1LL*a*b)/__gcd(a,b))
#define          mask(x)    (1LL<<(x))
#define     readbit(x,i)    ((x>>i)&1)
#define             Yes     cout << "Yes"
#define             YES     cout << "YES"
#define              No     cout << "No"
#define              NO     cout << "NO"

typedef long long ll;
typedef pair <ll,ll> ii;
typedef pair <ll,ii> iii;
typedef pair <ii,ii> iiii;

ll dx[]= {1,-1,0,0,1,-1,1,-1};
ll dy[]= {0,0,-1,1,1,-1,-1,1};

const ldb PI = acos (-1);
//const ll mod=978846151;
//const ll base=29;
const ll mod=1e9+7;
const char nl = '\n';

inline int ReadInt()
{
    char co;
    for (co = getchar(); co < '0' || co > '9'; co = getchar());
    int xo = co - '0';
    for (co = getchar(); co >= '0' && co <= '9'; co = getchar())
        xo = (xo<<1) + (xo<<3) + co - '0';
    return xo;
}

void WriteInt(int xo)
{
    if (xo > 9)
        WriteInt(xo / 10);
    putchar(xo % 10 + '0');
}

// DEBUG
/*
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
*/

/* END OF TEMPLATE*/

// ================= Solution =================//


void onepunchac168();

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    file(task);
    int tests;
    tests=1;
    //cin>>tests;
    while (tests--)
    {
        onepunchac168();
    }
}

const int N=105;
ll n,A,B;
ll a[2005];
bool dp[N][N];
ll sum[2005];
bool check(ll mid)
{
    for (int i=0;i<=n;i++)
    {
        for (int j=0;j<=n;j++)
        {
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=n;j++)
        {
            for (int h=1;h<=i;h++)
            {
                if (dp[h-1][j-1]==1&&((sum[i]-sum[h-1])|mid)==mid)
                {
                    dp[i][j]=1;
                    break;
                }
            }
        }
    }
    for (int i=A;i<=B;i++)
    {
        if (dp[n][i]==1)
        {
            return true;
        }
    }
    return false;
}
const int M=2005;
ll f[M];

bool solve(ll mid)
{
    for (int i=0;i<=n;i++)
    {
        f[i]=1e18+5;
    }
    f[0]=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=i;j++)
        {
            if (((sum[i]-sum[j-1])|mid)==mid)
            {
                f[i]=min(f[i],f[j-1]+1);
            }
        }
    }
    if (f[n]<=B)
    {
        return true;
    }
    return false;
}
void onepunchac168()
{
    cin>>n>>A>>B;
    sum[0]=0;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    if (n<=100){
        ll res=0;
        for (int i=38;i>=0;i--)
        {
            ll cnt=0;
            if (i>=1)
            {
                cnt=mask(i)-1;
            }
            if (check(res+cnt)==true)
            {

            }
            else res+=mask(i);
        }
        cout<<res;
    }
    else
    {
        ll res=0;
        for (int i=41;i>=0;i--)
        {
            ll cnt=0;
            if (i>=1)
            {
                cnt=mask(i)-1;
            }
            if (solve(res+cnt)==true)
            {

            }
            else res+=mask(i);
        }
        cout<<res;
    }
}
// goodbye see ya

Compilation message

sculpture.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //------------------------------------\\
      | ^
sculpture.cpp: In function 'int main()':
sculpture.cpp:15:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 | #define       file(name)    if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:108:5: note: in expansion of macro 'file'
  108 |     file(task);
      |     ^~~~
sculpture.cpp:15:99: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 | #define       file(name)    if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:108:5: note: in expansion of macro 'file'
  108 |     file(task);
      |     ^~~~
# 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 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 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 0 ms 472 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 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 1 ms 348 KB Output is correct
6 Correct 0 ms 600 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 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 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 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 472 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 344 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 344 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 6 ms 480 KB Output is correct
27 Correct 9 ms 476 KB Output is correct
28 Correct 12 ms 348 KB Output is correct
29 Correct 14 ms 480 KB Output is correct
30 Correct 13 ms 348 KB Output is correct
31 Correct 12 ms 348 KB Output is correct
32 Correct 12 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 596 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 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 0 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 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 348 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 0 ms 348 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 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 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 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 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 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 2 ms 348 KB Output is correct
44 Correct 4 ms 348 KB Output is correct
45 Correct 2 ms 348 KB Output is correct
46 Correct 2 ms 348 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 6 ms 348 KB Output is correct
50 Correct 10 ms 348 KB Output is correct
51 Correct 12 ms 348 KB Output is correct
52 Correct 12 ms 480 KB Output is correct
53 Correct 12 ms 348 KB Output is correct
54 Correct 14 ms 480 KB Output is correct
55 Correct 14 ms 344 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 8 ms 484 KB Output is correct
58 Correct 16 ms 344 KB Output is correct
59 Correct 16 ms 348 KB Output is correct
60 Correct 16 ms 344 KB Output is correct
61 Correct 15 ms 348 KB Output is correct
62 Correct 15 ms 476 KB Output is correct
63 Correct 16 ms 600 KB Output is correct
64 Correct 9 ms 348 KB Output is correct
65 Correct 3 ms 348 KB Output is correct
66 Correct 5 ms 476 KB Output is correct
67 Correct 8 ms 348 KB Output is correct
68 Correct 13 ms 484 KB Output is correct
69 Correct 15 ms 348 KB Output is correct
70 Correct 16 ms 348 KB Output is correct
71 Correct 15 ms 484 KB Output is correct
72 Correct 18 ms 604 KB Output is correct
73 Correct 17 ms 344 KB Output is correct
74 Correct 17 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 416 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 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 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 4 ms 604 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 480 KB Output is correct
31 Correct 2 ms 344 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 480 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 6 ms 480 KB Output is correct
37 Correct 10 ms 348 KB Output is correct
38 Correct 12 ms 344 KB Output is correct
39 Correct 14 ms 348 KB Output is correct
40 Correct 15 ms 348 KB Output is correct
41 Correct 12 ms 348 KB Output is correct
42 Correct 12 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 8 ms 348 KB Output is correct
45 Correct 11 ms 348 KB Output is correct
46 Correct 15 ms 480 KB Output is correct
47 Correct 16 ms 348 KB Output is correct
48 Correct 15 ms 348 KB Output is correct
49 Correct 15 ms 472 KB Output is correct
50 Correct 15 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 6 ms 488 KB Output is correct
53 Correct 9 ms 348 KB Output is correct
54 Correct 17 ms 508 KB Output is correct
55 Correct 16 ms 348 KB Output is correct
56 Correct 63 ms 348 KB Output is correct
57 Correct 57 ms 348 KB Output is correct
58 Correct 57 ms 348 KB Output is correct
59 Correct 58 ms 604 KB Output is correct
60 Correct 58 ms 348 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 9 ms 348 KB Output is correct
63 Correct 20 ms 508 KB Output is correct
64 Correct 15 ms 348 KB Output is correct
65 Correct 28 ms 476 KB Output is correct
66 Correct 43 ms 532 KB Output is correct
67 Correct 61 ms 508 KB Output is correct
68 Correct 61 ms 348 KB Output is correct
69 Correct 60 ms 344 KB Output is correct