답안 #168671

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168671 2019-12-14T23:53:07 Z Milki Bali Sculptures (APIO15_sculpture) C++14
100 / 100
346 ms 32064 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int mod = 1e9 + 7;

int add(int x, int y) {x += y; if(x >= mod) return x - mod; return x;}
int sub(int x, int y) {x -= y; if(x < 0) return x + mod; return x;}
int mul(int x, int y) {return (ll) x * y % mod;}

const int MAXN = 2e3 + 5;

ll n, a, b, x[MAXN], prefix[MAXN], dp1[MAXN], dp[MAXN][MAXN];

int rek(int pos, int num, ll forbidden){
  if(pos < 0){
    if(num >= a && num <= b)
      return 1;
    else
      return 0;
  }
  if(dp[pos][num] != -1)
    return dp[pos][num];

  int ret = 0;
  ll sum = 0;
  for(int i = pos; i >= 0; --i){
    sum += x[i];
    if((sum & forbidden) == 0)
      ret |= rek(i - 1, num + 1, forbidden);
    if(ret)
      return dp[pos][num] = ret;
  }

  return dp[pos][num] = ret;
}

int rek_min(int pos, ll forbidden){
  if(pos < 0)
    return 0;
  if(dp1[pos] != -1)
    return dp1[pos];

  int ret = 1e5;
  ll sum = 0;
  for(int i = pos; i >= 0; --i){
    sum += x[i];
    if((sum & forbidden) == 0)
      ret = min(ret, rek_min(i - 1, forbidden) + 1);
  }
  return dp1[pos] = ret;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);

  cin >> n >> a >> b;
  REP(i, n)
    cin >> x[i];

  ll forbidden = 0, sol = 0;
  for(int i = 40; i >= 0; --i){
    memset(dp1, -1, sizeof(dp1));
    memset(dp, -1, sizeof(dp));

    forbidden |= (1LL << i);
    if(n <= 100){
      if(!rek(n - 1, 0, forbidden)){
        forbidden ^= (1LL << i);
        sol |= (1LL << i);
      }
    }
    else{
      int val = rek_min(n - 1, forbidden);
      if(val > b){
        forbidden ^= (1LL << i);
        sol |= (1LL << i);
      }
    }
  }
  cout << sol;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 31868 KB Output is correct
