結果

問題 No.1185 完全な3の倍数
ユーザー hayaten
提出日時 2020-08-22 18:47:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 682 bytes
コンパイル時間 2,111 ms
コンパイル使用メモリ 190,812 KB
最終ジャッジ日時 2025-01-13 11:35:31
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18 TLE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
ll num[12] = {30, 33, 36, 39, 60, 63, 66, 69, 90, 93, 96, 99};
const ll three[4] = {0,3,6,9};
int ans;
int n;

void dfs(int num) {
  if(num > n)return;
  ans++;
  rep(i, 4) {
    if(num * 10 + three[i] > n)return;
    dfs(10 * num + three[i]);
  }
}

int main() {
  cin >> n;
  if(n <= 99){
    cout << n / 3 - 3 << endl;
    return 0;
  }
  ans = 30;
  rep(i, 12) {
    rep(j, 4) {
      dfs(num[i] * 10 + three[j]);
    }
  }
  cout << ans << endl;
}
0