답안 #78029

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78029 2018-10-02T00:18:51 Z xiaowuc1 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
184 ms 1020 KB
#include <bits/stdc++.h>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);

ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pill;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<vector<ll>> matrix;

ll pref[2001];

int n, lhs, rhs;
bool valid[2001];
bool nextValid[2001];

int dp[2001];

bool fastcan(ll mask) {
  for(int i = 1; i <= n; i++) {
    dp[i] = 1 << 25;
  }
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j <= n; j++) {
      ll vv = (pref[j] - pref[i]) & mask;
      if(vv == pref[j] - pref[i]) {
        dp[j] = min(dp[j], dp[i]+1);
      }
    }
  }
  return dp[n] <= rhs;
}

bool can(ll mask) {
  if(lhs == 1) return fastcan(mask);
  memset(valid, 0, sizeof(valid));
  valid[0] = true;
  for(int x = 1; x <= rhs; x++) {
    memset(nextValid, 0, sizeof(nextValid));
    for(int a = 0; a <= n; a++) {
      if(!valid[a]) continue;
      for(int b = a+1; b <= n; b++) {
        ll vv = pref[b] - pref[a];
        nextValid[b] |= (vv&mask)==vv;
      }
    }
    if(x >= lhs && nextValid[n]) return true;
    memcpy(valid, nextValid, sizeof(valid));
  }
  return false;
}

int main() {
  scanf("%d%d%d", &n, &lhs, &rhs);
  for(int i = 0; i < n; i++) {
    scanf("%lld", &pref[i+1]);
    pref[i+1] += pref[i];
  }
  ll ret = 1;
  while(ret < pref[n]) {
    ret |= ret << 1;
  }
  for(int i = 45; i >= 0; i--) {
    ll ans = ret & ~(1LL << (i));
    if(ans == ret) continue;
    if(can(ans)) {
      ret = ans;
    }
  }
  printf("%lld\n", ret);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &n, &lhs, &rhs);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld", &pref[i+1]);
     ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 2 ms 568 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 588 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 588 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 2 ms 620 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 3 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 636 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 2 ms 636 KB Output is correct
