結果

問題 No.3242 Count 8 Included Numbers (Hard)
コンテスト
ユーザー Heart_Blue
提出日時 2025-12-19 19:00:35
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 1,277 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,482 ms
コンパイル使用メモリ 157,480 KB
実行使用メモリ 89,404 KB
最終ジャッジ日時 2025-12-19 19:00:42
合計ジャッジ時間 6,328 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 4 WA * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <string>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <iomanip>
#include <ctime>
#include <valarray>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e6 + 10;
const int mod = 998244353;
LL dp[N][2];
LL solve(string& str, int pos, int flag = 0, bool limit = true, bool lead = true)
{
	if (pos == -1)
	{
		return flag;
	}
	if (!limit && !lead && dp[pos][flag] != -1) return dp[pos][flag];
	int up = limit ? str[pos] - '0' : 9;
	LL ret = 0;
	for (int i = 0; i <= up; i++)
	{
		ret += solve(str, pos - 1, flag || i == 8, limit && i == str[pos] - '0', lead && i == 0);
	}
	ret %= mod;
	if (!limit && !lead)
		dp[pos][flag] = ret;
	return ret;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	MEM(dp, -1);
	string str;
	cin >> str;
	cout << solve(str, str.length() - 1) << endl;
	return 0;
}
0