結果

問題 No.1246 ANDORゲーム(max)
ユーザー tnakao0123tnakao0123
提出日時 2020-10-03 14:07:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 667 ms / 2,000 ms
コード長 1,504 bytes
コンパイル時間 1,079 ms
コンパイル使用メモリ 99,240 KB
実行使用メモリ 202,372 KB
最終ジャッジ日時 2023-09-25 05:12:18
合計ジャッジ時間 11,475 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,216 KB
testcase_01 AC 4 ms
8,160 KB
testcase_02 AC 4 ms
8,220 KB
testcase_03 AC 4 ms
8,276 KB
testcase_04 AC 4 ms
8,168 KB
testcase_05 AC 4 ms
8,380 KB
testcase_06 AC 4 ms
8,232 KB
testcase_07 AC 4 ms
8,284 KB
testcase_08 AC 5 ms
8,500 KB
testcase_09 AC 4 ms
8,296 KB
testcase_10 AC 4 ms
8,160 KB
testcase_11 AC 18 ms
12,320 KB
testcase_12 AC 7 ms
8,908 KB
testcase_13 AC 8 ms
9,580 KB
testcase_14 AC 27 ms
14,620 KB
testcase_15 AC 27 ms
14,600 KB
testcase_16 AC 660 ms
200,500 KB
testcase_17 AC 660 ms
201,704 KB
testcase_18 AC 664 ms
202,264 KB
testcase_19 AC 659 ms
201,740 KB
testcase_20 AC 667 ms
202,300 KB
testcase_21 AC 661 ms
202,372 KB
testcase_22 AC 667 ms
202,292 KB
testcase_23 AC 28 ms
15,080 KB
testcase_24 AC 514 ms
201,588 KB
testcase_25 AC 515 ms
201,084 KB
testcase_26 AC 514 ms
201,324 KB
testcase_27 AC 35 ms
21,112 KB
testcase_28 AC 510 ms
194,988 KB
testcase_29 AC 506 ms
195,800 KB
testcase_30 AC 511 ms
194,216 KB
testcase_31 AC 59 ms
33,628 KB
testcase_32 AC 58 ms
33,604 KB
testcase_33 AC 59 ms
33,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1246.cc:  No.1246 ANDORゲーム(max) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef long long ll;
typedef map<int,ll> mil;

/* global variables */

int as[MAX_N];
mil dp[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  dp[0][t] = 0;
  for (int i = 0; i < n; i++) {
    mil &dp0 = dp[i], &dp1 = dp[i + 1];
    for (mil::iterator mit0 = dp0.begin(); mit0 != dp0.end(); mit0++) {
      int x0 = mit0->first;

      int ax = x0 & as[i];
      ll ad = mit0->second + abs(ax - x0);
      mil::iterator amit = dp1.find(ax);
      if (amit == dp1.end()) dp1[ax] = ad;
      else if (amit->second < ad) amit->second = ad;

      int ox = x0 | as[i];
      ll od = mit0->second + abs(ox - x0);
      mil::iterator omit = dp1.find(ox);
      if (omit == dp1.end()) dp1[ox] = od;
      else if (omit->second < od) omit->second = od;
    }
  }

  ll maxd = 0;
  for (mil::iterator mit = dp[n].begin(); mit != dp[n].end(); mit++)
    if (maxd < mit->second) maxd = mit->second;

  printf("%lld\n", maxd);
  return 0;
}
0