結果

問題 No.1185 完全な3の倍数
ユーザー mmn15277198mmn15277198
提出日時 2021-07-11 16:47:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 808 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 104,476 KB
実行使用メモリ 23,904 KB
最終ジャッジ日時 2023-09-14 20:14:08
合計ジャッジ時間 4,594 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
21,040 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 103 ms
20,016 KB
testcase_04 AC 118 ms
22,580 KB
testcase_05 AC 111 ms
21,620 KB
testcase_06 AC 105 ms
20,376 KB
testcase_07 AC 105 ms
20,052 KB
testcase_08 AC 135 ms
23,904 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 33 ms
8,764 KB
testcase_20 AC 94 ms
18,908 KB
testcase_21 AC 64 ms
13,900 KB
testcase_22 AC 40 ms
9,796 KB
testcase_23 AC 33 ms
8,484 KB
testcase_24 AC 94 ms
18,912 KB
testcase_25 AC 9 ms
4,844 KB
testcase_26 AC 64 ms
13,644 KB
testcase_27 AC 33 ms
8,476 KB
testcase_28 AC 67 ms
14,296 KB
testcase_29 AC 55 ms
12,380 KB
testcase_30 AC 64 ms
13,616 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 110 ms
21,332 KB
testcase_33 AC 22 ms
6,932 KB
testcase_34 AC 95 ms
18,736 KB
testcase_35 AC 119 ms
22,572 KB
testcase_36 AC 95 ms
18,848 KB
testcase_37 AC 94 ms
18,736 KB
testcase_38 AC 64 ms
13,700 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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