結果

問題 No.1185 完全な3の倍数
コンテスト
ユーザー ooaiu
提出日時 2026-11-06 14:59:11
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 616µs
コード長 548 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,169 ms
コンパイル使用メモリ 340,404 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-11-06 14:59:19
合計ジャッジ時間 4,567 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
long dp[12][2];
int main() {
	string S;
	cin >> S;
	const int N = S.size();
	long ans = 0;
	dp[0][0] = 1;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < 2; j++) {
			int lim = j ? 9 : S[i] - '0';
			for(int d: {0,3,6,9}) if(d <= lim) {
				dp[i + 1][j || d < S[i]-'0'] += dp[i][j];
			}
		}
	}

	long tmp = dp[N][0] + dp[N][1] - 4;
	for(int x = 10; x < 100 && x <= stoll(S); x++) {
		int t = (x % 10) + (x / 10);
		if (t % 3 == 0 and ((x /10) % 3 != 0)) {
			tmp++;
		}
	}
	cout << tmp << endl;
}
0