31 Correct 2 ms 636 KB Output is correct
32 Correct 2 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 2 ms 636 KB Output is correct
35 Correct 2 ms 636 KB Output is correct
36 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 3 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 636 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 2 ms 636 KB Output is correct
31 Correct 2 ms 636 KB Output is correct
32 Correct 3 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 2 ms 636 KB Output is correct
35 Correct 2 ms 636 KB Output is correct
36 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 4 ms 636 KB Output is correct
11 Correct 3 ms 636 KB Output is correct
12 Correct 3 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 4 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 636 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 2 ms 636 KB Output is correct
31 Correct 2 ms 636 KB Output is correct
32 Correct 2 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 636 KB Output is correct
2 Correct 2 ms 636 KB Output is correct
3 Correct 2 ms 636 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 2 ms 636 KB Output is correct
10 Correct 2 ms 636 KB Output is correct
11 Correct 2 ms 636 KB Output is correct
12 Correct 2 ms 636 KB Output is correct
13 Correct 2 ms 636 KB Output is correct
14 Correct 2 ms 636 KB Output is correct
15 Correct 2 ms 636 KB Output is correct
16 Correct 2 ms 636 KB Output is correct
17 Correct 2 ms 636 KB Output is correct
18 Correct 2 ms 636 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 3 ms 636 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 2 ms 636 KB Output is correct
31 Correct 2 ms 636 KB Output is correct
32 Correct 2 ms 636 KB Output is correct
33 Correct 2 ms 636 KB Output is correct
34 Correct 2 ms 636 KB Output is correct
35 Correct 2 ms 636 KB Output is correct
36 Correct 2 ms 636 KB Output is correct
37 Correct 2 ms 636 KB Output is correct
38 Correct 2 ms 636 KB Output is correct
39 Correct 2 ms 636 KB Output is correct
40 Correct 2 ms 636 KB Output is correct
41 Correct 2 ms 636 KB Output is correct
42 Correct 2 ms 636 KB Output is correct
43 Correct 2 ms 636 KB Output is correct
44 Correct 2 ms 636 KB Output is correct
45 Correct 2 ms 636 KB Output is correct
46 Correct 2 ms 636 KB Output is correct
47 Correct 2 ms 636 KB Output is correct
48 Correct 2 ms 636 KB Output is correct
49 Correct 2 ms 636 KB Output is correct
50 Correct 2 ms 636 KB Output is correct
51 Correct 2 ms 636 KB Output is correct
52 Correct 2 ms 636 KB Output is correct
53 Correct 2 ms 636 KB Output is correct
54 Correct 2 ms 636 KB Output is correct
55 Correct 2 ms 636 KB Output is correct
56 Correct 2 ms 636 KB Output is correct
57 Correct 2 ms 636 KB Output is correct
58 Correct 2 ms 636 KB Output is correct
59 Correct 2 ms 636 KB Output is correct
60 Correct 2 ms 636 KB Output is correct
61 Correct 2 ms 636 KB Output is correct
62 Correct 2 ms 636 KB Output is correct
63 Correct 2 ms 636 KB Output is correct
64 Correct 3 ms 636 KB Output is correct
65 Correct 2 ms 636 KB Output is correct
66 Correct 2 ms 636 KB Output is correct
67 Correct 2 ms 636 KB Output is correct
68 Correct 3 ms 636 KB Output is correct
69 Correct 4 ms 636 KB Output is correct
70 Correct 4 ms 644 KB Output is correct
71 Correct 2 ms 644 KB Output is correct
72 Correct 3 ms 644 KB Output is correct
73 Correct 4 ms 644 KB Output is correct
74 Correct 4 ms 644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 644 KB Output is correct
2 Correct 2 ms 644 KB Output is correct
3 Correct 2 ms 644 KB Output is correct
4 Correct 2 ms 644 KB Output is correct
5 Correct 2 ms 644 KB Output is correct
6 Correct 2 ms 644 KB Output is correct
7 Correct 2 ms 644 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 644 KB Output is correct
10 Correct 2 ms 644 KB Output is correct
11 Correct 2 ms 644 KB Output is correct
12 Correct 2 ms 644 KB Output is correct
13 Correct 2 ms 644 KB Output is correct
14 Correct 2 ms 644 KB Output is correct
15 Correct 2 ms 644 KB Output is correct
16 Correct 2 ms 644 KB Output is correct
17 Correct 2 ms 644 KB Output is correct
18 Correct 2 ms 644 KB Output is correct
19 Correct 2 ms 644 KB Output is correct
20 Correct 2 ms 644 KB Output is correct
21 Correct 2 ms 644 KB Output is correct
22 Correct 2 ms 644 KB Output is correct
23 Correct 2 ms 644 KB Output is correct
24 Correct 2 ms 644 KB Output is correct
25 Correct 2 ms 644 KB Output is correct
26 Correct 2 ms 644 KB Output is correct
27 Correct 2 ms 644 KB Output is correct
28 Correct 6 ms 644 KB Output is correct
29 Correct 2 ms 644 KB Output is correct
30 Correct 2 ms 644 KB Output is correct
31 Correct 2 ms 644 KB Output is correct
32 Correct 2 ms 644 KB Output is correct
33 Correct 2 ms 644 KB Output is correct
34 Correct 2 ms 644 KB Output is correct
35 Correct 3 ms 644 KB Output is correct
36 Correct 2 ms 644 KB Output is correct
37 Correct 2 ms 644 KB Output is correct
38 Correct 2 ms 644 KB Output is correct
39 Correct 2 ms 644 KB Output is correct
40 Correct 2 ms 644 KB Output is correct
41 Correct 2 ms 644 KB Output is correct
42 Correct 2 ms 644 KB Output is correct
43 Correct 2 ms 644 KB Output is correct
44 Correct 2 ms 644 KB Output is correct
45 Correct 2 ms 644 KB Output is correct
46 Correct 3 ms 644 KB Output is correct
47 Correct 2 ms 644 KB Output is correct
48 Correct 2 ms 644 KB Output is correct
49 Correct 2 ms 644 KB Output is correct
50 Correct 2 ms 644 KB Output is correct
51 Correct 3 ms 644 KB Output is correct
52 Correct 10 ms 644 KB Output is correct
53 Correct 14 ms 644 KB Output is correct
54 Correct 24 ms 644 KB Output is correct
55 Correct 22 ms 644 KB Output is correct
56 Correct 90 ms 760 KB Output is correct
57 Correct 113 ms 760 KB Output is correct
58 Correct 80 ms 760 KB Output is correct
59 Correct 110 ms 760 KB Output is correct
60 Correct 90 ms 760 KB Output is correct
61 Correct 2 ms 760 KB Output is correct
62 Correct 14 ms 764 KB Output is correct
63 Correct 26 ms 764 KB Output is correct
64 Correct 23 ms 764 KB Output is correct
65 Correct 41 ms 880 KB Output is correct
66 Correct 64 ms 1000 KB Output is correct
67 Correct 184 ms 1020 KB Output is correct
68 Correct 91 ms 1020 KB Output is correct
69 Correct 82 ms 1020 KB Output is correct