結果

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

ソースコード

diff #

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

long N, ans;

void dfs(int n) {
  if (n > N) return;
  if (n >= 10) ans++;
  string tmp = to_string(n);
  for (int next = 0; next <= 9; next++) {
    for (int i = 0; i < tmp.size(); i++) {
      int t = tmp.at(i) - '0';
      if ((t + next) % 3) goto NG;
    }
    dfs(n * 10 + next);
    NG:;
  }
}

int main() {
  cin >> N;
  for (int i = 1; i <= 9; i++) dfs(i);
  cout << ans << "\n";
}
0