2 Correct 228 ms 31868 KB Output is correct
3 Correct 207 ms 31868 KB Output is correct
4 Correct 216 ms 31864 KB Output is correct
5 Correct 233 ms 31864 KB Output is correct
6 Correct 251 ms 31964 KB Output is correct
7 Correct 229 ms 31868 KB Output is correct
8 Correct 346 ms 31992 KB Output is correct
9 Correct 166 ms 31868 KB Output is correct
10 Correct 156 ms 31864 KB Output is correct
11 Correct 143 ms 31864 KB Output is correct
12 Correct 172 ms 31864 KB Output is correct
13 Correct 168 ms 31864 KB Output is correct
14 Correct 212 ms 31864 KB Output is correct
15 Correct 144 ms 31784 KB Output is correct
16 Correct 136 ms 31864 KB Output is correct
17 Correct 137 ms 31864 KB Output is correct
18 Correct 164 ms 31864 KB Output is correct
19 Correct 228 ms 31872 KB Output is correct
20 Correct 218 ms 31864 KB Output is correct
21 Correct 169 ms 31784 KB Output is correct
22 Correct 191 ms 31992 KB Output is correct
23 Correct 169 ms 31864 KB Output is correct
24 Correct 166 ms 31864 KB Output is correct
25 Correct 187 ms 31992 KB Output is correct
26 Correct 156 ms 31872 KB Output is correct
27 Correct 162 ms 31904 KB Output is correct
28 Correct 180 ms 31864 KB Output is correct
29 Correct 172 ms 31864 KB Output is correct
30 Correct 161 ms 31992 KB Output is correct
31 Correct 211 ms 31864 KB Output is correct
32 Correct 219 ms 31864 KB Output is correct
33 Correct 195 ms 31992 KB Output is correct
34 Correct 150 ms 31908 KB Output is correct
35 Correct 157 ms 31864 KB Output is correct
36 Correct 175 ms 31864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 165 ms 31864 KB Output is correct
2 Correct 168 ms 31868 KB Output is correct
3 Correct 169 ms 31864 KB Output is correct
4 Correct 176 ms 31908 KB Output is correct
5 Correct 172 ms 31868 KB Output is correct
6 Correct 206 ms 31872 KB Output is correct
7 Correct 147 ms 31760 KB Output is correct
8 Correct 206 ms 31872 KB Output is correct
9 Correct 175 ms 31828 KB Output is correct
10 Correct 142 ms 31868 KB Output is correct
11 Correct 168 ms 31864 KB Output is correct
12 Correct 164 ms 31908 KB Output is correct
13 Correct 172 ms 31992 KB Output is correct
14 Correct 175 ms 31996 KB Output is correct
15 Correct 149 ms 31740 KB Output is correct
16 Correct 139 ms 31840 KB Output is correct
17 Correct 150 ms 31912 KB Output is correct
18 Correct 175 ms 31872 KB Output is correct
19 Correct 176 ms 31868 KB Output is correct
20 Correct 208 ms 31864 KB Output is correct
21 Correct 225 ms 31868 KB Output is correct
22 Correct 189 ms 31992 KB Output is correct
23 Correct 188 ms 31872 KB Output is correct
24 Correct 208 ms 31864 KB Output is correct
25 Correct 287 ms 31964 KB Output is correct
26 Correct 168 ms 31864 KB Output is correct
27 Correct 145 ms 31868 KB Output is correct
28 Correct 151 ms 31864 KB Output is correct
29 Correct 173 ms 31864 KB Output is correct
30 Correct 163 ms 31864 KB Output is correct
31 Correct 178 ms 31992 KB Output is correct
32 Correct 236 ms 31904 KB Output is correct
33 Correct 240 ms 31904 KB Output is correct
34 Correct 180 ms 31864 KB Output is correct
35 Correct 159 ms 31864 KB Output is correct
36 Correct 171 ms 31864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 31936 KB Output is correct
2 Correct 149 ms 31864 KB Output is correct
3 Correct 233 ms 31868 KB Output is correct
4 Correct 168 ms 31992 KB Output is correct
5 Correct 178 ms 31992 KB Output is correct
6 Correct 187 ms 31864 KB Output is correct
7 Correct 222 ms 31864 KB Output is correct
8 Correct 225 ms 31992 KB Output is correct
9 Correct 174 ms 31772 KB Output is correct
10 Correct 158 ms 31864 KB Output is correct
11 Correct 163 ms 31872 KB Output is correct
12 Correct 161 ms 31992 KB Output is correct
13 Correct 146 ms 31992 KB Output is correct
14 Correct 185 ms 31992 KB Output is correct
15 Correct 153 ms 31864 KB Output is correct
16 Correct 171 ms 31864 KB Output is correct
17 Correct 172 ms 31892 KB Output is correct
18 Correct 181 ms 31992 KB Output is correct
19 Correct 218 ms 31864 KB Output is correct
20 Correct 219 ms 31864 KB Output is correct
21 Correct 294 ms 31836 KB Output is correct
22 Correct 180 ms 31864 KB Output is correct
23 Correct 337 ms 31992 KB Output is correct
24 Correct 186 ms 31864 KB Output is correct
25 Correct 164 ms 31864 KB Output is correct
26 Correct 191 ms 31876 KB Output is correct
27 Correct 158 ms 31984 KB Output is correct
28 Correct 159 ms 31864 KB Output is correct
29 Correct 230 ms 31864 KB Output is correct
30 Correct 218 ms 31992 KB Output is correct
31 Correct 170 ms 31996 KB Output is correct
32 Correct 187 ms 31876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 31872 KB Output is correct
2 Correct 197 ms 31992 KB Output is correct
3 Correct 172 ms 31784 KB Output is correct
4 Correct 181 ms 31864 KB Output is correct
5 Correct 149 ms 31864 KB Output is correct
6 Correct 170 ms 31864 KB Output is correct
7 Correct 181 ms 31904 KB Output is correct
8 Correct 205 ms 31868 KB Output is correct
9 Correct 195 ms 31864 KB Output is correct
10 Correct 181 ms 31864 KB Output is correct
11 Correct 176 ms 31868 KB Output is correct
12 Correct 168 ms 31864 KB Output is correct
13 Correct 144 ms 31864 KB Output is correct
14 Correct 164 ms 31992 KB Output is correct
15 Correct 138 ms 31864 KB Output is correct
16 Correct 137 ms 31864 KB Output is correct
17 Correct 186 ms 31864 KB Output is correct
18 Correct 179 ms 31992 KB Output is correct
19 Correct 169 ms 31864 KB Output is correct
20 Correct 180 ms 31864 KB Output is correct
21 Correct 219 ms 31864 KB Output is correct
22 Correct 210 ms 31992 KB Output is correct
23 Correct 155 ms 31864 KB Output is correct
24 Correct 156 ms 31868 KB Output is correct
25 Correct 299 ms 31868 KB Output is correct
26 Correct 175 ms 31992 KB Output is correct
27 Correct 169 ms 31864 KB Output is correct
28 Correct 185 ms 31864 KB Output is correct
29 Correct 158 ms 31864 KB Output is correct
30 Correct 159 ms 31872 KB Output is correct
31 Correct 176 ms 31864 KB Output is correct
32 Correct 179 ms 31992 KB Output is correct
33 Correct 199 ms 31964 KB Output is correct
34 Correct 217 ms 31996 KB Output is correct
35 Correct 180 ms 31868 KB Output is correct
36 Correct 188 ms 31868 KB Output is correct
37 Correct 169 ms 31992 KB Output is correct
38 Correct 184 ms 31992 KB Output is correct
39 Correct 187 ms 31868 KB Output is correct
40 Correct 184 ms 31868 KB Output is correct
41 Correct 203 ms 31992 KB Output is correct
42 Correct 153 ms 31864 KB Output is correct
43 Correct 185 ms 31864 KB Output is correct
44 Correct 182 ms 31864 KB Output is correct
45 Correct 237 ms 31992 KB Output is correct
46 Correct 229 ms 31912 KB Output is correct
47 Correct 168 ms 31992 KB Output is correct
48 Correct 217 ms 31884 KB Output is correct
49 Correct 221 ms 31864 KB Output is correct
50 Correct 220 ms 31864 KB Output is correct
51 Correct 182 ms 31872 KB Output is correct
52 Correct 212 ms 31872 KB Output is correct
53 Correct 245 ms 31992 KB Output is correct
54 Correct 204 ms 31864 KB Output is correct
55 Correct 192 ms 31992 KB Output is correct
56 Correct 206 ms 31868 KB Output is correct
57 Correct 200 ms 31864 KB Output is correct
58 Correct 175 ms 31868 KB Output is correct
59 Correct 134 ms 31872 KB Output is correct
60 Correct 145 ms 31964 KB Output is correct
61 Correct 162 ms 31864 KB Output is correct
62 Correct 131 ms 31864 KB Output is correct
63 Correct 153 ms 31864 KB Output is correct
64 Correct 140 ms 31864 KB Output is correct
65 Correct 141 ms 31904 KB Output is correct
66 Correct 157 ms 31904 KB Output is correct
67 Correct 161 ms 31868 KB Output is correct
68 Correct 142 ms 31864 KB Output is correct
69 Correct 151 ms 31876 KB Output is correct
70 Correct 199 ms 31892 KB Output is correct
71 Correct 228 ms 31756 KB Output is correct
72 Correct 165 ms 31864 KB Output is correct
73 Correct 176 ms 31892 KB Output is correct
74 Correct 183 ms 31864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 31864 KB Output is correct
2 Correct 172 ms 31864 KB Output is correct
3 Correct 178 ms 31904 KB Output is correct
4 Correct 172 ms 31864 KB Output is correct
5 Correct 175 ms 31864 KB Output is correct
6 Correct 150 ms 31864 KB Output is correct
7 Correct 166 ms 31868 KB Output is correct
8 Correct 271 ms 31868 KB Output is correct
9 Correct 204 ms 31864 KB Output is correct
10 Correct 182 ms 31820 KB Output is correct
11 Correct 168 ms 31864 KB Output is correct
12 Correct 190 ms 31868 KB Output is correct
13 Correct 161 ms 31892 KB Output is correct
14 Correct 158 ms 31904 KB Output is correct
15 Correct 205 ms 31992 KB Output is correct
16 Correct 156 ms 31864 KB Output is correct
17 Correct 209 ms 31864 KB Output is correct
18 Correct 191 ms 31864 KB Output is correct
19 Correct 213 ms 31868 KB Output is correct
20 Correct 224 ms 31904 KB Output is correct
21 Correct 239 ms 31864 KB Output is correct
22 Correct 242 ms 31864 KB Output is correct
23 Correct 231 ms 31992 KB Output is correct
24 Correct 188 ms 31864 KB Output is correct
25 Correct 170 ms 31864 KB Output is correct
26 Correct 175 ms 31864 KB Output is correct
27 Correct 179 ms 31956 KB Output is correct
28 Correct 306 ms 31868 KB Output is correct
29 Correct 178 ms 31992 KB Output is correct
30 Correct 163 ms 31904 KB Output is correct
31 Correct 202 ms 31864 KB Output is correct
32 Correct 205 ms 31900 KB Output is correct
33 Correct 206 ms 31876 KB Output is correct
34 Correct 168 ms 31864 KB Output is correct
35 Correct 195 ms 31864 KB Output is correct
36 Correct 200 ms 31864 KB Output is correct
37 Correct 190 ms 31868 KB Output is correct
38 Correct 201 ms 31764 KB Output is correct
39 Correct 167 ms 31864 KB Output is correct
40 Correct 189 ms 31992 KB Output is correct
41 Correct 139 ms 31864 KB Output is correct
42 Correct 153 ms 31864 KB Output is correct
43 Correct 179 ms 31868 KB Output is correct
44 Correct 167 ms 31868 KB Output is correct
45 Correct 148 ms 31864 KB Output is correct
46 Correct 133 ms 31872 KB Output is correct
47 Correct 138 ms 31868 KB Output is correct
48 Correct 170 ms 31864 KB Output is correct
49 Correct 190 ms 31908 KB Output is correct
50 Correct 162 ms 31864 KB Output is correct
51 Correct 184 ms 31868 KB Output is correct
52 Correct 140 ms 31864 KB Output is correct
53 Correct 152 ms 31864 KB Output is correct
54 Correct 221 ms 31864 KB Output is correct
55 Correct 175 ms 31972 KB Output is correct
56 Correct 223 ms 31996 KB Output is correct
57 Correct 218 ms 32064 KB Output is correct
58 Correct 186 ms 31992 KB Output is correct
59 Correct 222 ms 32040 KB Output is correct
60 Correct 209 ms 31992 KB Output is correct
61 Correct 147 ms 31992 KB Output is correct
62 Correct 145 ms 31864 KB Output is correct
63 Correct 167 ms 31968 KB Output is correct
64 Correct 173 ms 31864 KB Output is correct
65 Correct 159 ms 31968 KB Output is correct
66 Correct 176 ms 31988 KB Output is correct
67 Correct 208 ms 32000 KB Output is correct
68 Correct 317 ms 32004 KB Output is correct
69 Correct 188 ms 32012 KB Output is correct