結果
問題 | No.1912 Get together 2 |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-10-23 15:37:29 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 302 ms / 2,000 ms |
コード長 | 2,206 bytes |
コンパイル時間 | 2,738 ms |
コンパイル使用メモリ | 107,312 KB |
実行使用メモリ | 41,304 KB |
最終ジャッジ日時 | 2023-09-04 18:38:55 |
合計ジャッジ時間 | 11,313 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,384 KB |
testcase_06 | AC | 1 ms
4,384 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 31 ms
6,864 KB |
testcase_09 | AC | 22 ms
4,424 KB |
testcase_10 | AC | 43 ms
9,716 KB |
testcase_11 | AC | 29 ms
5,108 KB |
testcase_12 | AC | 45 ms
12,908 KB |
testcase_13 | AC | 297 ms
36,700 KB |
testcase_14 | AC | 297 ms
36,820 KB |
testcase_15 | AC | 301 ms
37,252 KB |
testcase_16 | AC | 302 ms
38,756 KB |
testcase_17 | AC | 298 ms
36,724 KB |
testcase_18 | AC | 294 ms
37,248 KB |
testcase_19 | AC | 292 ms
37,192 KB |
testcase_20 | AC | 290 ms
41,304 KB |
testcase_21 | AC | 288 ms
37,012 KB |
testcase_22 | AC | 288 ms
36,800 KB |
testcase_23 | AC | 287 ms
36,680 KB |
testcase_24 | AC | 288 ms
36,356 KB |
testcase_25 | AC | 289 ms
38,060 KB |
testcase_26 | AC | 291 ms
36,364 KB |
testcase_27 | AC | 287 ms
37,120 KB |
testcase_28 | AC | 79 ms
20,788 KB |
testcase_29 | AC | 77 ms
18,616 KB |
testcase_30 | AC | 81 ms
20,416 KB |
testcase_31 | AC | 73 ms
19,708 KB |
testcase_32 | AC | 75 ms
19,616 KB |
testcase_33 | AC | 281 ms
37,880 KB |
testcase_34 | AC | 2 ms
4,380 KB |
testcase_35 | AC | 284 ms
37,188 KB |
ソースコード
import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const N = readInt; const M = readInt; auto V = new long[N]; foreach (i; 0 .. N) { V[i] = readLong; } auto S = new string[N]; foreach (i; 0 .. N) { S[i] = readToken; } auto fs = new long[1 << M]; foreach (i; 0 .. N) { int p; foreach (j; 0 .. M) if (S[i][j] == 'o') { p |= 1 << j; } fs[p] += V[i]; } // xx???? foreach (j; 0 .. M) { foreach (p; 0 .. 1 << M) if (!(p & 1 << j)) { fs[p | 1 << j] += fs[p]; } } const all = (1 << M) - 1; auto dp = new long[1 << M]; foreach (p; 0 .. 1 << M) { foreach (j; 0 .. M) if (!(p & 1 << j)) { // xxo??? = xx???? - xxx??? const pp = p | 1 << j; const score = fs[all - p] - fs[all - pp]; chmax(dp[pp], dp[p] + score^^2); } } writeln(dp[$ - 1]); } } catch (EOFException e) { } }