# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
43937 | 2018-03-28T12:07:42 Z | Kerim | Bali Sculptures (APIO15_sculpture) | C++17 | 144 ms | 16508 KB |
#include "bits/stdc++.h" #define MAXN 100009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<int,int> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const int N=2005; int dp[N][N],pd[N]; ll par[N]; int n,a,b; int f(int pos,int comp,ll mask){ if(comp>b) return 0; if(pos>n) return (a<=comp); int &ret=dp[pos][comp]; if(~ret) return ret;ret=0; for(int i=pos;i<=n;i++){ ll sum=par[i]-par[pos-1]; if((mask&sum)==sum and f(i+1,comp+1,mask)) return ret=1; }return ret; } int f1(int pos,ll mask){ if(pos>n) return 0; int &ret=pd[pos]; if(~ret) return ret;ret=INF; for(int i=pos;i<=n;i++){ ll sum=par[i]-par[pos-1]; if((mask&sum)==sum) umin(ret,f1(i+1,mask)+1); } return ret; } int main(){ //~ freopen("file.in", "r", stdin); scanf("%d%d%d",&n,&a,&b); for(int i=1;i<=n;i++){ int x; scanf("%d",&x); par[i]=par[i-1]+x; } ll ans=(1LL<<45)-1; if(a>1){ for(int i=44;i>=0;i--){ memset(dp,-1,sizeof dp); if(f(1,0,ans-(1LL<<i))) ans-=(1LL<<i); } } else{ for(int i=44;i>=0;i--){ memset(pd,-1,sizeof pd); if(f1(1,ans-(1LL<<i))<=b) ans-=(1LL<<i); } } printf("%lld\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 416 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 560 KB | Output is correct |
7 | Correct | 2 ms | 680 KB | Output is correct |
8 | Correct | 2 ms | 680 KB | Output is correct |
9 | Correct | 2 ms | 680 KB | Output is correct |
10 | Correct | 2 ms | 680 KB | Output is correct |
11 | Correct | 2 ms | 680 KB | Output is correct |
12 | Correct | 2 ms | 680 KB | Output is correct |
13 | Correct | 2 ms | 752 KB | Output is correct |
14 | Correct | 54 ms | 16252 KB | Output is correct |
15 | Correct | 57 ms | 16252 KB | Output is correct |
16 | Correct | 61 ms | 16356 KB | Output is correct |
17 | Correct | 58 ms | 16356 KB | Output is correct |
18 | Correct | 57 ms | 16356 KB | Output is correct |
19 | Correct | 55 ms | 16356 KB | Output is correct |
20 | Correct | 58 ms | 16392 KB | Output is correct |
21 | Correct | 59 ms | 16392 KB | Output is correct |
22 | Correct | 57 ms | 16392 KB | Output is correct |
23 | Correct | 56 ms | 16392 KB | Output is correct |
24 | Correct | 55 ms | 16392 KB | Output is correct |
25 | Correct | 58 ms | 16392 KB | Output is correct |
26 | Correct | 59 ms | 16392 KB | Output is correct |
27 | Correct | 2 ms | 16392 KB | Output is correct |
28 | Correct | 2 ms | 16392 KB | Output is correct |
29 | Correct | 2 ms | 16392 KB | Output is correct |
30 | Correct | 2 ms | 16392 KB | Output is correct |
31 | Correct | 2 ms | 16392 KB | Output is correct |
32 | Correct | 2 ms | 16392 KB | Output is correct |
33 | Correct | 2 ms | 16392 KB | Output is correct |
34 | Correct | 2 ms | 16392 KB | Output is correct |
35 | Correct | 2 ms | 16392 KB | Output is correct |
36 | Correct | 2 ms | 16392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 16392 KB | Output is correct |
2 | Correct | 2 ms | 16392 KB | Output is correct |
3 | Correct | 2 ms | 16392 KB | Output is correct |
4 | Correct | 2 ms | 16392 KB | Output is correct |
5 | Correct | 2 ms | 16392 KB | Output is correct |
6 | Correct | 2 ms | 16392 KB | Output is correct |
7 | Correct | 2 ms | 16392 KB | Output is correct |
8 | Correct | 2 ms | 16392 KB | Output is correct |
9 | Correct | 2 ms | 16392 KB | Output is correct |
10 | Correct | 2 ms | 16392 KB | Output is correct |
11 | Correct | 2 ms | 16392 KB | Output is correct |
12 | Correct | 2 ms | 16392 KB | Output is correct |
13 | Correct | 3 ms | 16392 KB | Output is correct |
14 | Correct | 72 ms | 16392 KB | Output is correct |
15 | Correct | 55 ms | 16392 KB | Output is correct |
16 | Correct | 60 ms | 16392 KB | Output is correct |
17 | Correct | 52 ms | 16392 KB | Output is correct |
18 | Correct | 54 ms | 16392 KB | Output is correct |
19 | Correct | 67 ms | 16392 KB | Output is correct |
20 | Correct | 56 ms | 16392 KB | Output is correct |
21 | Correct | 62 ms | 16392 KB | Output is correct |
22 | Correct | 55 ms | 16392 KB | Output is correct |
23 | Correct | 55 ms | 16392 KB | Output is correct |
24 | Correct | 52 ms | 16392 KB | Output is correct |
25 | Correct | 56 ms | 16392 KB | Output is correct |
26 | Correct | 55 ms | 16392 KB | Output is correct |
27 | Correct | 2 ms | 16392 KB | Output is correct |
28 | Correct | 2 ms | 16392 KB | Output is correct |
29 | Correct | 2 ms | 16392 KB | Output is correct |
30 | Correct | 2 ms | 16392 KB | Output is correct |
31 | Correct | 2 ms | 16392 KB | Output is correct |
32 | Correct | 3 ms | 16392 KB | Output is correct |
33 | Correct | 3 ms | 16392 KB | Output is correct |
34 | Correct | 2 ms | 16392 KB | Output is correct |
35 | Correct | 2 ms | 16392 KB | Output is correct |
36 | Correct | 3 ms | 16392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 16392 KB | Output is correct |
2 | Correct | 2 ms | 16392 KB | Output is correct |
3 | Correct | 2 ms | 16392 KB | Output is correct |
4 | Correct | 2 ms | 16392 KB | Output is correct |
5 | Correct | 2 ms | 16392 KB | Output is correct |
6 | Correct | 2 ms | 16392 KB | Output is correct |
7 | Correct | 2 ms | 16392 KB | Output is correct |
8 | Correct | 2 ms | 16392 KB | Output is correct |
9 | Correct | 2 ms | 16392 KB | Output is correct |
10 | Correct | 2 ms | 16392 KB | Output is correct |
11 | Correct | 2 ms | 16392 KB | Output is correct |
12 | Correct | 2 ms | 16392 KB | Output is correct |
13 | Correct | 2 ms | 16392 KB | Output is correct |
14 | Correct | 2 ms | 16392 KB | Output is correct |
15 | Correct | 2 ms | 16392 KB | Output is correct |
16 | Correct | 2 ms | 16392 KB | Output is correct |
17 | Correct | 2 ms | 16392 KB | Output is correct |
18 | Correct | 2 ms | 16392 KB | Output is correct |
19 | Correct | 2 ms | 16392 KB | Output is correct |
20 | Correct | 3 ms | 16392 KB | Output is correct |
21 | Correct | 2 ms | 16392 KB | Output is correct |
22 | Correct | 2 ms | 16392 KB | Output is correct |
23 | Correct | 2 ms | 16392 KB | Output is correct |
24 | Correct | 2 ms | 16392 KB | Output is correct |
25 | Correct | 2 ms | 16392 KB | Output is correct |
26 | Correct | 2 ms | 16392 KB | Output is correct |
27 | Correct | 2 ms | 16392 KB | Output is correct |
28 | Correct | 3 ms | 16392 KB | Output is correct |
29 | Correct | 3 ms | 16392 KB | Output is correct |
30 | Correct | 3 ms | 16392 KB | Output is correct |
31 | Correct | 2 ms | 16392 KB | Output is correct |
32 | Correct | 3 ms | 16392 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 16392 KB | Output is correct |
2 | Correct | 2 ms | 16392 KB | Output is correct |
3 | Correct | 2 ms | 16392 KB | Output is correct |
4 | Correct | 2 ms | 16392 KB | Output is correct |
5 | Correct | 2 ms | 16392 KB | Output is correct |
6 | Correct | 2 ms | 16392 KB | Output is correct |
7 | Correct | 2 ms | 16392 KB | Output is correct |
8 | Correct | 2 ms | 16392 KB | Output is correct |
9 | Correct | 2 ms | 16392 KB | Output is correct |
10 | Correct | 2 ms | 16392 KB | Output is correct |
11 | Correct | 2 ms | 16392 KB | Output is correct |
12 | Correct | 2 ms | 16392 KB | Output is correct |
13 | Correct | 2 ms | 16392 KB | Output is correct |
14 | Correct | 58 ms | 16392 KB | Output is correct |
15 | Correct | 51 ms | 16508 KB | Output is correct |
16 | Correct | 60 ms | 16508 KB | Output is correct |
17 | Correct | 51 ms | 16508 KB | Output is correct |
18 | Correct | 59 ms | 16508 KB | Output is correct |
19 | Correct | 62 ms | 16508 KB | Output is correct |
20 | Correct | 56 ms | 16508 KB | Output is correct |
21 | Correct | 54 ms | 16508 KB | Output is correct |
22 | Correct | 56 ms | 16508 KB | Output is correct |
23 | Correct | 56 ms | 16508 KB | Output is correct |
24 | Correct | 53 ms | 16508 KB | Output is correct |
25 | Correct | 54 ms | 16508 KB | Output is correct |
26 | Correct | 53 ms | 16508 KB | Output is correct |
27 | Correct | 2 ms | 16508 KB | Output is correct |
28 | Correct | 2 ms | 16508 KB | Output is correct |
29 | Correct | 2 ms | 16508 KB | Output is correct |
30 | Correct | 2 ms | 16508 KB | Output is correct |
31 | Correct | 2 ms | 16508 KB | Output is correct |
32 | Correct | 2 ms | 16508 KB | Output is correct |
33 | Correct | 2 ms | 16508 KB | Output is correct |
34 | Correct | 2 ms | 16508 KB | Output is correct |
35 | Correct | 2 ms | 16508 KB | Output is correct |
36 | Correct | 2 ms | 16508 KB | Output is correct |
37 | Correct | 2 ms | 16508 KB | Output is correct |
38 | Correct | 2 ms | 16508 KB | Output is correct |
39 | Correct | 2 ms | 16508 KB | Output is correct |
40 | Correct | 2 ms | 16508 KB | Output is correct |
41 | Correct | 2 ms | 16508 KB | Output is correct |
42 | Correct | 2 ms | 16508 KB | Output is correct |
43 | Correct | 2 ms | 16508 KB | Output is correct |
44 | Correct | 2 ms | 16508 KB | Output is correct |
45 | Correct | 2 ms | 16508 KB | Output is correct |
46 | Correct | 2 ms | 16508 KB | Output is correct |
47 | Correct | 2 ms | 16508 KB | Output is correct |
48 | Correct | 2 ms | 16508 KB | Output is correct |
49 | Correct | 2 ms | 16508 KB | Output is correct |
50 | Correct | 3 ms | 16508 KB | Output is correct |
51 | Correct | 2 ms | 16508 KB | Output is correct |
52 | Correct | 2 ms | 16508 KB | Output is correct |
53 | Correct | 3 ms | 16508 KB | Output is correct |
54 | Correct | 3 ms | 16508 KB | Output is correct |
55 | Correct | 3 ms | 16508 KB | Output is correct |
56 | Correct | 2 ms | 16508 KB | Output is correct |
57 | Correct | 2 ms | 16508 KB | Output is correct |
58 | Correct | 2 ms | 16508 KB | Output is correct |
59 | Correct | 2 ms | 16508 KB | Output is correct |
60 | Correct | 3 ms | 16508 KB | Output is correct |
61 | Correct | 2 ms | 16508 KB | Output is correct |
62 | Correct | 2 ms | 16508 KB | Output is correct |
63 | Correct | 2 ms | 16508 KB | Output is correct |
64 | Correct | 52 ms | 16508 KB | Output is correct |
65 | Correct | 56 ms | 16508 KB | Output is correct |
66 | Correct | 53 ms | 16508 KB | Output is correct |
67 | Correct | 57 ms | 16508 KB | Output is correct |
68 | Correct | 60 ms | 16508 KB | Output is correct |
69 | Correct | 53 ms | 16508 KB | Output is correct |
70 | Correct | 52 ms | 16508 KB | Output is correct |
71 | Correct | 53 ms | 16508 KB | Output is correct |
72 | Correct | 57 ms | 16508 KB | Output is correct |
73 | Correct | 58 ms | 16508 KB | Output is correct |
74 | Correct | 61 ms | 16508 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 16508 KB | Output is correct |
2 | Correct | 2 ms | 16508 KB | Output is correct |
3 | Correct | 2 ms | 16508 KB | Output is correct |
4 | Correct | 2 ms | 16508 KB | Output is correct |
5 | Correct | 2 ms | 16508 KB | Output is correct |
6 | Correct | 2 ms | 16508 KB | Output is correct |
7 | Correct | 2 ms | 16508 KB | Output is correct |
8 | Correct | 2 ms | 16508 KB | Output is correct |
9 | Correct | 2 ms | 16508 KB | Output is correct |
10 | Correct | 2 ms | 16508 KB | Output is correct |
11 | Correct | 2 ms | 16508 KB | Output is correct |
12 | Correct | 2 ms | 16508 KB | Output is correct |
13 | Correct | 2 ms | 16508 KB | Output is correct |
14 | Correct | 2 ms | 16508 KB | Output is correct |
15 | Correct | 2 ms | 16508 KB | Output is correct |
16 | Correct | 2 ms | 16508 KB | Output is correct |
17 | Correct | 2 ms | 16508 KB | Output is correct |
18 | Correct | 2 ms | 16508 KB | Output is correct |
19 | Correct | 2 ms | 16508 KB | Output is correct |
20 | Correct | 2 ms | 16508 KB | Output is correct |
21 | Correct | 2 ms | 16508 KB | Output is correct |
22 | Correct | 2 ms | 16508 KB | Output is correct |
23 | Correct | 2 ms | 16508 KB | Output is correct |
24 | Correct | 2 ms | 16508 KB | Output is correct |
25 | Correct | 2 ms | 16508 KB | Output is correct |
26 | Correct | 2 ms | 16508 KB | Output is correct |
27 | Correct | 2 ms | 16508 KB | Output is correct |
28 | Correct | 2 ms | 16508 KB | Output is correct |
29 | Correct | 2 ms | 16508 KB | Output is correct |
30 | Correct | 2 ms | 16508 KB | Output is correct |
31 | Correct | 2 ms | 16508 KB | Output is correct |
32 | Correct | 2 ms | 16508 KB | Output is correct |
33 | Correct | 2 ms | 16508 KB | Output is correct |
34 | Correct | 2 ms | 16508 KB | Output is correct |
35 | Correct | 2 ms | 16508 KB | Output is correct |
36 | Correct | 2 ms | 16508 KB | Output is correct |
37 | Correct | 2 ms | 16508 KB | Output is correct |
38 | Correct | 3 ms | 16508 KB | Output is correct |
39 | Correct | 3 ms | 16508 KB | Output is correct |
40 | Correct | 3 ms | 16508 KB | Output is correct |
41 | Correct | 2 ms | 16508 KB | Output is correct |
42 | Correct | 3 ms | 16508 KB | Output is correct |
43 | Correct | 2 ms | 16508 KB | Output is correct |
44 | Correct | 2 ms | 16508 KB | Output is correct |
45 | Correct | 2 ms | 16508 KB | Output is correct |
46 | Correct | 2 ms | 16508 KB | Output is correct |
47 | Correct | 2 ms | 16508 KB | Output is correct |
48 | Correct | 2 ms | 16508 KB | Output is correct |
49 | Correct | 2 ms | 16508 KB | Output is correct |
50 | Correct | 2 ms | 16508 KB | Output is correct |
51 | Correct | 2 ms | 16508 KB | Output is correct |
52 | Correct | 11 ms | 16508 KB | Output is correct |
53 | Correct | 12 ms | 16508 KB | Output is correct |
54 | Correct | 37 ms | 16508 KB | Output is correct |
55 | Correct | 27 ms | 16508 KB | Output is correct |
56 | Correct | 78 ms | 16508 KB | Output is correct |
57 | Correct | 63 ms | 16508 KB | Output is correct |
58 | Correct | 91 ms | 16508 KB | Output is correct |
59 | Correct | 144 ms | 16508 KB | Output is correct |
60 | Correct | 77 ms | 16508 KB | Output is correct |
61 | Correct | 2 ms | 16508 KB | Output is correct |
62 | Correct | 20 ms | 16508 KB | Output is correct |
63 | Correct | 40 ms | 16508 KB | Output is correct |
64 | Correct | 33 ms | 16508 KB | Output is correct |
65 | Correct | 38 ms | 16508 KB | Output is correct |
66 | Correct | 72 ms | 16508 KB | Output is correct |
67 | Correct | 91 ms | 16508 KB | Output is correct |
68 | Correct | 131 ms | 16508 KB | Output is correct |
69 | Correct | 89 ms | 16508 KB | Output is correct |