結果
| 問題 | No.783 門松計画 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-01-11 22:57:47 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 33 ms / 2,000 ms | 
| コード長 | 2,146 bytes | 
| コンパイル時間 | 711 ms | 
| コンパイル使用メモリ | 108,728 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-13 02:40:22 | 
| 合計ジャッジ時間 | 1,624 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 27 | 
ソースコード
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;
enum inf = 1 << 30;
void main() {
    int n, c;
    scan(n, c);
    auto len = readln.split.to!(int[]);
    auto w = readln.split.to!(int[]);
    // dp(総コスト, 2個前の竹の長さ, 1個前の竹の長さ) = (竹の長さの総和のmax)
    auto dp = new int[][][](c + 1, 51, 51);
    fillAll(dp, -inf);
    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. n) {
            if (len[i] == len[j]) continue;
            if (w[i] + w[j] > c) continue;
            debug {
                writefln("%d, %d, %d", w[i] + w[j], len[i], len[j]);
            }
            dp[w[i] + w[j]][len[i]][len[j]] = max(dp[w[i] + w[j]][len[i]][len[j]], len[i] + len[j]);
        }
    }
    int ans;
    foreach (ci ; 0 .. c + 1) {
        foreach (i ; 0 .. 51) {
            foreach (j ; 0 .. 51) {
                if (dp[ci][i][j] == -inf) continue;
                foreach (k ; 0 .. n) {
                    if (len[k] == i || len[k] == j) continue;
                    if (i < j && j < len[k]) continue;
                    if (i > j && j > len[k]) continue;
                    if (ci + w[k] > c) continue;
                    debug {
                        writefln("(%d, %d, %d)", i, j, len[k]);
                    }
                    dp[ci + w[k]][j][len[k]] = max(dp[ci + w[k]][j][len[k]], dp[ci][i][j] + len[k]);
                    ans = max(ans, dp[ci + w[k]][j][len[k]]);
                }
            }
        }
    }
    writeln(ans);
}
void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;
    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}
void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}
            
            
            
        