結果
問題 |
No.3254 Xor, Max and Sum
|
ユーザー |
![]() |
提出日時 | 2025-09-06 15:23:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 725 bytes |
コンパイル時間 | 328 ms |
コンパイル使用メモリ | 41,960 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-06 15:24:15 |
合計ジャッジ時間 | 1,739 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:25:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | scanf("%d%d", &n, &m); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3254.cc: No.3254 Xor, Max and Sum - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ /* 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 msi = 0; while ((1 << (msi + 1)) <= m) msi++; ll sum = 0; int f = 0; for (int i = msi, bi = 1 << i; i >= 0; i--, bi >>= 1) { if (m & bi) { sum += (ll)bi * (n - 1); if (f < n) f++; } else { sum += (ll)bi * ((f / 2) * 2); } } printf("%lld\n", sum); return 0; }