結果

問題 No.1185 完全な3の倍数
コンテスト
ユーザー mmn15277198
提出日時 2021-07-11 16:47:38
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 808 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 779 ms
コンパイル使用メモリ 121,620 KB
実行使用メモリ 24,064 KB
最終ジャッジ日時 2026-03-23 06:43:32
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

const long long MOD = (long long)(1e9) + 7;

map<string , int> mp;
long long n;
int d;

void dfs(string s) {
  if (s.size() > d) {
    return;
  }

  long long now = 0;
  for (int i = 0; i < s.size(); i++) {
    now *= 10LL;
    now += s[i] - '0';
  }
  
  if (now > n) {
    return;
  }

  mp[s]++;
  dfs(s + "3");
  dfs(s + "6");
  dfs(s + "9");
  dfs(s + "0");

  return;
}

int main() {

  //cout << fixed << setprecision(15);

  cin >> n;
  d = to_string(n).size();
  
  for (int i = 12; i <= min(99LL , n); i += 3) {
    mp[to_string(i)]++;
  }

  dfs("3");
  dfs("6");
  dfs("9");

  cout << mp.size() - 3 << endl;

  return 0;
}
0