답안 #45939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45939 2018-04-16T14:12:14 Z Just_Solve_The_Problem Bali Sculptures (APIO15_sculpture) C++11
100 / 100
190 ms 16508 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define ok puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");

const int N = (int)2e3 + 7;
const int inf = (int)1e9 + 7;

int ar[N];
int dp[N];
int dpp[N][N];
int n, a, b;
ll pref[N];
ll ans;

ll get(int l, int r) {
  return pref[r] - pref[l - 1];
}

bool check1(ll x) {
  for (int i = 1; i <= n; i++) {
    dp[i] = inf;
    for (int j = i; j >= 1; j--) {
      if ((x | get(j, i)) == x) {
        dp[i] = min(dp[i], dp[j - 1] + 1);
      }
    }
  }
  return dp[n] <= b;
}

bool check(int x) {
  memset(dpp, 0, sizeof dpp);
  dpp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (int k = j; k >= 1; k--) {
        if ((ans | ((get(k, j) >> x) << x)) == ans) {
          dpp[i][j] |= dpp[i - 1][k - 1];
        }
      }
    }
  }
  for (int i = a; i <= b; i++) {
    if (dpp[i][n]) return 1;
  }
  return 0;
}

main() {
  scanf("%d %d %d", &n, &a, &b);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ar[i]);
    pref[i] = pref[i - 1] + ar[i];
  }
  if (a == 1) {
    for (int i = 40; i >= 0; i--) {
      if (!check1(ans + (1LL << i) - 1)) {
        ans += (1LL << i);
      }
    }
  } else {
    for (int k = 40; k >= 0; k--) {
      if (!check(k)) {
        ans += (1LL << k);
      }
    }
  }
  printf("%lld", ans);
}

Compilation message

sculpture.cpp:62:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
sculpture.cpp: In function 'int main()':
sculpture.cpp:63:8: 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:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &ar[i]);
     ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 488 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 75 ms 16316 KB Output is correct
