답안 #185655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
185655 2020-01-12T03:21:01 Z dndhk Bali Sculptures (APIO15_sculpture) C++14
100 / 100
324 ms 11128 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 2000;
const int INF = 10000000;

int N, A, B;
vector<ll> v;
ll sum[MAX_N+1];
ll ans;

ll Sum(ll x, ll y){
	return sum[max(x, y)] - sum[min(x, y)-1];
}
vector<int> gp[MAX_N+1];
bool chk1[MAX_N+1], chk2[MAX_N+1];

bool check(ll x){
	for(int i=0; i<=N; i++){
		while(!gp[i].empty())	gp[i].pop_back();
	}
	for(int i=1; i<=N; i++){
		for(int j=i; j<=N; j++){
			if((Sum(i, j) | x) == x){
				gp[i-1].pb(j);
			}
		}
	}
	for(int i=0; i<=N; i++)	chk1[i] = chk2[i] = false;
	chk1[0] = true;
	for(int t=1; t<=B; t++){
		for(int i=0; i<=N; i++){
			if(chk1[i]){
				for(int j : gp[i]){
					chk2[j] = true;
				}
			}
		}
		for(int i=0; i<=N; i++){
			chk1[i] = chk2[i];
			chk2[i] = false;
		}
		if(t>=A && chk1[N])	return true;
	}
	return false;
}


void solve1(){
	ans = (1LL<<40LL)-1;
	for(int k=39; k>=0; k--){
		ll t = (1LL<<(ll)k);
		if(check(ans-t)){
			ans-=t;
		}
	}
}

deque<int> dq;
int dist[MAX_N+1];

bool check2(ll x){
	for(int i=0; i<=N; i++){
		while(!gp[i].empty())	gp[i].pop_back();
	}
	for(int i=1; i<=N; i++){
		for(int j=i; j<=N; j++){
			if((Sum(i, j) | x) == x){
				gp[i-1].pb(j);
			}
		}
	}
	for(int i=0; i<=N; i++)	dist[i] = INF;
	dist[0] = 0;
	dq.pb(0);
	while(!dq.empty()){
		int now = dq.front(); dq.pop_front();
		for(int i : gp[now]){
			if(dist[i]>dist[now]+1){
				dist[i] = dist[now]+1;
				dq.pb(i);
			}
		}
	}
	return (dist[N]<=B);
}

void solve2(){
	ans = (1LL<<45LL)-1;
	for(int k=44; k>=0; k--){
		ll t = (1LL<<(ll)k);
		if(check2(ans-t)){
			ans-=t;
		}
	}
}

int main(){
	scanf("%d%d%d", &N, &A, &B);
	v.pb(0LL);
	for(int i=1 ;i<=N; i++){
		ll x; scanf("%lld", &x);
		v.pb(x);
		sum[i]=sum[i-1]+v[i];
	}
	if(A!=1)	solve1();
	else	solve2();
	cout<<ans;
	return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:106:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &N, &A, &B);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:109:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll x; scanf("%lld", &x);
         ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 7 ms 376 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 7 ms 404 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 380 KB Output is correct
18 Correct 0 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 4 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 4 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 380 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 1 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 1 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 1 ms 376 KB Output is correct
6 Correct 1 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 508 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 7 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 4 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 4 ms 380 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 7 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 380 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 1 ms 376 KB Output is correct
30 Correct 4 ms 376 KB Output is correct
31 Correct 3 ms 452 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 0 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 0 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 0 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 376 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 0 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 1 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 380 KB Output is correct
44 Correct 2 ms 376 KB Output is correct
45 Correct 1 ms 376 KB Output is correct
46 Correct 2 ms 376 KB Output is correct
47 Correct 3 ms 424 KB Output is correct
48 Correct 3 ms 416 KB Output is correct
49 Correct 3 ms 376 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 4 ms 376 KB Output is correct
53 Correct 3 ms 376 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 3 ms 376 KB Output is correct
56 Correct 2 ms 376 KB Output is correct
57 Correct 3 ms 376 KB Output is correct
58 Correct 3 ms 376 KB Output is correct
59 Correct 3 ms 376 KB Output is correct
60 Correct 3 ms 380 KB Output is correct
61 Correct 3 ms 376 KB Output is correct
62 Correct 4 ms 376 KB Output is correct
63 Correct 3 ms 348 KB Output is correct
64 Correct 14 ms 376 KB Output is correct
65 Correct 3 ms 376 KB Output is correct
66 Correct 3 ms 376 KB Output is correct
67 Correct 9 ms 376 KB Output is correct
68 Correct 5 ms 376 KB Output is correct
69 Correct 8 ms 376 KB Output is correct
70 Correct 6 ms 448 KB Output is correct
71 Correct 3 ms 376 KB Output is correct
72 Correct 4 ms 376 KB Output is correct
73 Correct 7 ms 376 KB Output is correct
74 Correct 7 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 380 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 0 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 3 ms 376 KB Output is correct
35 Correct 6 ms 376 KB Output is correct
36 Correct 5 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 3 ms 348 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 5 ms 376 KB Output is correct
43 Correct 2 ms 380 KB Output is correct
44 Correct 3 ms 376 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 6 ms 376 KB Output is correct
47 Correct 3 ms 376 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 4 ms 376 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 28 ms 1400 KB Output is correct
53 Correct 44 ms 2168 KB Output is correct
54 Correct 74 ms 3192 KB Output is correct
55 Correct 76 ms 3064 KB Output is correct
56 Correct 298 ms 11000 KB Output is correct
57 Correct 296 ms 11068 KB Output is correct
58 Correct 301 ms 11060 KB Output is correct
59 Correct 324 ms 11128 KB Output is correct
60 Correct 299 ms 11072 KB Output is correct
61 Correct 2 ms 376 KB Output is correct
62 Correct 46 ms 2040 KB Output is correct
63 Correct 83 ms 3064 KB Output is correct
64 Correct 74 ms 3064 KB Output is correct
65 Correct 144 ms 6264 KB Output is correct
66 Correct 221 ms 9080 KB Output is correct
67 Correct 294 ms 11060 KB Output is correct
68 Correct 301 ms 11000 KB Output is correct
69 Correct 290 ms 11128 KB Output is correct