Submission #243373

# Submission time Handle Problem Language Result Execution time Memory
243373 2020-07-01T01:12:21 Z neihcr7j Bali Sculptures (APIO15_sculpture) C++14
0 / 100
5 ms 384 KB
#include<bits/stdc++.h>

#define maxn 2005

#define submask(mask1, mask2) ((mask1 ^ mask2) == mask1 - mask2)

using namespace std;
typedef long long ll;

int n;
int l, r;

int a[maxn];

bool check(int ret, int is) {
  if (l == 1) {
    vector < int > d(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
      d[i] = r + 1;
      for (int j = i - 1; j >= 0; --j)
        if (submask(ret >> is, (a[i] - a[j]) >> is))
          d[i] = min(d[i], d[j] + 1);
    }

    return d[n] <= r;
  }
  else {
    vector < vector < int > > d(n + 1, vector < int >(n + 1, 0));
    for (int i = 1; i <= n; ++i)
      for (int k = 1; k <= r && k <= i; ++k)
        for (int j = i - 1; j >= 0 && !d[i][k]; --j)
          if (submask(ret >> is, (a[i] - a[j]) >> is))
            d[i][k] |= d[j][k - 1];

    for (int k = l; k <= r; ++k)
      if (d[n][k])
        return 1;
    return 0;
  }
}

int main(){
  #define TASK "ABC"
  //freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n;

  cin >> l >> r;

  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    a[i] += a[i - 1];
  }

  int ret = 0;

  for (int i = 30; i >= 0; --i)
    if (!check(ret, i))
      ret += (1 << i);

  cout << ret;

  return 0;
}

Compilation message

sculpture.cpp: In function 'bool check(int, int)':
sculpture.cpp:5:57: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
 #define submask(mask1, mask2) ((mask1 ^ mask2) == mask1 - mask2)
sculpture.cpp:21:28:
         if (submask(ret >> is, (a[i] - a[j]) >> is))
                            ~~~~~~~~~~~~~~~~~             
sculpture.cpp:21:13: note: in expansion of macro 'submask'
         if (submask(ret >> is, (a[i] - a[j]) >> is))
             ^~~~~~~
sculpture.cpp:5:57: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
 #define submask(mask1, mask2) ((mask1 ^ mask2) == mask1 - mask2)
sculpture.cpp:32:30:
           if (submask(ret >> is, (a[i] - a[j]) >> is))
                              ~~~~~~~~~~~~~~~~~           
sculpture.cpp:32:15: note: in expansion of macro 'submask'
           if (submask(ret >> is, (a[i] - a[j]) >> is))
               ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -