Submission #168668

# Submission time Handle Problem Language Result Execution time Memory
168668 2019-12-14T23:47:06 Z Milki Bali Sculptures (APIO15_sculpture) C++14
71 / 100
355 ms 31992 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{
      if(rek_min(n - 1, forbidden) > n){
        forbidden ^= (1LL << i);
        sol |= (1LL << i);
      }
    }
  }
  cout << sol;
}
# Verdict Execution time Memory Grader output
1 Correct 199 ms 31864 KB Output is correct
2 Correct 191 ms 31864 KB Output is correct
3 Correct 204 ms 31992 KB Output is correct
4 Correct 210 ms 31868 KB Output is correct
5 Correct 213 ms 31784 KB Output is correct
6 Correct 229 ms 31908 KB Output is correct
7 Correct 200 ms 31992 KB Output is correct
8 Correct 191 ms 31876 KB Output is correct
9 Correct 201 ms 31900 KB Output is correct
10 Correct 190 ms 31904 KB Output is correct
11 Correct 185 ms 31864 KB Output is correct
12 Correct 189 ms 31864 KB Output is correct
13 Correct 170 ms 31992 KB Output is correct
14 Correct 195 ms 31864 KB Output is correct
15 Correct 208 ms 31864 KB Output is correct
16 Correct 208 ms 31868 KB Output is correct
17 Correct 228 ms 31868 KB Output is correct
18 Correct 212 ms 31992 KB Output is correct
19 Correct 187 ms 31864 KB Output is correct
20 Correct 193 ms 31864 KB Output is correct
21 Correct 181 ms 31900 KB Output is correct
22 Correct 192 ms 31992 KB Output is correct
23 Correct 156 ms 31880 KB Output is correct
24 Correct 192 ms 31864 KB Output is correct
25 Correct 174 ms 31992 KB Output is correct
26 Correct 251 ms 31992 KB Output is correct
27 Correct 159 ms 31836 KB Output is correct
28 Correct 190 ms 31876 KB Output is correct
29 Correct 203 ms 31908 KB Output is correct
30 Correct 206 ms 31908 KB Output is correct
31 Correct 162 ms 31836 KB Output is correct
32 Correct 180 ms 31864 KB Output is correct
33 Correct 180 ms 31864 KB Output is correct
34 Correct 161 ms 31964 KB Output is correct
35 Correct 202 ms 31904 KB Output is correct
36 Correct 191 ms 31824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 31864 KB Output is correct
2 Correct 177 ms 31900 KB Output is correct
3 Correct 203 ms 31864 KB Output is correct
4 Correct 191 ms 31864 KB Output is correct
5 Correct 225 ms 31900 KB Output is correct
6 Correct 188 ms 31836 KB Output is correct
7 Correct 159 ms 31864 KB Output is correct
8 Correct 247 ms 31864 KB Output is correct
9 Correct 174 ms 31992 KB Output is correct
10 Correct 206 ms 31864 KB Output is correct
11 Correct 203 ms 31900 KB Output is correct
12 Correct 323 ms 31976 KB Output is correct
13 Correct 228 ms 31864 KB Output is correct
14 Correct 173 ms 31864 KB Output is correct
15 Correct 301 ms 31864 KB Output is correct
16 Correct 259 ms 31992 KB Output is correct
17 Correct 193 ms 31864 KB Output is correct
18 Correct 259 ms 31992 KB Output is correct
19 Correct 200 ms 31864 KB Output is correct
20 Correct 191 ms 31908 KB Output is correct
21 Correct 239 ms 31864 KB Output is correct
22 Correct 212 ms 31992 KB Output is correct
23 Correct 182 ms 31868 KB Output is correct
24 Correct 207 ms 31868 KB Output is correct
25 Correct 249 ms 31904 KB Output is correct
26 Correct 215 ms 31864 KB Output is correct
27 Correct 232 ms 31808 KB Output is correct
28 Correct 217 ms 31864 KB Output is correct
29 Correct 239 ms 31864 KB Output is correct
30 Correct 187 ms 31864 KB Output is correct
31 Correct 250 ms 31864 KB Output is correct
32 Correct 202 ms 31868 KB Output is correct
33 Correct 241 ms 31992 KB Output is correct
34 Correct 199 ms 31864 KB Output is correct
35 Correct 254 ms 31880 KB Output is correct
36 Correct 250 ms 31868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 247 ms 31896 KB Output is correct
2 Correct 342 ms 31864 KB Output is correct
3 Correct 220 ms 31864 KB Output is correct
4 Correct 251 ms 31868 KB Output is correct
5 Correct 250 ms 31864 KB Output is correct
6 Correct 251 ms 31868 KB Output is correct
7 Correct 246 ms 31864 KB Output is correct
8 Correct 249 ms 31836 KB Output is correct
9 Correct 252 ms 31864 KB Output is correct
10 Correct 249 ms 31872 KB Output is correct
11 Correct 250 ms 31864 KB Output is correct
12 Correct 250 ms 31868 KB Output is correct
13 Correct 248 ms 31908 KB Output is correct
14 Correct 250 ms 31872 KB Output is correct
15 Correct 251 ms 31872 KB Output is correct
16 Correct 252 ms 31868 KB Output is correct
17 Correct 242 ms 31868 KB Output is correct
18 Correct 252 ms 31868 KB Output is correct
19 Correct 254 ms 31864 KB Output is correct
20 Correct 254 ms 31904 KB Output is correct
21 Correct 250 ms 31868 KB Output is correct
22 Correct 251 ms 31868 KB Output is correct
23 Correct 254 ms 31864 KB Output is correct
24 Correct 254 ms 31876 KB Output is correct
25 Correct 256 ms 31868 KB Output is correct
26 Correct 235 ms 31872 KB Output is correct
27 Correct 252 ms 31864 KB Output is correct
28 Correct 255 ms 31880 KB Output is correct
29 Correct 245 ms 31804 KB Output is correct
30 Correct 279 ms 31868 KB Output is correct
31 Correct 274 ms 31872 KB Output is correct
32 Correct 253 ms 31872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 251 ms 31876 KB Output is correct
2 Correct 247 ms 31904 KB Output is correct
3 Correct 254 ms 31864 KB Output is correct
4 Correct 255 ms 31868 KB Output is correct
5 Correct 249 ms 31868 KB Output is correct
6 Correct 251 ms 31864 KB Output is correct
7 Correct 248 ms 31992 KB Output is correct
8 Correct 246 ms 31836 KB Output is correct
9 Correct 251 ms 31836 KB Output is correct
10 Correct 254 ms 31864 KB Output is correct
11 Correct 249 ms 31876 KB Output is correct
12 Correct 252 ms 31876 KB Output is correct
13 Correct 248 ms 31872 KB Output is correct
14 Correct 195 ms 31864 KB Output is correct
15 Correct 285 ms 31864 KB Output is correct
16 Correct 336 ms 31872 KB Output is correct
17 Correct 264 ms 31868 KB Output is correct
18 Correct 255 ms 31864 KB Output is correct
19 Correct 247 ms 31872 KB Output is correct
20 Correct 247 ms 31872 KB Output is correct
21 Correct 247 ms 31884 KB Output is correct
22 Correct 249 ms 31776 KB Output is correct
23 Correct 252 ms 31864 KB Output is correct
24 Correct 247 ms 31960 KB Output is correct
25 Correct 245 ms 31864 KB Output is correct
26 Correct 247 ms 31864 KB Output is correct
27 Correct 247 ms 31988 KB Output is correct
28 Correct 245 ms 31864 KB Output is correct
29 Correct 246 ms 31764 KB Output is correct
30 Correct 352 ms 31964 KB Output is correct
31 Correct 353 ms 31864 KB Output is correct
32 Correct 194 ms 31864 KB Output is correct
33 Correct 212 ms 31828 KB Output is correct
34 Correct 226 ms 31880 KB Output is correct
35 Correct 236 ms 31864 KB Output is correct
36 Correct 308 ms 31872 KB Output is correct
37 Correct 255 ms 31868 KB Output is correct
38 Correct 355 ms 31872 KB Output is correct
39 Correct 267 ms 31864 KB Output is correct
40 Correct 257 ms 31872 KB Output is correct
41 Correct 208 ms 31864 KB Output is correct
42 Correct 230 ms 31864 KB Output is correct
43 Correct 211 ms 31872 KB Output is correct
44 Correct 210 ms 31864 KB Output is correct
45 Correct 245 ms 31868 KB Output is correct
46 Correct 305 ms 31872 KB Output is correct
47 Correct 200 ms 31868 KB Output is correct
48 Correct 239 ms 31868 KB Output is correct
49 Correct 254 ms 31868 KB Output is correct
50 Correct 231 ms 31868 KB Output is correct
51 Correct 249 ms 31864 KB Output is correct
52 Correct 252 ms 31872 KB Output is correct
53 Correct 281 ms 31868 KB Output is correct
54 Correct 257 ms 31872 KB Output is correct
55 Correct 256 ms 31876 KB Output is correct
56 Correct 252 ms 31864 KB Output is correct
57 Correct 256 ms 31864 KB Output is correct
58 Correct 255 ms 31876 KB Output is correct
59 Correct 252 ms 31928 KB Output is correct
60 Correct 245 ms 31864 KB Output is correct
61 Correct 257 ms 31940 KB Output is correct
62 Correct 244 ms 31992 KB Output is correct
63 Correct 245 ms 31876 KB Output is correct
64 Correct 253 ms 31872 KB Output is correct
65 Correct 252 ms 31988 KB Output is correct
66 Correct 215 ms 31856 KB Output is correct
67 Correct 265 ms 31868 KB Output is correct
68 Correct 253 ms 31872 KB Output is correct
69 Correct 241 ms 31868 KB Output is correct
70 Correct 233 ms 31876 KB Output is correct
71 Correct 242 ms 31872 KB Output is correct
72 Correct 232 ms 31872 KB Output is correct
73 Correct 241 ms 31868 KB Output is correct
74 Correct 242 ms 31872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 213 ms 31868 KB Output is correct
2 Correct 224 ms 31868 KB Output is correct
3 Correct 245 ms 31864 KB Output is correct
4 Correct 272 ms 31868 KB Output is correct
5 Correct 204 ms 31872 KB Output is correct
6 Correct 264 ms 31868 KB Output is correct
7 Correct 289 ms 31872 KB Output is correct
8 Correct 208 ms 31868 KB Output is correct
9 Correct 193 ms 31864 KB Output is correct
10 Correct 258 ms 31992 KB Output is correct
11 Correct 222 ms 31868 KB Output is correct
12 Correct 251 ms 31868 KB Output is correct
13 Correct 242 ms 31992 KB Output is correct
14 Correct 245 ms 31868 KB Output is correct
15 Correct 223 ms 31864 KB Output is correct
16 Correct 234 ms 31872 KB Output is correct
17 Correct 248 ms 31864 KB Output is correct
18 Correct 237 ms 31864 KB Output is correct
19 Correct 222 ms 31864 KB Output is correct
20 Correct 229 ms 31868 KB Output is correct
21 Correct 233 ms 31992 KB Output is correct
22 Correct 214 ms 31868 KB Output is correct
23 Correct 249 ms 31872 KB Output is correct
24 Correct 289 ms 31872 KB Output is correct
25 Correct 260 ms 31864 KB Output is correct
26 Correct 249 ms 31864 KB Output is correct
27 Correct 246 ms 31872 KB Output is correct
28 Correct 248 ms 31864 KB Output is correct
29 Correct 245 ms 31880 KB Output is correct
30 Correct 246 ms 31872 KB Output is correct
31 Correct 250 ms 31964 KB Output is correct
32 Correct 253 ms 31868 KB Output is correct
33 Correct 245 ms 31876 KB Output is correct
34 Correct 250 ms 31864 KB Output is correct
35 Correct 255 ms 31872 KB Output is correct
36 Correct 259 ms 31868 KB Output is correct
37 Correct 304 ms 31876 KB Output is correct
38 Correct 319 ms 31872 KB Output is correct
39 Correct 223 ms 31872 KB Output is correct
40 Correct 287 ms 31992 KB Output is correct
41 Correct 265 ms 31872 KB Output is correct
42 Correct 258 ms 31872 KB Output is correct
43 Correct 193 ms 31880 KB Output is correct
44 Correct 205 ms 31864 KB Output is correct
45 Correct 240 ms 31872 KB Output is correct
46 Correct 224 ms 31872 KB Output is correct
47 Correct 220 ms 31868 KB Output is correct
48 Correct 292 ms 31868 KB Output is correct
49 Correct 340 ms 31992 KB Output is correct
50 Correct 235 ms 31880 KB Output is correct
51 Incorrect 340 ms 31868 KB Output isn't correct
52 Halted 0 ms 0 KB -