結果

問題 No.1246 ANDORゲーム(max)
ユーザー risujirohrisujiroh
提出日時 2020-10-03 03:05:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,759 bytes
コンパイル時間 4,600 ms
コンパイル使用メモリ 378,140 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 04:37:29
合計ジャッジ時間 10,933 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 15 ms
4,380 KB
testcase_15 AC 15 ms
4,380 KB
testcase_16 AC 383 ms
4,376 KB
testcase_17 AC 385 ms
4,380 KB
testcase_18 AC 388 ms
4,376 KB
testcase_19 AC 385 ms
4,380 KB
testcase_20 AC 387 ms
4,376 KB
testcase_21 AC 389 ms
4,376 KB
testcase_22 AC 387 ms
4,380 KB
testcase_23 AC 17 ms
4,376 KB
testcase_24 AC 261 ms
4,380 KB
testcase_25 AC 259 ms
4,380 KB
testcase_26 AC 259 ms
4,376 KB
testcase_27 AC 19 ms
4,376 KB
testcase_28 AC 256 ms
4,376 KB
testcase_29 AC 258 ms
4,380 KB
testcase_30 AC 258 ms
4,376 KB
testcase_31 AC 28 ms
4,376 KB
testcase_32 AC 28 ms
4,376 KB
testcase_33 AC 28 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt")
// #define NDEBUG

#include <bits/extc++.h>
#include <x86intrin.h>

struct rep {
  struct iter {
    int i;
    constexpr void operator++() { ++i; }
    constexpr int operator*() const { return i; }
    friend constexpr bool operator!=(iter a, iter b) { return *a != *b; }
  };
  const int l, r;
  constexpr rep(int _l, int _r) : l(std::min(_l, _r)), r(_r) {}
  constexpr rep(int n) : rep(0, n) {}
  constexpr iter begin() const { return {l}; }
  constexpr iter end() const { return {r}; }
};
struct per {
  struct iter {
    int i;
    constexpr void operator++() { --i; }
    constexpr int operator*() const { return i; }
    friend constexpr bool operator!=(iter a, iter b) { return *a != *b; }
  };
  const int l, r;
  constexpr per(int _l, int _r) : l(std::min(_l, _r)), r(_r) {}
  constexpr per(int n) : per(0, n) {}
  constexpr iter begin() const { return {r - 1}; }
  constexpr iter end() const { return {l - 1}; }
};
template <class T, class U>
constexpr bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U>
constexpr bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

int main() {
  using namespace std;
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, x;
  cin >> n >> x;
  map<int, int64_t> dp;
  dp[x] = 0;
  while (n--) {
    int a;
    cin >> a;
    map<int, int64_t> ndp;
    for (auto [k, v] : dp) {
      chmax(ndp[k & a], v + abs((k & a) - k));
      chmax(ndp[k | a], v + abs((k | a) - k));
    }
    dp = move(ndp);
  }
  int64_t ans{};
  for (auto [k, v] : dp) chmax(ans, v);
  cout << ans << '\n';
}
0