結果

問題 No.1185 完全な3の倍数
ユーザー a01sa01to
提出日時 2025-07-10 01:18:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 3,211 ms
コンパイル使用メモリ 281,172 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2025-07-10 01:18:32
合計ジャッジ時間 6,735 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
#else
  #define Debug(...) void(0)
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  set<int> s;
  function<void(ll)> dfs = [&](ll x) {
    if (x > n) return;
    if (x >= 100) s.insert(x);
    if (x != 0) dfs(x * 10 + 0);
    dfs(x * 10 + 3);
    dfs(x * 10 + 6);
    dfs(x * 10 + 9);
  };
  dfs(0);
  for (int x = 10; x <= min(n, 99); ++x) {
    if (((x / 10) + (x % 10)) % 3 == 0) s.insert(x);
  }
  //Debug(s);
  cout << s.size() << '\n';
  return 0;
}
0