이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define END "\n"
#define rall(v) (v).rbegin(), (v).rend()
#define all(v) (v).begin(), (v).end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int D = 50;
ll solve_small(int n, int a, int b) {
vector<ll> A(n + 1);
for (int i = 1; i <= n; ++i) cin >> A[i];
ll ans = (1LL << D) - 1;
for (int bit = D - 1; bit >= 0; --bit) {
vector<vector<bool>> dp(b + 1, vector<bool>(n + 1, false));
dp[0][0] = 1;
ans -= (1LL << bit);
bool ok = false;
for (int j = 1; j <= b; ++j) {
for (int i = 1; i <= n; ++i) {
ll sum = A[i];
for (int k = i - 1; k >= 0; --k) {
if ((sum | ans) == ans) {
dp[j][i] = dp[j][i] || dp[j - 1][k];
}
sum += A[k];
}
}
}
for (int i = a; i <= b; ++i) if (dp[i][n]) ok = 1;
// cout << bit << " " << ok << endl;
if (!ok) ans += (1LL << bit);
}
return ans;
}
ll solve_large(int n, int a, int b) {
vector<ll> A(n + 1);
for (int i = 0; i < n; ++i) cin >> A[i + 1];
ll ans = (1LL << D) - 1;
for (int bit = D - 1; bit >= 0; --bit) {
vector<int> dp(n + 1, INT_MAX - 1);
dp[0] = 0;
ans -= (1LL << bit);
bool ok = false;
for (int i = 1; i <= n; ++i) {
ll sum = A[i];
for (int j = i - 1; j >= 0; --j) {
if ((sum | ans) != ans) {
sum += A[j];
continue;
}
dp[i] = min(dp[i], dp[j] + 1);
sum += A[j];
}
}
if (dp[n] <= b) ok = 1;
if (!ok) ans += (1LL << bit);
}
return ans;
}
void solve(){
int n, a, b;
cin >> n >> a >> b;
if (n <= 100) cout << solve_small(n, a, b);
else cout << solve_large(n, a, b);
cout << END;
}
int main()
{
fastio
int t = 1;
// cin>> t;
while(t--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |