結果

問題 No.3254 Xor, Max and Sum
ユーザー tnakao0123
提出日時 2025-09-06 14:14:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 837 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 41,832 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-06 14:14:23
合計ジャッジ時間 1,719 ms
ジャッジサーバーID
(参考情報)
judge / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3254.cc:  No.3254 Xor, Max and Sum - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int BN = 30;

/* typedef */

using ll = long long;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  if (n == 1) { puts("0"); return 0; }
  if (! (n & 1)) { printf("%lld\n", (ll)m * n); return 0; }

  int as[3] = {};
  for (int i = BN - 1, bi = 1 << i; i >= 0; i--, bi >>= 1)
    if (bi <= m) {
      if (as[0] == 0) as[0] = as[1] = bi;
      else if (as[2] == 0 && (as[0] | bi) <= m) as[0] |= bi, as[2] = bi;
      else if ((as[1] | bi) <= m) as[1] |= bi, as[2] |= bi;
    }
  //printf(" %d %d %d\n", as[0], as[1], as[2]);

  ll s = (ll)m * (n - 3) + as[0] + as[1] + as[2];
  printf("%lld\n", s);

  return 0;
}
0