結果

問題 No.3254 Xor, Max and Sum
コンテスト
ユーザー OnjoujiToki
提出日時 2025-12-14 07:04:34
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 632 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 711 ms
コンパイル使用メモリ 90,836 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-14 07:04:36
合計ジャッジ時間 2,403 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cmath>
#include <cstdint>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

int main() {
  int n, m;
  std::cin >> n >> m;
  if (n % 2 == 0) {
    std::cout << 1LL * n * m << "\n";
    return 0;
  }
  long long ans = 0;

  int msb = 31 - __builtin_clz(m);
  int free_elements = 0;
  for (int i = msb; i >= 0; i--) {
    if (m >> i & 1) {
      ans += 1LL * (n - 1) * (1 << i);
      free_elements += 1;
      if (free_elements >= n) {
        free_elements = n;
      }
    } else {
      ans += 1LL * (free_elements / 2 * 2) * (1 << i);
    } 
    
  }
  std::cout << ans << "\n";

  return 0;
}
0