結果

問題 No.398 ハーフパイプ(2)
ユーザー nebukuro09
提出日時 2017-03-09 10:42:36
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,743 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 116,080 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-12 07:15:01
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;
     
void main() {
    immutable long MAX = 100;
    
    auto N = readln.chomp.replace(".", "").to!long;
    N /= 25;

    long[] f = [1, 1, 2, 6, 24, 120, 720];
    long ans = 0;
    long tmp;
    
    foreach (a; 0..MAX+1) {
        foreach (b; a..MAX+1) {
            foreach (c; b..MAX+1) {
                auto d = N - a - b - c;
                if (d < c || d > MAX) continue;
                long[long] count;
                count[a] += 1;
                count[b] += 1;
                count[c] += 1;
                count[d] += 1;
                
                // a, a, b, c, d, d
                tmp = f[6];
                count[a] += 1;
                count[d] += 1;
                foreach (i; count.values) tmp /= f[i.to!int];
                count[a] -= 1;
                count[d] -= 1;
                ans += tmp;

                // a未満, a, b, c, d, d
                tmp = f[6];
                count[d] += 1;
                foreach (i; count.values) tmp /= f[i.to!int];
                count[d] -= 1;
                ans += tmp * a;

                // a, a, b, c, d, dより大きい
                tmp = f[6];
                count[a] += 1;
                foreach (i; count.values) tmp /= f[i.to!int];
                count[a] -= 1;
                ans += tmp * (MAX-d);

                // a未満, a, b, c, d, dより大きい
                tmp = f[6];
                foreach (i; count.values) tmp /= f[i.to!int];
                ans += tmp * a * (MAX-d);
            }
        }
    }

    ans.writeln;
}
0