結果

問題 No.1185 完全な3の倍数
ユーザー ninoinui
提出日時 2020-08-22 19:03:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 192,980 KB
最終ジャッジ日時 2025-01-13 11:36:55
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N;
  cin >> N;
  int ans = 0;
  auto dfs = [&](auto &&dfs, long n) -> void {
    if (n > N) return;
    if (n > 9) ans++;
    string s = to_string(n);
    for (int next = 0; next <= 9; next++) {
      for (int i = 0; i < s.size(); i++) {
        int tmp = s.at(i) - '0';
        if ((tmp + next) % 3) goto NG;
      }
      dfs(dfs, n * 10 + next);
      NG:;
    }
  };
  for (int i = 1; i <= 9; i++) dfs(dfs, i);
  cout << ans << "\n";
}
0