結果

問題 No.1185 完全な3の倍数
ユーザー SSRS
提出日時 2020-08-22 13:09:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 654 bytes
コンパイル時間 1,595 ms
コンパイル使用メモリ 169,108 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 09:03:29
合計ジャッジ時間 3,295 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int ans = 0;
  int D = to_string(N).size();
  for (int i = 0; i < (1 << (D * 2)); i++){
    string S;
    for (int j = 0; j < D; j++){
      int tmp = i >> (j * 2) & 3;
      S += tmp * 3 + '0';
    }
    if (S <= to_string(N)){  
      while (!S.empty() && S[0] == '0'){
        S.erase(S.begin());
      }
      if (S.size() > 1){
        ans++;
      }
    }
  }
  for (int i = 1; i <= 9; i++){
    for (int j = 0; j <= 9; j++){
      if ((i * 10 + j) % 3 == 0 && !(i % 3 == 0 && j % 3 == 0) && i * 10 + j <= N){
        ans++;
      }
    }
  }
  cout << ans << endl;
}
0