답안 #45721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
45721 2018-04-16T04:41:45 Z Just_Solve_The_Problem Bali Sculptures (APIO15_sculpture) C++11
9 / 100
1000 ms 760 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 n, a, b;
int ar[N];
ll dp[N][N];
ll pref[N];

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

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];
  }
  ll mn = 1e18;
  for (int mask = 0; mask < (1 << n); mask++) {
    int ones = (int)__builtin_popcount(mask);
    if ((mask >> (n - 1)) & 1 ^ 1) ones++;
    if (a <= ones && ones <= b) {
      vector < int > v;
      for (int j = 0; j < n; j++) {
        if ((mask >> j) & 1) {
          v.pb(j + 1);
        }
      }
      ll ans = 0;
      if (v.empty()) {
        ans = pref[n];
      } else {
        for (int j = 1; j < sz(v); j++) {
          ans |= get(v[j - 1] + 1, v[j]);
        }
        ans |= pref[v[0]];
        ans |= get(v.back() + 1, n);
      }
      mn = min(mn, ans);
      v.clear();
    }
  }
  cout << mn;
}

Compilation message

sculpture.cpp:30:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
sculpture.cpp: In function 'int main()':
sculpture.cpp:39:27: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
     if ((mask >> (n - 1)) & 1 ^ 1) ones++;
         ~~~~~~~~~~~~~~~~~~^~~
