結果

問題 No.2772 Appearing Even Times
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-06-01 01:43:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,078 ms / 4,000 ms
コード長 1,011 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 208,456 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-01 01:43:18
合計ジャッジ時間 15,090 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 811 ms
5,376 KB
testcase_09 AC 1,078 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 923 ms
5,376 KB
testcase_13 AC 946 ms
5,376 KB
testcase_14 AC 920 ms
5,376 KB
testcase_15 AC 947 ms
5,376 KB
testcase_16 AC 950 ms
5,376 KB
testcase_17 AC 921 ms
5,376 KB
testcase_18 AC 948 ms
5,376 KB
testcase_19 AC 973 ms
5,376 KB
testcase_20 AC 935 ms
5,376 KB
testcase_21 AC 940 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
using ll = mint;
int nxt(int bit, int t) {
	int ret = bit;
	if (bit & (1 << t)) {
		ret &= ~(1 << t);
	} else {
		ret |= (1 << t);
	}
	return ret;
}
int main()  {
	string X;cin >> X;
	int N = X.size();
	vector<vector<ll>> dp(1024, vector<ll>(2, 0));
	for (int i = 0;i < N;i++) {
		int nt = X[i] - '0';
		vector<vector<ll>> ndp(1024, vector<ll>(2, 0));
		if (i == 0) {
			for (int c = 1;c < nt;c++) ndp[nxt(0, c)][1]++;
			ndp[nxt(0, nt)][0]++;
			swap(dp, ndp);
			continue;
		}
		//leadin zero
		for (int c = 1;c < 10;c++) ndp[nxt(0, c)][1]++;
		for (int bit = 0;bit < 1024;bit++) {
			//from sml = true
			for (int c = 0;c < 10;c++) {
				ndp[nxt(bit, c)][1] += dp[bit][1];
			}
			//from sml = false;
			for (int c = 0;c < nt;c++) ndp[nxt(bit, c)][1] += dp[bit][0];
			ndp[nxt(bit, nt)][0] += dp[bit][0];
		}
		swap(dp, ndp);
	}
	cout << mint(dp[0][0] + dp[0][1]).val() << endl;
}
0