結果

問題 No.357 品物の並び替え (Middle)
ユーザー nobuta05
提出日時 2022-04-01 21:51:12
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,673 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 143,968 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-22 14:45:43
合計ジャッジ時間 2,025 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import std.stdio, std.string, std.conv;
import std.algorithm, std.math;
import std.range;
import std.container.rbtree, std.container.dlist;
import std.container.binaryheap, std.container.array;
import std.typecons;
alias mstring = char[];
const long INF = 1L << 60L;
const long mod = 1_000_000_000 + 7;
void chmin(T)(ref T x, T y) {
x = min(x, y);
}
void chmax(T)(ref T x, T y) {
x = max(x, y);
}
//
// readln.chomp.to!int;
// or
// int a;
// readf("%s\n", a);
// ()
// readln.chomp.split.map!(to!long).array
// ()
// int a, b;
// readf("%s %s\n", &a, &b);
// (1-indexed)
// long[] vs = readln.chomp.split.map!(to!long).array;
// vs = [0L] ~ vs;
//
// double ret = 10.0;
// writefln("%.12f", ret);
// arr[$-1]
void main() {
int N, M;
readf("%s %s\n", &N, &M);
auto scores = new long[][](N + 1, N + 1);
foreach (i; 0 .. M) {
int u, v;
long scr;
readf("%s %s %s\n", &u, &v, &scr);
u++;
v++;
scores[u][v] = scr;
}
auto dp = new long[](1 << N);
foreach (s; 0 .. (1 << N))
foreach (v; 1 .. N + 1) {
if (s & (1 << (v - 1)))
continue;
long tot = 0L;
foreach (u; 1 .. N + 1) {
if ((s & (1 << (u - 1))) == 0)
continue;
tot += scores[u][v];
}
chmax(dp[s | (1 << (v - 1))], dp[s] + tot);
}
long ret = dp[(1 << N) - 1];
writeln(ret);
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0