結果

問題 No.3431 popcount & sum (Easy)
コンテスト
ユーザー startcpp
提出日時 2026-01-11 14:02:42
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 748 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 779 ms
コンパイル使用メモリ 109,268 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-01-11 14:02:52
合計ジャッジ時間 1,358 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <atcoder/modint>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
using namespace atcoder;
using mint = modint998244353;

signed main() {
	int n;
	cin >> n;

	vector<int> bcnt(n + 1);
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < 20; j++) {
			if ((i >> j) % 2) bcnt[i]++;
		}
	}

	int ans = 0;
	for (int a = 0; a <= n; a++) {
		for (int b = a; b <= n; b++) {
			if (bcnt[a] == bcnt[b]) ans += a & b;
		}
	}
	ans %= 998244353;

	cout << ans << endl;
	return 0;
}
0