#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x) cout << "Line " << __LINE__ << ", " << #x << " is " << x << endl
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<ll, ll>
#define ld long double
#define nl endl
#define tb '\t'
#define sp ' '
#define sqr(x) (x)*(x)
using namespace std;
const ll MX=2002, MOD=1000000007, BLOCK=327, INF=2e9+7;
const ll INFF=1000000000000000007;
const ld ERR=1e-6, pi=3.14159265358979323846;
ll N, L, R, A[MX], pref[MX], ans=INF;
bool DP[55][505][25];
ll getp(ll le, ll ri){
return pref[ri]-pref[le-1];
}
int main(){
fastio;
cin >> N >> L >> R;
for(ll i=1; i<=N; i++){
cin >> A[i];
pref[i]=pref[i-1]+A[i];
}
DP[1][0][0]=1;
for(ll i=1; i<=N; i++){
for(ll j=0; j<=500; j++){
for(ll k=i; k<=N; k++){
for(ll l=0; l<=N; l++){
ll tmp=(j|getp(i, k));
DP[k+1][tmp][l+1]|=DP[i][j][l];
}
}
}
}
for(ll i=0; i<=2000; i++){
for(ll j=L; j<=R; j++){
for(ll k=0; k<=500; k++){
if(DP[N+1][k][j])
ans=min(ans, k);
}
}
}
if(ans==INF)
cout << "-1\n";
else
cout << ans << nl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
400 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
14 ms |
468 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
17 ms |
596 KB |
Output is correct |
14 |
Correct |
2 ms |
420 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
468 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
7 ms |
596 KB |
Output is correct |
23 |
Correct |
7 ms |
592 KB |
Output is correct |
24 |
Correct |
3 ms |
592 KB |
Output is correct |
25 |
Correct |
7 ms |
596 KB |
Output is correct |
26 |
Correct |
9 ms |
592 KB |
Output is correct |
27 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
3 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
468 KB |
Output is correct |
6 |
Correct |
12 ms |
528 KB |
Output is correct |
7 |
Correct |
6 ms |
468 KB |
Output is correct |
8 |
Correct |
5 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
17 ms |
588 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
420 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
468 KB |
Output is correct |
21 |
Correct |
10 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
596 KB |
Output is correct |
23 |
Correct |
6 ms |
588 KB |
Output is correct |
24 |
Correct |
3 ms |
516 KB |
Output is correct |
25 |
Correct |
8 ms |
592 KB |
Output is correct |
26 |
Correct |
10 ms |
596 KB |
Output is correct |
27 |
Correct |
21 ms |
592 KB |
Output is correct |
28 |
Correct |
12 ms |
656 KB |
Output is correct |
29 |
Incorrect |
17 ms |
724 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
13 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
596 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
16 ms |
592 KB |
Output is correct |
14 |
Correct |
21 ms |
596 KB |
Output is correct |
15 |
Correct |
17 ms |
648 KB |
Output is correct |
16 |
Incorrect |
18 ms |
812 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
464 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
15 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
5 ms |
596 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
4 ms |
596 KB |
Output is correct |
12 |
Correct |
5 ms |
468 KB |
Output is correct |
13 |
Correct |
15 ms |
468 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
3 ms |
340 KB |
Output is correct |
16 |
Correct |
4 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
468 KB |
Output is correct |
21 |
Correct |
8 ms |
468 KB |
Output is correct |
22 |
Correct |
6 ms |
596 KB |
Output is correct |
23 |
Correct |
6 ms |
592 KB |
Output is correct |
24 |
Correct |
3 ms |
592 KB |
Output is correct |
25 |
Correct |
7 ms |
596 KB |
Output is correct |
26 |
Correct |
9 ms |
596 KB |
Output is correct |
27 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
15 ms |
468 KB |
Output is correct |
7 |
Correct |
7 ms |
468 KB |
Output is correct |
8 |
Correct |
6 ms |
468 KB |
Output is correct |
9 |
Correct |
6 ms |
588 KB |
Output is correct |
10 |
Correct |
5 ms |
468 KB |
Output is correct |
11 |
Correct |
3 ms |
468 KB |
Output is correct |
12 |
Correct |
4 ms |
468 KB |
Output is correct |
13 |
Correct |
15 ms |
468 KB |
Output is correct |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |