結果

問題 No.2067 ±2^k operations
ユーザー QCFiumQCFium
提出日時 2022-09-02 22:42:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,436 bytes
コンパイル時間 1,715 ms
コンパイル使用メモリ 168,328 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 05:00:20
合計ジャッジ時間 4,214 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 35 ms
4,384 KB
testcase_02 AC 35 ms
4,384 KB
testcase_03 AC 36 ms
4,384 KB
testcase_04 AC 35 ms
4,380 KB
testcase_05 AC 35 ms
4,380 KB
testcase_06 AC 29 ms
4,380 KB
testcase_07 AC 68 ms
4,380 KB
testcase_08 AC 69 ms
4,380 KB
testcase_09 AC 68 ms
4,384 KB
testcase_10 AC 69 ms
4,384 KB
testcase_11 AC 69 ms
4,384 KB
testcase_12 AC 67 ms
4,384 KB
testcase_13 AC 68 ms
4,380 KB
testcase_14 AC 68 ms
4,380 KB
testcase_15 AC 68 ms
4,380 KB
testcase_16 AC 68 ms
4,380 KB
testcase_17 AC 68 ms
4,384 KB
testcase_18 AC 67 ms
4,380 KB
testcase_19 AC 17 ms
4,384 KB
testcase_20 AC 17 ms
4,380 KB
testcase_21 AC 61 ms
4,380 KB
testcase_22 AC 63 ms
4,384 KB
testcase_23 AC 61 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

void solve() {
	int64_t t;
	std::cin >> t;
	std::vector<int> dd;
	while (t) dd.push_back(t & 1), t >>= 1;
	
	std::pair<int64_t, int64_t> dp[3][2][2];
	memset(dp, 0, sizeof(dp));
	dp[1][0][0] = {1, 0};
	
	for (auto d : dd) {
		std::pair<int64_t, int64_t> next[3][2][2];
		memset(next, 0, sizeof(next));
		for (int j = 0; j < 3; j++) for (int k = 0; k < 2; k++) for (int l = 0; l < 2; l++) if (dp[j][k][l].first) {
			for (int m = 0; m < 2; m++) {
				int next_j = j;
				if (m < d) next_j = 0;
				if (m > d) next_j = 2;
				int next_k = m;
				int next_l = l;
				if (!k && !m) next_l = 0;
				if (k && m) next_l = 1;
				int cost = m && (!k || !l);
				next[next_j][next_k][next_l].first += dp[j][k][l].first;
				next[next_j][next_k][next_l].second += dp[j][k][l].first * cost;
				next[next_j][next_k][next_l].second += dp[j][k][l].second;
			}
		}
		memcpy(dp, next, sizeof(dp));
		/*
		for (int j = 0; j < 3; j++) for (int k = 0; k < 2; k++) for (int l = 0; l < 2; l++) if (dp[j][k][l].first) {
			std::cerr << j << " " << k << " " << l << " : " << dp[j][k][l].first << " " << dp[j][k][l].second << std::endl;
		}*/
	}
	int64_t res = 0;
	for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) res += dp[0][i][j].second + dp[1][i][j].second;
	printf("%" PRId64 "\n", res);
}
int main() {
	int t = ri();
	for (int i = 0; i < t; i++) solve();
	return 0;
}
0