답안 #168670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168670 2019-12-14T23:52:30 Z Milki Bali Sculptures (APIO15_sculpture) C++14
50 / 100
346 ms 32124 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 183 ms 31864 KB Output is correct
2 Correct 160 ms 31864 KB Output is correct
3 Correct 218 ms 31872 KB Output is correct
4 Correct 160 ms 31904 KB Output is correct
5 Correct 158 ms 31864 KB Output is correct
6 Correct 182 ms 31864 KB Output is correct
7 Correct 164 ms 31868 KB Output is correct
8 Correct 169 ms 31900 KB Output is correct
9 Correct 153 ms 31864 KB Output is correct
10 Correct 179 ms 31964 KB Output is correct
11 Correct 234 ms 31904 KB Output is correct
12 Correct 209 ms 31992 KB Output is correct
13 Correct 179 ms 31864 KB Output is correct
14 Correct 149 ms 31844 KB Output is correct
15 Incorrect 160 ms 31904 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 170 ms 31864 KB Output is correct
2 Correct 146 ms 31904 KB Output is correct
3 Correct 150 ms 31872 KB Output is correct
4 Correct 148 ms 31908 KB Output is correct
5 Correct 147 ms 31776 KB Output is correct
6 Correct 145 ms 31964 KB Output is correct
7 Correct 165 ms 31864 KB Output is correct
8 Correct 217 ms 31872 KB Output is correct
9 Correct 208 ms 31836 KB Output is correct
10 Correct 164 ms 31992 KB Output is correct
11 Correct 164 ms 31864 KB Output is correct
12 Correct 202 ms 31864 KB Output is correct
13 Correct 191 ms 31872 KB Output is correct
14 Correct 205 ms 31992 KB Output is correct
15 Incorrect 171 ms 31992 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 31736 KB Output is correct
2 Correct 168 ms 31868 KB Output is correct
3 Correct 189 ms 31864 KB Output is correct
4 Correct 178 ms 31864 KB Output is correct
5 Correct 177 ms 31864 KB Output is correct
6 Correct 153 ms 31760 KB Output is correct
7 Correct 150 ms 31996 KB Output is correct
8 Correct 173 ms 31868 KB Output is correct
9 Correct 163 ms 31864 KB Output is correct
10 Correct 203 ms 31864 KB Output is correct
11 Correct 199 ms 31868 KB Output is correct
12 Correct 192 ms 31864 KB Output is correct
13 Correct 158 ms 31876 KB Output is correct
14 Correct 166 ms 31864 KB Output is correct
15 Correct 184 ms 31992 KB Output is correct
16 Correct 175 ms 31904 KB Output is correct
17 Correct 202 ms 31868 KB Output is correct
18 Correct 201 ms 31768 KB Output is correct
19 Correct 175 ms 31964 KB Output is correct
20 Correct 139 ms 31864 KB Output is correct
21 Correct 139 ms 31864 KB Output is correct
22 Correct 145 ms 31864 KB Output is correct
23 Correct 173 ms 31880 KB Output is correct
24 Correct 168 ms 31864 KB Output is correct
25 Correct 172 ms 31864 KB Output is correct
26 Correct 168 ms 31872 KB Output is correct
27 Correct 194 ms 31872 KB Output is correct
28 Correct 159 ms 31872 KB Output is correct
29 Correct 147 ms 31872 KB Output is correct
30 Correct 174 ms 31892 KB Output is correct
31 Correct 202 ms 31872 KB Output is correct
32 Correct 209 ms 31836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 31864 KB Output is correct
2 Correct 155 ms 31864 KB Output is correct
3 Correct 168 ms 31868 KB Output is correct
4 Correct 274 ms 31868 KB Output is correct
5 Correct 302 ms 31864 KB Output is correct
6 Correct 302 ms 31992 KB Output is correct
7 Correct 284 ms 31992 KB Output is correct
8 Correct 151 ms 31864 KB Output is correct
9 Correct 271 ms 31992 KB Output is correct
10 Correct 272 ms 31864 KB Output is correct
11 Correct 320 ms 31864 KB Output is correct
12 Correct 166 ms 31992 KB Output is correct
13 Correct 265 ms 31992 KB Output is correct
14 Correct 168 ms 31864 KB Output is correct
15 Incorrect 200 ms 31864 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 185 ms 31992 KB Output is correct
2 Correct 208 ms 31964 KB Output is correct
3 Correct 339 ms 31864 KB Output is correct
4 Correct 204 ms 31880 KB Output is correct
5 Correct 182 ms 31868 KB Output is correct
6 Correct 163 ms 31864 KB Output is correct
7 Correct 166 ms 31864 KB Output is correct
8 Correct 181 ms 31904 KB Output is correct
9 Correct 152 ms 31884 KB Output is correct
10 Correct 190 ms 31872 KB Output is correct
11 Correct 162 ms 31864 KB Output is correct
12 Correct 173 ms 31868 KB Output is correct
13 Correct 187 ms 31864 KB Output is correct
14 Correct 204 ms 31868 KB Output is correct
15 Correct 201 ms 31864 KB Output is correct
16 Correct 200 ms 31992 KB Output is correct
17 Correct 171 ms 31864 KB Output is correct
18 Correct 138 ms 31864 KB Output is correct
19 Correct 159 ms 31904 KB Output is correct
20 Correct 173 ms 31992 KB Output is correct
21 Correct 132 ms 31852 KB Output is correct
22 Correct 147 ms 31864 KB Output is correct
23 Correct 184 ms 31864 KB Output is correct
24 Correct 184 ms 31868 KB Output is correct
25 Correct 177 ms 31888 KB Output is correct
26 Correct 151 ms 31864 KB Output is correct
27 Correct 158 ms 31868 KB Output is correct
28 Correct 184 ms 31864 KB Output is correct
29 Correct 206 ms 31864 KB Output is correct
30 Correct 160 ms 31780 KB Output is correct
31 Correct 164 ms 31872 KB Output is correct
32 Correct 196 ms 31864 KB Output is correct
33 Correct 236 ms 31864 KB Output is correct
34 Correct 178 ms 31864 KB Output is correct
35 Correct 238 ms 31864 KB Output is correct
36 Correct 189 ms 31992 KB Output is correct
37 Correct 213 ms 31864 KB Output is correct
38 Correct 226 ms 31868 KB Output is correct
39 Correct 213 ms 31864 KB Output is correct
40 Correct 233 ms 31964 KB Output is correct
41 Correct 208 ms 31864 KB Output is correct
42 Correct 212 ms 31964 KB Output is correct
43 Correct 202 ms 31992 KB Output is correct
44 Correct 175 ms 31900 KB Output is correct
45 Correct 215 ms 31864 KB Output is correct
46 Correct 177 ms 31864 KB Output is correct
47 Correct 166 ms 31992 KB Output is correct
48 Correct 176 ms 31904 KB Output is correct
49 Correct 211 ms 31864 KB Output is correct
50 Correct 245 ms 31992 KB Output is correct
51 Correct 207 ms 31964 KB Output is correct
52 Correct 346 ms 31836 KB Output is correct
53 Correct 208 ms 31992 KB Output is correct
54 Correct 220 ms 31964 KB Output is correct
55 Correct 327 ms 31864 KB Output is correct
56 Correct 209 ms 32124 KB Output is correct
57 Correct 235 ms 32028 KB Output is correct
58 Correct 238 ms 32024 KB Output is correct
59 Correct 274 ms 31992 KB Output is correct
60 Correct 281 ms 32024 KB Output is correct
61 Correct 235 ms 31864 KB Output is correct
62 Correct 232 ms 31864 KB Output is correct
63 Correct 197 ms 31952 KB Output is correct
64 Correct 197 ms 31952 KB Output is correct
65 Correct 228 ms 31980 KB Output is correct
66 Correct 258 ms 32020 KB Output is correct
67 Correct 266 ms 32032 KB Output is correct
68 Correct 324 ms 31992 KB Output is correct
69 Correct 280 ms 31992 KB Output is correct