sculpture.cpp:31: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:33: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 380 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
3 Correct 2 ms 476 KB Output is correct
4 Correct 2 ms 552 KB Output is correct
5 Correct 2 ms 552 KB Output is correct
6 Correct 12 ms 552 KB Output is correct
7 Correct 3 ms 552 KB Output is correct
8 Correct 12 ms 676 KB Output is correct
9 Correct 14 ms 684 KB Output is correct
10 Correct 8 ms 684 KB Output is correct
11 Correct 8 ms 684 KB Output is correct
12 Correct 8 ms 684 KB Output is correct
13 Correct 335 ms 684 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 2 ms 684 KB Output is correct
16 Correct 2 ms 684 KB Output is correct
17 Correct 2 ms 684 KB Output is correct
18 Correct 2 ms 684 KB Output is correct
19 Correct 2 ms 684 KB Output is correct
20 Correct 3 ms 684 KB Output is correct
21 Correct 32 ms 684 KB Output is correct
22 Correct 31 ms 684 KB Output is correct
23 Correct 32 ms 684 KB Output is correct
24 Correct 8 ms 684 KB Output is correct
25 Correct 34 ms 684 KB Output is correct
26 Correct 311 ms 732 KB Output is correct
27 Correct 2 ms 732 KB Output is correct
28 Correct 2 ms 732 KB Output is correct
29 Correct 4 ms 732 KB Output is correct
30 Correct 5 ms 732 KB Output is correct
31 Correct 34 ms 732 KB Output is correct
32 Correct 9 ms 732 KB Output is correct
33 Correct 305 ms 732 KB Output is correct
34 Correct 343 ms 732 KB Output is correct
35 Correct 9 ms 732 KB Output is correct
36 Correct 343 ms 732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 2 ms 732 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 11 ms 732 KB Output is correct
7 Correct 2 ms 732 KB Output is correct
8 Correct 14 ms 732 KB Output is correct
9 Correct 8 ms 732 KB Output is correct
10 Correct 8 ms 732 KB Output is correct
11 Correct 8 ms 732 KB Output is correct
12 Correct 8 ms 732 KB Output is correct
13 Correct 337 ms 732 KB Output is correct
14 Correct 2 ms 732 KB Output is correct
15 Correct 2 ms 732 KB Output is correct
16 Correct 2 ms 732 KB Output is correct
17 Correct 2 ms 732 KB Output is correct
18 Correct 2 ms 732 KB Output is correct
19 Correct 2 ms 732 KB Output is correct
20 Correct 3 ms 732 KB Output is correct
21 Correct 31 ms 732 KB Output is correct
22 Correct 33 ms 732 KB Output is correct
23 Correct 30 ms 732 KB Output is correct
24 Correct 9 ms 732 KB Output is correct
25 Correct 31 ms 732 KB Output is correct
26 Correct 304 ms 732 KB Output is correct
27 Correct 673 ms 732 KB Output is correct
28 Execution timed out 1055 ms 732 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 2 ms 732 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 11 ms 732 KB Output is correct
7 Correct 4 ms 732 KB Output is correct
8 Correct 8 ms 732 KB Output is correct
9 Correct 8 ms 732 KB Output is correct
10 Correct 8 ms 732 KB Output is correct
11 Correct 10 ms 732 KB Output is correct
12 Correct 8 ms 732 KB Output is correct
13 Correct 353 ms 732 KB Output is correct
14 Correct 685 ms 732 KB Output is correct
15 Execution timed out 1078 ms 732 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 732 KB Output is correct
2 Correct 2 ms 732 KB Output is correct
3 Correct 2 ms 732 KB Output is correct
4 Correct 2 ms 732 KB Output is correct
5 Correct 2 ms 732 KB Output is correct
6 Correct 11 ms 732 KB Output is correct
7 Correct 3 ms 732 KB Output is correct
8 Correct 8 ms 732 KB Output is correct
9 Correct 8 ms 732 KB Output is correct
10 Correct 8 ms 732 KB Output is correct
11 Correct 10 ms 732 KB Output is correct
12 Correct 8 ms 732 KB Output is correct
13 Correct 331 ms 732 KB Output is correct
14 Correct 2 ms 732 KB Output is correct
15 Correct 2 ms 732 KB Output is correct
16 Correct 2 ms 732 KB Output is correct
17 Correct 2 ms 760 KB Output is correct
18 Correct 2 ms 760 KB Output is correct
19 Correct 2 ms 760 KB Output is correct
20 Correct 3 ms 760 KB Output is correct
21 Correct 32 ms 760 KB Output is correct
22 Correct 34 ms 760 KB Output is correct
23 Correct 31 ms 760 KB Output is correct
24 Correct 8 ms 760 KB Output is correct
25 Correct 31 ms 760 KB Output is correct
26 Correct 318 ms 760 KB Output is correct
27 Correct 2 ms 760 KB Output is correct
28 Correct 2 ms 760 KB Output is correct
29 Correct 6 ms 760 KB Output is correct
30 Correct 5 ms 760 KB Output is correct
31 Correct 32 ms 760 KB Output is correct
32 Correct 13 ms 760 KB Output is correct
33 Correct 383 ms 760 KB Output is correct
34 Correct 370 ms 760 KB Output is correct
35 Correct 9 ms 760 KB Output is correct
36 Correct 346 ms 760 KB Output is correct
37 Correct 827 ms 760 KB Output is correct
38 Execution timed out 1071 ms 760 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 760 KB Output is correct
2 Correct 2 ms 760 KB Output is correct
3 Correct 2 ms 760 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 2 ms 760 KB Output is correct
6 Correct 19 ms 760 KB Output is correct
7 Correct 3 ms 760 KB Output is correct
8 Correct 10 ms 760 KB Output is correct
9 Correct 12 ms 760 KB Output is correct
10 Correct 9 ms 760 KB Output is correct
11 Correct 8 ms 760 KB Output is correct
12 Correct 11 ms 760 KB Output is correct
13 Correct 466 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 760 KB Output is correct
16 Correct 5 ms 760 KB Output is correct
17 Correct 5 ms 760 KB Output is correct
18 Correct 31 ms 760 KB Output is correct
19 Correct 8 ms 760 KB Output is correct
20 Correct 311 ms 760 KB Output is correct
21 Correct 378 ms 760 KB Output is correct
22 Correct 8 ms 760 KB Output is correct
23 Correct 359 ms 760 KB Output is correct
24 Correct 701 ms 760 KB Output is correct
25 Execution timed out 1077 ms 760 KB Time limit exceeded
26 Halted 0 ms 0 KB -