結果

問題 No.1185 完全な3の倍数
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-08-22 17:48:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,116 bytes
コンパイル時間 1,562 ms
コンパイル使用メモリ 167,196 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 00:29:02
合計ジャッジ時間 3,154 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,376 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 5 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 6 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 5 ms
4,380 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 6 ms
4,376 KB
testcase_23 AC 5 ms
4,376 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 6 ms
4,380 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 5 ms
4,380 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 5 ms
4,380 KB
testcase_32 AC 5 ms
4,384 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 5 ms
4,380 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 6 ms
4,380 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 5 ms
4,380 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 5 ms
4,380 KB
testcase_41 AC 5 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.22 17:48:54
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

bool ok(int x) {
    if (x % 3 != 0) return false;
    vector<int> v;
    while(x) {
        v.push_back(x % 10);
        x /= 10;
    }
    for (int i = 0; i < v.size(); i++) {
        for (int j = i + 1; j < v.size(); j++) {
            if ((v[i] + v[j]) % 3 != 0) {
                return false;
            }
        }
    }
    return true;
}
int n,cnt;
void dfs(int keta, vector<int> &v) {
    if (keta == 9) {
        int p = 0;
        int k = 1;
        for (int i = 0; i < 9; i++) {
            p += k * v[i];
            k *= 10;
        }
        if (100 <= p && p <= n) {
            
            cnt++;
        }
    }
    else {
        for (int i = 0; i <= 9; i+=3) {
            v.push_back(i);
            dfs(keta+1,v);
            v.pop_back();
        }
    }
}
int main() {
    cin >> n;
    for (int i = 12; i <= min(99,n); i++) {
        if (ok(i)) cnt++;
    }
    vector<int> v;
    dfs(0,v);
    cout << cnt << endl;
    return 0;
}
0