結果

問題 No.1185 完全な3の倍数
ユーザー れいん
提出日時 2025-05-27 00:18:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 3,188 ms
コンパイル使用メモリ 276,356 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-27 00:18:13
合計ジャッジ時間 4,273 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    if (N < 100)
    {
        cout << N / 3 - 3;
        return 0;
    }
    vector<int> A = {0, 3, 6, 9};
    int ans = 0;
    auto dfs = [&](auto dfs, long long v, int d) -> void
    {
        if (v > N)
        {
            return;
        }
        if (d >= 3)
        {
            ans++;
        }

        for (int i = 0; i < 4; i++)
        {
            dfs(dfs, v * 10 + A[i], d + 1);
        }
    };
    dfs(dfs, 3, 1);
    dfs(dfs, 6, 1);
    dfs(dfs, 9, 1);
    cout << ans + 30;
}
0