Submission #793494

# Submission time Handle Problem Language Result Execution time Memory
793494 2023-07-25T22:44:46 Z nnhzzz Bali Sculptures (APIO15_sculpture) C++14
100 / 100
54 ms 3552 KB
// cre: Nguyen Ngoc Hung - Train VOI 2024 :>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <unordered_set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <cstring>
#include <unordered_map>
#include <cmath>
#include <array>
#include <cassert>
#include <random>

using namespace std;

#define    SORT_UNIQUE(v)  sort(ALL(v)),(v).resize(unique(ALL(v))-(v).begin())
#define        __nnhzzz__  signed main()
#define          BIT(i,j)  ((i>>j)&1LL)
#define           MASK(i)  (1LL<<i)
#define           RALL(x)  (x).rbegin(),(x).rend()
#define            ALL(x)  (x).begin(),(x).end()
#define             SZ(x)  (int)(x).size()
#define                fi  first
#define                se  second
#define               INF  0x3f3f3f3f
#define                ll  long long
#define               ull  unsigned long long
#define                ld  long double
#define                vi  vector<int>
#define               vvi  vector<vi>
#define              vvvi  vector<vvi>
#define             vvvvi  vector<vvvi>
#define               pii  pair<int,int>
#define              vpii  vector<pii>
#define      RESET(x,val)  memset((x),(val),sizeof(x))
#define REPDIS(i,be,en,j)  for(int i = (be); i<=(en); i+=j)
#define     REPD(i,be,en)  for(int i = (be); i>=(en); i--)
#define      REP(i,be,en)  for(int i = (be); i<=(en); i++)
#define               int  ll
//-------------------------------------------------------------//
const int oo = 1e12,LOG = 20,MAXN = 2e3+7,N = 105;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-------------------------------------------------------------//
template<typename T1, typename T2> bool mini(T1 &a, T2 b){if(a>b){a=b;return true;}return false;}
template<typename T1, typename T2> bool maxi(T1 &a, T2 b){if(a<b){a=b;return true;}return false;}
template<typename T> T gcd(T a, T b) { while(b) { a %= b; swap(a,b); } return a; }
template<typename T> T lcm(T a, T b) { return a/gcd(a,b)*b; }

/*
----------------------------------------------------------------
    END OF TEMPLATE
----------------------------------------------------------------
    Nguyen Ngoc Hung - nnhzzz
    Training for VOI24 gold medal
----------------------------------------------------------------
*/

int a[MAXN],s[MAXN];
int n,l,r;

// 100

void sub1(){
    int res = oo;
    REP(state,0,MASK(n)-1){
        int cnt = __builtin_popcount(state)+1;
        if(cnt<l || cnt>r || BIT(state,(n-1))){
            continue;
        }
        int pre = 0,ans = 0;
        REP(i,1,n){
            if(BIT(state,(i-1))){
                ans |= s[i]-s[pre];
                pre = i;
            }
        }
        if(pre!=n){
            ans |= s[n]-s[pre];
        }
        mini(res,ans);
    }
    cout << res;
}

int dp[53][23][515];

void sub2(){
    dp[0][0][0] = 1;
    REP(gr,0,r-1){
        REP(i,0,n){
            REP(now,0,512){
                if(dp[i][gr][now]==0){
                    continue;
                }
                REP(j,i+1,n){
                    dp[j][gr+1][now|(s[j]-s[i])] = 1;
                }
            }
        }
    }
    int res = oo;
    REP(gr,l,r){
        REP(now,0,512){
            if(dp[n][gr][now]==1){
                mini(res,now);
            }
        }
    }
    cout << res;
}

int dp1[MAXN],dp2[N][N];

bool check1(int x){
    REP(i,1,n){
        dp1[i] = oo;
    }
    dp1[0] = 0;
    REP(i,0,n){
        if(dp1[i]==oo){
            continue;
        }
        REP(j,i+1,n){
            if(((s[j]-s[i])|x)==x){
                mini(dp1[j],dp1[i]+1);
            }
        }
    }
    return (dp1[n]<=r);
}

bool check2(int x){
    REP(i,0,n){
        REP(j,0,n){
            dp2[i][j] = 0;
        }
    }
    dp2[0][0] = 1;
    REP(i,0,n-1){
        REP(j,0,i){
            if(dp2[i][j]==0){
                continue;
            }
            REP(k,i+1,n){
                if(((s[k]-s[i])|x)==x){
                    dp2[k][j+1] = 1;
                }
            }
        }
    }
    REP(i,l,r){
        if(dp2[n][i]==1){
            return true;
        }
    }
    return false;
}

void sub(){
    int state = 0,res = 0;
    REPD(i,40,0){
        if(l==1){
            res = res+1LL*MASK(i)*(!check1(res+MASK(i)-1));
        }else{
            res = res+1LL*MASK(i)*(!check2(res+MASK(i)-1));
        }
    }
    cout << res;
}

void solve(){
    cin >> n >> l >> r;
    int ma = 0;
    REP(i,1,n){
        cin >> a[i];
        s[i] = s[i-1]+a[i];
        maxi(ma,a[i]);
    }
    // sub(); return ;
    if(n<=20){
        sub1(); return ;
    }
    if(n<=50 && r<=20 && ma<=10){
        sub2(); return ;
    }
    sub();
}

