답안 #317746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317746 2020-10-30T09:16:05 Z soroush Bali Sculptures (APIO15_sculpture) C++14
75 / 100
242 ms 6272 KB
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 2100;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
int a[maxn];
int l , r;

void sub1(){
    ll ans = 1e18;
    for(int i = 0 ; i < (1 << (n - 1)) ; i ++)
        if(__builtin_popcount(i)+1 >= l and  __builtin_popcount(i)+1 <= r){
        vector < ll > vec;
        vec.clear();
        vec.pb(0);
        for(int j = 0 ; j < n ; j ++){
            vec.back()+=a[j];
            if(i & (1 << j))
                vec.pb(0);
        }
        ll orr = 0;
        for(auto x : vec)
            orr|=x;
        ans = min(ans , orr);
    }
    dokme(ans);
}

int mark[60][60][600];

int ans;

void dfs(int i , int k , int Or){
    if(i == n and k >= l and k <= r)
        ans = min(ans , Or);
    mark[i][k][Or] = 1;
    int sum = 0;
    for(int j = i+1 ; j <= n ; j ++){
        sum += a[j - 1];
        if(!mark[j][k+1][Or|sum])
            dfs(j, k + 1 , Or | sum);
    }
}


void sub2(){
    ans = 1e9;
    dfs(0 , 0 , 0);
    dokme(ans);
}

ll dp[maxn];

ll solve(){
	ans = (1LL << 60LL)-1;
	for(int i = 59 ; i >= 0 ; i --){
		ms(dp , 63), dp[0] = 0;
		ans ^= (1LL << i);
		for(int j = 0 ; j < n ; j ++){
			ll sum = 0;
			for(int k = j ; k < n ; k ++)
				sum += a[k], dp[k+1] = min(dp[k+1] ,(ans - (sum|ans))?dp[k+1] : dp[j]+1);
		}
		if(dp[n] > r)	
			ans += (1LL << i);
	}
	return(ans);
}


int32_t main(){
    migmig;
    cin >> n >> l >> r;
    for(int i = 0 ; i < n ; i ++)
        cin >> a[i];
    if(n <= 20){
        sub1();
    }
    if(n <= 50 and r <= 20 and *max_element(a , a + n) <= 10){
        sub2();
    }
    if(l == 1){
		dokme(solve());
	}
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 236 ms 528 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 512 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 288 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 14 ms 384 KB Output is correct
22 Correct 14 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 14 ms 384 KB Output is correct
26 Correct 225 ms 504 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 14 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 217 ms 504 KB Output is correct
34 Correct 233 ms 384 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 233 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 236 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 14 ms 384 KB Output is correct
22 Correct 14 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 14 ms 384 KB Output is correct
26 Correct 216 ms 384 KB Output is correct
27 Correct 1 ms 1408 KB Output is correct
28 Correct 2 ms 1792 KB Output is correct
29 Correct 3 ms 3712 KB Output is correct
30 Correct 4 ms 4352 KB Output is correct
31 Correct 6 ms 6016 KB Output is correct
32 Correct 5 ms 6016 KB Output is correct
33 Correct 5 ms 6016 KB Output is correct
34 Correct 6 ms 6016 KB Output is correct
35 Correct 6 ms 6016 KB Output is correct
36 Correct 6 ms 6016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 240 ms 504 KB Output is correct
14 Correct 1 ms 1408 KB Output is correct
15 Correct 2 ms 1792 KB Output is correct
16 Correct 3 ms 3584 KB Output is correct
17 Correct 4 ms 4352 KB Output is correct
18 Correct 6 ms 6016 KB Output is correct
19 Correct 5 ms 6016 KB Output is correct
20 Correct 6 ms 6016 KB Output is correct
21 Correct 6 ms 6016 KB Output is correct
22 Correct 6 ms 6016 KB Output is correct
23 Correct 6 ms 6016 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 242 ms 504 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 14 ms 384 KB Output is correct
22 Correct 14 ms 384 KB Output is correct
23 Correct 14 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 14 ms 384 KB Output is correct
26 Correct 219 ms 504 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 14 ms 384 KB Output is correct
32 Correct 3 ms 384 KB Output is correct
33 Correct 218 ms 504 KB Output is correct
34 Correct 242 ms 512 KB Output is correct
35 Correct 2 ms 384 KB Output is correct
36 Correct 239 ms 384 KB Output is correct
37 Correct 1 ms 1408 KB Output is correct
38 Correct 2 ms 1792 KB Output is correct
39 Correct 3 ms 3584 KB Output is correct
40 Correct 4 ms 4352 KB Output is correct
41 Correct 6 ms 6272 KB Output is correct
42 Correct 5 ms 6016 KB Output is correct
43 Correct 7 ms 6016 KB Output is correct
44 Correct 6 ms 6144 KB Output is correct
45 Correct 6 ms 6016 KB Output is correct
46 Correct 6 ms 6144 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 1 ms 384 KB Output is correct
53 Correct 1 ms 384 KB Output is correct
54 Correct 1 ms 384 KB Output is correct
55 Correct 1 ms 384 KB Output is correct
56 Correct 1 ms 384 KB Output is correct
57 Correct 1 ms 512 KB Output is correct
58 Correct 1 ms 384 KB Output is correct
59 Correct 1 ms 384 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 1 ms 384 KB Output is correct
63 Correct 1 ms 384 KB Output is correct
64 Incorrect 1 ms 384 KB Output isn't correct
65 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 239 ms 504 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 14 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 219 ms 384 KB Output is correct
21 Correct 236 ms 400 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 235 ms 504 KB Output is correct
24 Correct 1 ms 1408 KB Output is correct
25 Correct 2 ms 1792 KB Output is correct
26 Correct 3 ms 3584 KB Output is correct
27 Correct 4 ms 4352 KB Output is correct
28 Correct 6 ms 6016 KB Output is correct
29 Correct 5 ms 6016 KB Output is correct
30 Correct 5 ms 6016 KB Output is correct
31 Correct 6 ms 6016 KB Output is correct
32 Correct 6 ms 6016 KB Output is correct
33 Correct 6 ms 6144 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 1 ms 384 KB Output is correct
37 Correct 1 ms 384 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 1 ms 512 KB Output is correct
44 Correct 1 ms 384 KB Output is correct
45 Correct 1 ms 512 KB Output is correct
46 Correct 1 ms 384 KB Output is correct
47 Correct 1 ms 384 KB Output is correct
48 Correct 1 ms 384 KB Output is correct
49 Correct 1 ms 384 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 1 ms 384 KB Output is correct
52 Correct 17 ms 384 KB Output is correct
53 Correct 28 ms 512 KB Output is correct
54 Correct 44 ms 504 KB Output is correct
55 Correct 43 ms 384 KB Output is correct
56 Correct 171 ms 384 KB Output is correct
57 Correct 169 ms 504 KB Output is correct
58 Correct 167 ms 384 KB Output is correct
59 Correct 174 ms 384 KB Output is correct
60 Correct 176 ms 384 KB Output is correct
61 Correct 1 ms 384 KB Output is correct
62 Correct 24 ms 384 KB Output is correct
63 Correct 46 ms 504 KB Output is correct
64 Correct 42 ms 384 KB Output is correct
65 Correct 83 ms 416 KB Output is correct
66 Correct 128 ms 384 KB Output is correct
67 Correct 179 ms 384 KB Output is correct
68 Correct 178 ms 504 KB Output is correct
69 Correct 167 ms 384 KB Output is correct