Submission #1032777

# Submission time Handle Problem Language Result Execution time Memory
1032777 2024-07-24T08:26:00 Z Phuoc Bali Sculptures (APIO15_sculpture) C++14
9 / 100
76 ms 604 KB
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <map>
#include <stack>
#include <queue>
 
using namespace std;
 
#define ll long long
#define pb push_back
#define el '\n'
#define mpair make_pair
#define MASK(i) (1LL << (i))
#define BIT(mask, i) (((mask) >> (i)) & 1)
#define fi first
#define se second
 
/* Author: Pham Gia Phuoc */
 
const ll MOD = (ll)(1e9) + 1LL * 19972207;
 
template <class T1, class T2>
    void add(T1 &a, T2 b){
        a += b;
        if(a >= MOD) a -= MOD;
    }
 
template <class T1, class T2>
    void sub(T1 &a, T2 b){
        a -= b;
        if(a < 0) a += MOD;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if(a > b){a = b; return true;} return false;
    }
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if(a < b){a = b; return true;} return false;
    }
 
/** END OF TEMPLATE. DRINK A CUP OF COFFEE BEFORE READING MY CODE **/
 
const int MAX = 2010;
const ll INF = (ll) 1e18 + 67LL;
const int oo = (int)(1e9 + 7);
const int NUM_BIT = 62;

#define FOR(i, a, b) for(int i = a; i <= b; i++)


int N, A, B;
long long ages[MAX];
 
void init(){
    cin >> N >> A >> B;
    FOR(i, 1, N) cin >> ages[i];
}

namespace subtask1{
    bool check(){
        return N <= 20;
    }

    long long solve(){
        long long ans = INF;
        for(int mask = 0; mask < MASK(N); mask++){
            if(__builtin_popcount(mask) == 0) continue;
            int cntGroup = __builtin_popcount(mask) + (BIT(mask, N - 1) == 1 ? 0 : 1);
            if(cntGroup < A || cntGroup > B) continue;
            
            long long sum = 0, sumor = -1;
            for(int i = 0; i < N; i++){
                sum += ages[i + 1];
                if(BIT(mask, i)){
                    sumor = (sumor == -1) ? sum : (sumor | sum);
                    sum = 0;
                }
            }
            if(!BIT(mask, N - 1)){
                // sum += ages[N];
                sumor = (sumor == -1) ? sum : (sumor | sum);
            }
            minimize(ans, sumor);
        }
        return ans;
    }
}

void solve(){
    if(subtask1::check()){cout << subtask1::solve(); return;}
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define test "test"
    srand(time(0));
    int t = 1;
    while(t--){
        // gen();
        init();
        solve();
    }
    
    return 0;
}
 
 
 
/*** ROAD TO VOI 2025 ***/
# 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 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 5 ms 460 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 64 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 432 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 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 7 ms 460 KB Output is correct
22 Correct 8 ms 456 KB Output is correct
23 Correct 7 ms 348 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 57 ms 432 KB Output is correct
27 Correct 0 ms 600 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 2 ms 456 KB Output is correct
31 Correct 7 ms 344 KB Output is correct
32 Correct 3 ms 460 KB Output is correct
33 Correct 55 ms 344 KB Output is correct
34 Correct 62 ms 348 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 62 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 1 ms 456 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 604 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 62 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 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 452 KB Output is correct
21 Correct 7 ms 464 KB Output is correct
22 Correct 9 ms 348 KB Output is correct
23 Correct 9 ms 456 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 7 ms 348 KB Output is correct
26 Correct 56 ms 596 KB Output is correct
27 Incorrect 0 ms 348 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 2 ms 460 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 3 ms 348 KB Output is correct
9 Correct 3 ms 348 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 5 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 69 ms 436 KB Output is correct
14 Incorrect 0 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 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 352 KB Output is correct
5 Correct 0 ms 456 KB Output is correct
6 Correct 2 ms 456 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 3 ms 352 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 4 ms 460 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 76 ms 440 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 0 ms 352 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 352 KB Output is correct
19 Correct 0 ms 352 KB Output is correct
20 Correct 1 ms 456 KB Output is correct
21 Correct 7 ms 472 KB Output is correct
22 Correct 7 ms 464 KB Output is correct
23 Correct 9 ms 476 KB Output is correct
24 Correct 4 ms 356 KB Output is correct
25 Correct 7 ms 460 KB Output is correct
26 Correct 54 ms 352 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 6 ms 348 KB Output is correct
32 Correct 4 ms 464 KB Output is correct
33 Correct 64 ms 432 KB Output is correct
34 Correct 64 ms 344 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 62 ms 348 KB Output is correct
37 Incorrect 0 ms 348 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 356 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 2 ms 412 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 6 ms 348 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 3 ms 464 KB Output is correct
13 Correct 63 ms 436 KB Output is correct
14 Correct 0 ms 456 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 7 ms 456 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 55 ms 436 KB Output is correct
21 Correct 67 ms 348 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 62 ms 348 KB Output is correct
24 Incorrect 1 ms 344 KB Output isn't correct
25 Halted 0 ms 0 KB -