Submission #768872

# Submission time Handle Problem Language Result Execution time Memory
768872 2023-06-28T19:47:38 Z raysh07 Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 468 KB
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

int n, a, b;
const int N = 2005;
int aa[N]; 
long long p[N];
bitset <N> bs[N];

bool check(long long x){
    bs[0].set(0);
    
    for (int i = 1; i <= n; i++){
        bs[i] &= 0;
        for (int j = 0; j < i; j++){
            long long val = p[i] - p[j];
            if ((val | x) == x) {
                bs[i] |= bs[j] << 1;
            }
        }
        
        int cnt = 0;
        for (int j = 1; j <= n; j++){
            if (bs[i].test(j) && !bs[i].test(j - 1)) cnt++;
        }
        
        assert(cnt <= 2);
    }
    
    for (int i = a; i <= b; i++){
        if (bs[n].test(i)) return true;
    }
    return false;
}

void Solve() 
{
    cin >> n >> a >> b;
    
    for (int i = 1; i <= n; i++) cin >> aa[i], p[i] = p[i - 1] + aa[i];
    
    long long ans = (1LL << 63) - 1;
    for (int i = 62; i >= 0; i--){
        if (check(ans - (1LL << i))) ans -= 1LL << i;
    }
    
    cout << ans << "\n";
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
//    cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}

Compilation message

sculpture.cpp: In function 'void Solve()':
sculpture.cpp:48:33: warning: integer overflow in expression of type 'long long int' results in '9223372036854775807' [-Woverflow]
   48 |     long long ans = (1LL << 63) - 1;
      |                     ~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 212 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 Runtime error 1 ms 468 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 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 336 KB Output is correct
9 Runtime error 1 ms 468 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# 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 0 ms 340 KB Output is correct
4 Correct 0 ms 212 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 1 ms 340 KB Output is correct
9 Runtime error 1 ms 468 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 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 1 ms 340 KB Output is correct
9 Runtime error 1 ms 468 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 212 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 Runtime error 1 ms 468 KB Execution killed with signal 6
10 Halted 0 ms 0 KB -