結果

問題 No.783 門松計画
ユーザー ikdikd
提出日時 2019-01-12 11:04:44
言語 Nim
(2.0.2)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 3,997 ms
コンパイル使用メモリ 68,816 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-30 18:40:46
合計ジャッジ時間 5,214 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import strutils, sequtils

proc ok(a, b, c: int): bool =
  result = (a!=b and b!=c and c!=a)
  result = result and ((a<b and b>c) or (a>b and b<c))

proc main() =
  let
    nc = stdin.readLine.split.map(parseInt)
    (n, c) = (nc[0], nc[1])
    ls = stdin.readLine.split.map(parseInt)
    ws = stdin.readLine.split.map(parseInt)
  var dp = newSeqWith(c+1, newSeqWith(51, newSeqWith(51, -1)))
  for i in 0..<n:
    for j in 0..<n:
      for k in 0..<n:
        if ok(ls[i], ls[j], ls[k]):
          let s = ws[i]+ws[j]+ws[k]
          if s<=c:
            dp[s][ls[j]][ls[k]] = max(
              dp[s][ls[j]][ls[k]], ls[i]+ls[j]+ls[k])
  for i in 0..c:
    for j in 0..<n:
      for k in 0..<n:
        if dp[i][ls[j]][ls[k]]>=0:
          for t in 0..<n:
            if ok(ls[j], ls[k], ls[t]):
              if i+ws[t]<=c:
                dp[i+ws[t]][ls[k]][ls[t]] = max(
                  dp[i+ws[t]][ls[k]][ls[t]], dp[i][ls[j]][ls[k]]+ls[t])
  var ans = 0
  for x in dp:
    for y in x:
      for z in y:
        ans = max(ans, z)
  echo ans
main()
0