結果

問題 No.1185 完全な3の倍数
ユーザー bluemeganebluemegane
提出日時 2021-10-29 18:34:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 3,979 ms
コンパイル使用メモリ 105,088 KB
実行使用メモリ 36,736 KB
最終ジャッジ日時 2024-04-16 13:26:37
合計ジャッジ時間 7,763 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
36,352 KB
testcase_01 AC 24 ms
18,688 KB
testcase_02 AC 24 ms
18,688 KB
testcase_03 AC 112 ms
36,608 KB
testcase_04 AC 112 ms
36,480 KB
testcase_05 AC 112 ms
36,352 KB
testcase_06 AC 111 ms
36,352 KB
testcase_07 AC 111 ms
36,352 KB
testcase_08 AC 25 ms
18,688 KB
testcase_09 AC 23 ms
18,560 KB
testcase_10 AC 23 ms
18,560 KB
testcase_11 AC 23 ms
18,560 KB
testcase_12 AC 24 ms
18,688 KB
testcase_13 AC 24 ms
18,560 KB
testcase_14 AC 24 ms
18,560 KB
testcase_15 AC 24 ms
18,560 KB
testcase_16 AC 23 ms
18,688 KB
testcase_17 AC 23 ms
18,432 KB
testcase_18 AC 24 ms
18,432 KB
testcase_19 AC 25 ms
18,688 KB
testcase_20 AC 82 ms
29,440 KB
testcase_21 AC 54 ms
25,728 KB
testcase_22 AC 53 ms
25,984 KB
testcase_23 AC 24 ms
18,944 KB
testcase_24 AC 82 ms
29,568 KB
testcase_25 AC 24 ms
18,816 KB
testcase_26 AC 53 ms
25,856 KB
testcase_27 AC 24 ms
18,688 KB
testcase_28 AC 80 ms
29,568 KB
testcase_29 AC 55 ms
25,984 KB
testcase_30 AC 55 ms
25,856 KB
testcase_31 AC 25 ms
19,072 KB
testcase_32 AC 114 ms
36,736 KB
testcase_33 AC 38 ms
21,684 KB
testcase_34 AC 81 ms
29,440 KB
testcase_35 AC 113 ms
36,224 KB
testcase_36 AC 80 ms
29,440 KB
testcase_37 AC 81 ms
29,440 KB
testcase_38 AC 54 ms
25,984 KB
testcase_39 AC 23 ms
18,432 KB
testcase_40 AC 25 ms
19,072 KB
testcase_41 AC 24 ms
18,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Collections.Generic;
using System.Linq;
using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        Console.WriteLine(getAns(n));
    }
    static int getAns(int n)
    {
        if (n <= 99) return n / 3 - 3;
        var d = n.ToString().Length;
        var ans = (int)Pow(4, d - 1) + 14;
        var k = "0369";
        var k2 = new int[] { 3, 6, 9 };
        var q = new Queue<string>();
        var p1 = n.ToString()[0] - '0';
        foreach (var x in k2)
            if (x <= p1) q.Enqueue(x.ToString());
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w.Length == d)
            {
                if (int.Parse(w) <= n) ans++;
            }
            else foreach (var x in k) q.Enqueue(w + x);
        }
        return ans;
    }
}
0