結果

問題 No.1185 完全な3の倍数
ユーザー mikianaaamikianaaa
提出日時 2020-10-22 16:36:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,706 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 165,148 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-28 14:38:22
合計ジャッジ時間 3,852 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,500 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 2 ms
4,376 KB
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
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
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

ll count3(int a, bool j) {
    int res = 0;
    if (j) {
        for (int i = 0; i <= a; i++) {
            if (i % 3 == 0)
                res++;
        }
    } else {
        for (int i = 1; i <= a; i++) {
            if (i % 3 == 0)
                res++;
        }
    }
    return res;
}

ll cnt(int size) {
    ll res = 0;
    for (int i = 2; i < size - 1; i++) {
        res += 3 * pow(4, i);
    }

    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    int ans = 0;
    if (N < 300) {
        for (int i = 10; i <= N; i++) {
            if (i % 3 != 0)
                continue;
            string s = to_string(i);
            bool judge = 1;
            rep(j, s.size()) {
                for (int k = j + 1; k < s.size(); k++) {
                    if (((s[j] - '0') + (s[k] - '0')) % 3 != 0) {
                        judge = 0;
                        break;
                    }
                }
            }

            if (judge) {
                ans++;
            }
        }
    } else {
        ans = 30;
        ll res = 1;
        string s = to_string(N);
        rep(i, s.size()) {
            if (i == 0) {
                res *= count3(s[i] - '0', 0);
            } else {
                res *= count3(s[i] - '0', 1);
            }
        }

        ans += res;

        ans += cnt(s.size());
    }

    cout << ans << endl;
}
0