結果

問題 No.220 世界のなんとか2
ユーザー nanaenanae
提出日時 2017-06-10 17:04:42
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,203 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 105,600 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 14:14:30
合計ジャッジ時間 1,748 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.string, std.conv, std.range, std.array, std.algorithm;
import std.uni, std.math, std.container, std.typecons, std.typetuple;
import core.bitop, std.datetime;

immutable long mod = 10^^9 + 7;

void main(){
    auto p = readln.chomp.to!int;
    auto s = "1" ~ repeat("0", p).join;

    //s.writeln;

    long ans = nabeatsu(s, false) - 1;

    writeln(ans);
}

long nabeatsu(string n, bool miman){
    int L = n.length.to!int;
    auto dp = new long[][][][](L + 1, 2, 2, 3);
    dp[0][0][0][0] = 1;

    foreach(i ; 0 .. L) foreach(j ; 0 .. 2) foreach(k ; 0 .. 2) foreach(l ; 0 .. 3) {
        for(int d = 0; d <= (j ? 9 : n[i] - '0'); d++){
            dp[i + 1][j || (d < n[i] - '0')][k || (d == 3)][(l + d) % 3] += dp[i][j][k][l];
        }
    }

    long ans;

    foreach(j ; 0 .. 2) foreach(k ; 0 .. 2) foreach(l ; 0 .. 3) {
        if (k || (l == 0)) {
            ans += dp[L][j][k][l];
        }
    }

    return ans;
}


void readVars(T...)(auto ref T args){
    auto line = readln.split;
    foreach(ref arg ; args){
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    if(!line.empty){
        throw new Exception("args num < input num");
    }
}
0