Submission #334558

# Submission time Handle Problem Language Result Execution time Memory
334558 2020-12-09T11:59:25 Z neihcr7j Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>

#define submask(i, j) ((i ^ j) == (i - j))
#define maxn 100005

using namespace std;
typedef long long ll;

int n, A, B;
ll f[maxn];

bool check(ll mask, int index) {
  if (A == 1) {
    vector < int > d(n + 1, B + 1);

    d[0] = 0;

    for (int i = 1; i <= n; ++i)
      for (int j = 0; j < i; ++j)
        if (submask((f[i] - f[j]) >> index, mask >> index))
          d[i] = min(d[i], d[j] + 1);

    return d[n] <= B;
  }
  else {
    vector < vector < int > > d(n + 1, vector < int >(n + 1, 0));

    d[0][0] = 1;

    for (int i = 1; i <= n; ++i)
      for (int j = 0; j < i; ++j)
        if (submask((f[i] - f[j]) >> index, mask >> index))
          for (int k = 1; k <= n; ++k)
            d[i][k] |= d[j][k - 1];

    for (int i = A; i <= B; ++i)
      if (d[n][i])
        return 1;
    return 0;
  }
}

int main() {
  #define TASK "ABC"

  if (fopen(TASK".INP", "r")) {
    freopen(TASK".INP", "r", stdin);
    freopen(TASK".OUT", "w", stdout);
  }

  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  cin >> n >> A >> B;

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

  ll ans = 0;

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

  cout << ans;

  return 0;
}

Compilation message

sculpture.cpp: In function 'bool check(ll, int)':
sculpture.cpp:3:38: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
    3 | #define submask(i, j) ((i ^ j) == (i - j))
......
   20 |         if (submask((f[i] - f[j]) >> index, mask >> index))
      |                                      ~~~~~~~~~~~
sculpture.cpp:20:13: note: in expansion of macro 'submask'
   20 |         if (submask((f[i] - f[j]) >> index, mask >> index))
      |             ^~~~~~~
sculpture.cpp:3:38: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
    3 | #define submask(i, j) ((i ^ j) == (i - j))
......
   32 |         if (submask((f[i] - f[j]) >> index, mask >> index))
      |                                      ~~~~~~~~~~~
sculpture.cpp:32:13: note: in expansion of macro 'submask'
   32 |         if (submask((f[i] - f[j]) >> index, mask >> index))
      |             ^~~~~~~
sculpture.cpp: In function 'int main()':
sculpture.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     freopen(TASK".INP", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   48 |     freopen(TASK".OUT", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -