結果

問題 No.1849 Three Times Value
ユーザー bluemeganebluemegane
提出日時 2023-08-23 20:04:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 759 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 62,748 KB
実行使用メモリ 23,304 KB
最終ジャッジ日時 2023-08-23 20:05:04
合計ジャッジ時間 4,590 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
22,896 KB
testcase_01 AC 50 ms
22,364 KB
testcase_02 AC 51 ms
20,464 KB
testcase_03 AC 59 ms
20,888 KB
testcase_04 AC 58 ms
18,928 KB
testcase_05 AC 58 ms
20,820 KB
testcase_06 AC 62 ms
21,248 KB
testcase_07 AC 49 ms
22,532 KB
testcase_08 AC 49 ms
20,368 KB
testcase_09 AC 57 ms
23,108 KB
testcase_10 AC 59 ms
23,304 KB
testcase_11 AC 58 ms
23,256 KB
testcase_12 AC 58 ms
21,240 KB
testcase_13 AC 57 ms
23,276 KB
testcase_14 AC 56 ms
21,100 KB
testcase_15 AC 57 ms
21,156 KB
testcase_16 AC 49 ms
20,372 KB
testcase_17 AC 49 ms
20,552 KB
testcase_18 AC 59 ms
20,860 KB
testcase_19 AC 57 ms
18,968 KB
testcase_20 AC 49 ms
20,300 KB
testcase_21 AC 50 ms
20,492 KB
testcase_22 AC 57 ms
20,808 KB
testcase_23 AC 49 ms
20,368 KB
testcase_24 AC 49 ms
20,312 KB
testcase_25 AC 49 ms
20,480 KB
testcase_26 AC 57 ms
21,180 KB
testcase_27 AC 50 ms
20,480 KB
testcase_28 AC 50 ms
20,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var s = Console.ReadLine().Trim();
        getAns(s);
    }
    static void getAns(string s)
    {
        var n = s.Length;
        if (n % 3 != 0)
        {
            var w = n / 3;
            Console.WriteLine(w > 0 ? new string('9', w) : "0");
        }
        else
        {
            var w = n / 3;
            var ws = s.Substring(0, w);
            var ww = int.Parse(ws);
            var www = long.Parse(ws + ws + ws);
            var ww2 = w > 1 ? int.Parse(new string('9', w - 1)) : 0;
            var ans = ww - (int)Pow(10, w - 1) + 1 + ww2;
            if (www > long.Parse(s)) ans--;
            Console.WriteLine(ans);
        }
    }
}
0