結果

問題 No.1185 完全な3の倍数
ユーザー f843nmfwisfeuwf843nmfwisfeuw
提出日時 2020-08-30 11:39:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,318 bytes
コンパイル時間 967 ms
コンパイル使用メモリ 96,644 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 01:48:38
合計ジャッジ時間 8,205 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

vector<long> ps = {0, 3, 6, 9};

long m(long x, long k) {
    if (x > k) {
        return 0;
    }

    cout << x << endl;

    long cnt = 1;
    for (long i = 0; i < 4; ++i) {
        cnt += m(x * 10 + ps[i], k);
    }
    return cnt;
}

int main() {

    vector<long> xs;
    for (long i = 10; i < 100; ++i) {
        if (i % 3 == 0 and ((i / 10) + (i % 10)) % 3 == 0) {
            xs.push_back(i);
        }
    }

    long N;
    cin >> N;

    if (N < 100) {
        long cnt = 0;
        for (long i = 0; i < xs.size(); ++i) {
            if (xs[i] <= N) {
                cnt += 1;
            }
        }
        cout << cnt << endl;
    } else {

        long cnt = xs.size();
        vector<long> ys;
        for (long i = 0; i < xs.size(); ++i) {
            if ((xs[i] % 10) % 3 == 0 and (xs[i] / 10) % 3 == 0) {
                ys.push_back(xs[i]);
            }
        }
        cnt -= ys.size();
        for (long i = 0; i < ys.size(); ++i) {
            cnt += m(ys[i], N);
        }

        cout << cnt << endl;
    }

}
0