이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> order_set;
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//uniform_int_distribution<int> gen; ///(min, max)
//int random() {return gen(mt_rand);}
const int mxN=2001;
const int mod=998244353;
const int mxlogN=40;
const int mxK=26;
const ll inf=1e18;
const int K=600;
int dp[mxN][mxN], a[mxN], n, A, B;
ll check(int i, int k, ll msk)
{
if(i==n) return k>=A&&k<=B;
if(~dp[i][k]) return dp[i][k];
ll sum=0;
for(int j=i+1; j<=n; j++)
{
sum+=a[j-1];
if((msk&sum)==sum) if(check(j,k+1,msk)) return dp[i][k]=1;
}
return dp[i][k]=0;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1;
cin >> n >> A >> B;
for(int i=0; i<n; i++) cin >> a[i];
ll msk=(1LL<<(mxlogN+1))-1;
for(int j=0; j<=mxlogN; j++)
{
msk^=check(0,0,msk^1LL<<(mxlogN-j))<<(mxlogN-j);
for(int i=0; i<mxN; i++) for(int j=0; j<mxN; j++) dp[i][j]=-1;
}
cout << msk << "\n";
}
/*
6 2 2
8 1 2 1 5 4
*/
# | 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... |