Submission #251977

#TimeUsernameProblemLanguageResultExecution timeMemory
251977IgorIBali Sculptures (APIO15_sculpture)C++17
71 / 100
1096 ms896 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<ll> vll; #define forn(i, n) for (int (i) = 0; (i) != (n); (i)++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define popcount(x) __builtin_popcount(x) #define popcountll(x) __builtin_popcountll(x) #define fi first #define se second #define re return #define pb push_back #define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin()) #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl #define ln cerr << __LINE__ << endl #else #define dbg(x) void(0) #define ln void(0) #endif // LOCAL const int N = 2005; int check(int n, int a, int b, vector<ll> &p, ll mask) { vector<bitset<N> > dp(n + 1, bitset<N>()); dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) { ll x = p[i] - p[j]; if ((x & mask) == x) { dp[i] |= dp[j] << 1; } } } for (int i = a; i <= b; i++) if (dp[n][i]) return 1; return 0; } signed main() { int n, a, b; cin >> n >> a >> b; vector<ll> x(n); forn(i, n) cin >> x[i]; vector<ll> p(n + 1); for (int i = 1; i <= n; i++) p[i] = x[i - 1] + p[i - 1]; ll ans = (1ll << 60) - 1; for (int j = 59; j >= 0; j--) { if (check(n, a, b, p, ans - (1ll << j))) { ans -= (1ll << j); } } cout << ans; } /* Note: Check constants at the beginning of the code. N is set to 4e5 but be careful in problems with large constant factor. Setting N in every problem is more effective. Check corner cases. N = 1 No def int long long for now. Add something here. */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...