__nnhzzz__{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #define name "test"
    if(fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    #define name1 "nnhzzz"
    if(fopen(name1".inp","r")){
        freopen(name1".inp","r",stdin);
        freopen(name1".out","w",stdout);
    }

    int test = 1;

    while(test--){
      solve();
    }
    cerr << "\nTime elapsed: " << 1000*clock()/CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

sculpture.cpp: In function 'void sub()':
sculpture.cpp:189:9: warning: unused variable 'state' [-Wunused-variable]
  189 |     int state = 0,res = 0;
      |         ^~~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:223:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  223 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:224:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  224 |         freopen(name".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:228:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  228 |         freopen(name1".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:229:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  229 |         freopen(name1".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 2 ms 336 KB Output is correct
7 Correct 1 ms 432 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 37 ms 340 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 344 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 6 ms 348 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 6 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 6 ms 336 KB Output is correct
26 Correct 36 ms 460 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 344 KB Output is correct
31 Correct 6 ms 352 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 33 ms 340 KB Output is correct
34 Correct 39 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 37 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 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 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 37 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 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 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 6 ms 336 KB Output is correct
22 Correct 6 ms 348 KB Output is correct
23 Correct 6 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 6 ms 340 KB Output is correct
26 Correct 33 ms 340 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1108 KB Output is correct
29 Correct 1 ms 980 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 3 ms 3504 KB Output is correct
32 Correct 3 ms 3540 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 3540 KB Output is correct
35 Correct 2 ms 3152 KB Output is correct
36 Correct 2 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 336 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 3 ms 340 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 37 ms 332 KB Output is correct
14 Correct 1 ms 1236 KB Output is correct
15 Correct 1 ms 1108 KB Output is correct
16 Correct 1 ms 976 KB Output is correct
17 Correct 2 ms 2772 KB Output is correct
18 Correct 2 ms 3540 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 2 ms 3540 KB Output is correct
22 Correct 2 ms 3156 KB Output is correct
23 Correct 2 ms 2132 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 332 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 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 3 ms 336 KB Output is correct
10 Correct 3 ms 292 KB Output is correct
11 Correct 3 ms 340 KB Output is correct
12 Correct 3 ms 336 KB Output is correct
13 Correct 37 ms 340 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 332 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 6 ms 340 KB Output is correct
22 Correct 6 ms 340 KB Output is correct
23 Correct 6 ms 340 KB Output is correct
24 Correct 3 ms 340 KB Output is correct
25 Correct 6 ms 336 KB Output is correct
26 Correct 33 ms 324 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 6 ms 340 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 33 ms 340 KB Output is correct
34 Correct 37 ms 340 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 38 ms 352 KB Output is correct
37 Correct 1 ms 1240 KB Output is correct
38 Correct 1 ms 1104 KB Output is correct
39 Correct 1 ms 984 KB Output is correct
40 Correct 2 ms 2772 KB Output is correct
41 Correct 3 ms 3552 KB Output is correct
42 Correct 2 ms 3548 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 3544 KB Output is correct
45 Correct 2 ms 3156 KB Output is correct
46 Correct 2 ms 2132 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 356 KB Output is correct
56 Correct 1 ms 324 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 360 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 4 ms 344 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 1 ms 336 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 2 ms 344 KB Output is correct
69 Correct 2 ms 344 KB Output is correct
70 Correct 2 ms 344 KB Output is correct
71 Correct 2 ms 344 KB Output is correct
72 Correct 3 ms 344 KB Output is correct
73 Correct 3 ms 352 KB Output is correct
74 Correct 3 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 352 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 37 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 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 6 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 33 ms 340 KB Output is correct
21 Correct 37 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 37 ms 340 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1108 KB Output is correct
26 Correct 1 ms 980 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 3540 KB Output is correct
29 Correct 2 ms 3540 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 2 ms 3540 KB Output is correct
32 Correct 2 ms 3156 KB Output is correct
33 Correct 1 ms 2132 KB Output is correct
34 Correct 0 ms 332 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 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 344 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 344 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 336 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 4 ms 340 KB Output is correct
53 Correct 3 ms 340 KB Output is correct
54 Correct 15 ms 392 KB Output is correct
55 Correct 10 ms 340 KB Output is correct
56 Correct 18 ms 404 KB Output is correct
57 Correct 16 ms 340 KB Output is correct
58 Correct 28 ms 396 KB Output is correct
59 Correct 35 ms 344 KB Output is correct
60 Correct 22 ms 416 KB Output is correct
61 Correct 1 ms 336 KB Output is correct
62 Correct 3 ms 340 KB Output is correct
63 Correct 16 ms 384 KB Output is correct
64 Correct 5 ms 344 KB Output is correct
65 Correct 9 ms 340 KB Output is correct
66 Correct 14 ms 408 KB Output is correct
67 Correct 16 ms 344 KB Output is correct
68 Correct 54 ms 340 KB Output is correct
69 Correct 15 ms 404 KB Output is correct