15 Correct 72 ms 16340 KB Output is correct
16 Correct 69 ms 16444 KB Output is correct
17 Correct 87 ms 16468 KB Output is correct
18 Correct 82 ms 16468 KB Output is correct
19 Correct 67 ms 16468 KB Output is correct
20 Correct 83 ms 16468 KB Output is correct
21 Correct 59 ms 16468 KB Output is correct
22 Correct 67 ms 16468 KB Output is correct
23 Correct 66 ms 16468 KB Output is correct
24 Correct 68 ms 16468 KB Output is correct
25 Correct 89 ms 16468 KB Output is correct
26 Correct 80 ms 16468 KB Output is correct
27 Correct 2 ms 16468 KB Output is correct
28 Correct 2 ms 16468 KB Output is correct
29 Correct 2 ms 16468 KB Output is correct
30 Correct 2 ms 16468 KB Output is correct
31 Correct 2 ms 16468 KB Output is correct
32 Correct 2 ms 16468 KB Output is correct
33 Correct 2 ms 16468 KB Output is correct
34 Correct 2 ms 16468 KB Output is correct
35 Correct 3 ms 16468 KB Output is correct
36 Correct 2 ms 16468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16468 KB Output is correct
2 Correct 2 ms 16468 KB Output is correct
3 Correct 2 ms 16468 KB Output is correct
4 Correct 2 ms 16468 KB Output is correct
5 Correct 2 ms 16468 KB Output is correct
6 Correct 2 ms 16468 KB Output is correct
7 Correct 2 ms 16468 KB Output is correct
8 Correct 2 ms 16468 KB Output is correct
9 Correct 2 ms 16468 KB Output is correct
10 Correct 2 ms 16468 KB Output is correct
11 Correct 2 ms 16468 KB Output is correct
12 Correct 2 ms 16468 KB Output is correct
13 Correct 2 ms 16468 KB Output is correct
14 Correct 69 ms 16468 KB Output is correct
15 Correct 65 ms 16468 KB Output is correct
16 Correct 68 ms 16468 KB Output is correct
17 Correct 98 ms 16508 KB Output is correct
18 Correct 66 ms 16508 KB Output is correct
19 Correct 60 ms 16508 KB Output is correct
20 Correct 65 ms 16508 KB Output is correct
21 Correct 57 ms 16508 KB Output is correct
22 Correct 63 ms 16508 KB Output is correct
23 Correct 63 ms 16508 KB Output is correct
24 Correct 55 ms 16508 KB Output is correct
25 Correct 52 ms 16508 KB Output is correct
26 Correct 59 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 3 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
# 결과 실행 시간 메모리 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 3 ms 16508 KB Output is correct
20 Correct 3 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 3 ms 16508 KB Output is correct
28 Correct 2 ms 16508 KB Output is correct
29 Correct 3 ms 16508 KB Output is correct
30 Correct 3 ms 16508 KB Output is correct
31 Correct 3 ms 16508 KB Output is correct
32 Correct 3 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 61 ms 16508 KB Output is correct
15 Correct 59 ms 16508 KB Output is correct
16 Correct 67 ms 16508 KB Output is correct
17 Correct 105 ms 16508 KB Output is correct
18 Correct 59 ms 16508 KB Output is correct
19 Correct 90 ms 16508 KB Output is correct
20 Correct 68 ms 16508 KB Output is correct
21 Correct 84 ms 16508 KB Output is correct
22 Correct 54 ms 16508 KB Output is correct
23 Correct 53 ms 16508 KB Output is correct
24 Correct 70 ms 16508 KB Output is correct
25 Correct 80 ms 16508 KB Output is correct
26 Correct 66 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 3 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 3 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 3 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 3 ms 16508 KB Output is correct
52 Correct 3 ms 16508 KB Output is correct
53 Correct 2 ms 16508 KB Output is correct
54 Correct 2 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 3 ms 16508 KB Output is correct
60 Correct 2 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 3 ms 16508 KB Output is correct
64 Correct 135 ms 16508 KB Output is correct
65 Correct 66 ms 16508 KB Output is correct
66 Correct 79 ms 16508 KB Output is correct
67 Correct 110 ms 16508 KB Output is correct
68 Correct 130 ms 16508 KB Output is correct
69 Correct 121 ms 16508 KB Output is correct
70 Correct 184 ms 16508 KB Output is correct
71 Correct 133 ms 16508 KB Output is correct
72 Correct 145 ms 16508 KB Output is correct
73 Correct 174 ms 16508 KB Output is correct
74 Correct 190 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 3 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 3 ms 16508 KB Output is correct
36 Correct 3 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 2 ms 16508 KB Output is correct
40 Correct 2 ms 16508 KB Output is correct
41 Correct 3 ms 16508 KB Output is correct
42 Correct 2 ms 16508 KB Output is correct
43 Correct 3 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 3 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 3 ms 16508 KB Output is correct
52 Correct 11 ms 16508 KB Output is correct
53 Correct 20 ms 16508 KB Output is correct
54 Correct 28 ms 16508 KB Output is correct
55 Correct 26 ms 16508 KB Output is correct
56 Correct 109 ms 16508 KB Output is correct
57 Correct 104 ms 16508 KB Output is correct
58 Correct 93 ms 16508 KB Output is correct
59 Correct 87 ms 16508 KB Output is correct
60 Correct 109 ms 16508 KB Output is correct
61 Correct 2 ms 16508 KB Output is correct
62 Correct 16 ms 16508 KB Output is correct
63 Correct 31 ms 16508 KB Output is correct
64 Correct 27 ms 16508 KB Output is correct
65 Correct 52 ms 16508 KB Output is correct
66 Correct 70 ms 16508 KB Output is correct
67 Correct 116 ms 16508 KB Output is correct
68 Correct 93 ms 16508 KB Output is correct
69 Correct 94 ms 16508 KB Output is correct