結果

問題 No.844 split game
ユーザー dot_haraaidot_haraai
提出日時 2021-06-01 22:15:49
言語 Nim
(2.0.2)
結果
AC  
実行時間 148 ms / 2,000 ms
コード長 2,038 bytes
コンパイル時間 5,310 ms
コンパイル使用メモリ 88,704 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-04-26 09:54:21
合計ジャッジ時間 9,047 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
8,576 KB
testcase_01 AC 51 ms
12,288 KB
testcase_02 AC 114 ms
12,672 KB
testcase_03 AC 87 ms
13,312 KB
testcase_04 AC 47 ms
7,680 KB
testcase_05 AC 129 ms
14,592 KB
testcase_06 AC 41 ms
7,680 KB
testcase_07 AC 37 ms
10,368 KB
testcase_08 AC 21 ms
6,144 KB
testcase_09 AC 91 ms
8,960 KB
testcase_10 AC 138 ms
14,336 KB
testcase_11 AC 134 ms
16,640 KB
testcase_12 AC 88 ms
8,320 KB
testcase_13 AC 55 ms
6,656 KB
testcase_14 AC 59 ms
10,880 KB
testcase_15 AC 146 ms
17,152 KB
testcase_16 AC 147 ms
17,152 KB
testcase_17 AC 148 ms
17,152 KB
testcase_18 AC 144 ms
17,152 KB
testcase_19 AC 143 ms
17,152 KB
testcase_20 AC 146 ms
17,152 KB
testcase_21 AC 144 ms
17,152 KB
testcase_22 AC 144 ms
17,152 KB
testcase_23 AC 6 ms
5,376 KB
testcase_24 AC 11 ms
5,376 KB
testcase_25 AC 7 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 9 ms
5,376 KB
testcase_28 AC 4 ms
5,376 KB
testcase_29 AC 9 ms
5,376 KB
testcase_30 AC 11 ms
5,376 KB
testcase_31 AC 9 ms
5,376 KB
testcase_32 AC 4 ms
5,376 KB
testcase_33 AC 12 ms
5,376 KB
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 14 ms
5,376 KB
testcase_36 AC 9 ms
5,376 KB
testcase_37 AC 21 ms
5,376 KB
testcase_38 AC 32 ms
6,528 KB
testcase_39 AC 66 ms
9,472 KB
testcase_40 AC 26 ms
8,448 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 1 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
testcase_57 AC 2 ms
5,376 KB
testcase_58 AC 2 ms
5,376 KB
testcase_59 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 18) Warning: Use the new 'sugar' module instead; future is deprecated [Deprecated]
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'times' [UnusedImport]
/home/judge/data/code/Main.nim(2, 26) Warning: imported and not used: 'strformat' [UnusedImport]
/home/judge/data/code/Main.nim(2, 18) Warning: imported and not used: 'future' [UnusedImport]
/home/judge/data/code/Main.nim(2, 37) Warning: imported and not used: 'deques' [UnusedImport]
/home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'critbits' [UnusedImport]
/home/judge/data/code/Main.nim(1, 73) Warning: imported and not used: 'intsets' [UnusedImport]
/home/judge/data/code/Main.nim(1, 60) Warning: imported and not used: 'sets' [UnusedImport]
/home/judge/data/code/Main.nim(1, 66) Warning: imported and not used: 'lists' [UnusedImport]

ソースコード

diff #

import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets
import critbits, future, strformat, deques
template `max=`(x,y) = x = max(x,y)
template `min=`(x,y) = x = min(x,y)
template `mod=`(x,y) = x = x mod y
template scan2 = (scan(), scan())
template scan3 = (scan(), scan())
let read* = iterator: string {.closure.} =
    while true: (for s in stdin.readLine.split: yield s)
proc scan(): int = read().parseInt
proc scanf(): float = read().parseFloat
proc toInt(c:char): int =
    return int(c) - int('0')



proc solveDP():int=
  var
    (n,m,a)=(scan(),scan(),scan())
    lrp = newseqwith(m,(scan(),scan(),scan()))
    le = newseqwith(n+2,newseq[int]())
    re = newseqwith(n+2,newseq[int]())
    dp = newseqwith(n+2,newseqwith(2,-int.high.div(4)))
  lrp = lrp.sorted()
  dp[1][1]=0
  for idx,(l,r,p) in lrp:
    le[l].add(idx)
    re[r].add(idx)
  for i in 1..n+1:
    #echo "i:", i
    if i>1:
      dp[i][0].max=max(dp[i-1][0],dp[i-1][1])
      dp[i][1].max=max(dp[i-1][0],dp[i-1][1])-a
    for idx in le[i]:
      #echo lrp[idx]
      if lrp[idx][1]==n:
        dp[lrp[idx][1]+1][1].max=max(lrp[idx][2]+dp[i][1],lrp[idx][2]+dp[i][0]-a)
      else:
        dp[lrp[idx][1]+1][1].max=max(lrp[idx][2]+dp[i][1],lrp[idx][2]+dp[i][0]-a)-a
    #echo dp.join("\n")
    #echo "###"
  return dp[n+1].max()




proc solve():int=
  var
    (n,m,a)=(scan(),scan(),scan())
    lrp = newseqwith(m,(scan()-1,scan()-1,scan()))
    le = newseqwith(n+1,newseq[int]())
    re = newseqwith(n+1,newseq[int]())
    memo = initTable[(int,int,),int]()
  lrp = lrp.sorted()
  for idx,(l,r,p) in lrp:
    le[l].add(idx)
    re[r].add(idx)

  # l-1とlのあいだ、rとr+1の間に黒線が存在するケース
  proc recSolve(l,r:int):int=
    echo l,", ", r
    if memo.hasKey((l,r)):
      return memo[(l,r)]
    for idx in le[l]:
      if lrp[idx][1]==r:
        result.max=lrp[idx][2]
    #
    for m in l..<r:
      result.max=(-a)+(recSolve(l,m)+recSolve(m+1,r))
    memo[(l,r)]=result
  return recSolve(0,n-1)

  
echo solveDP()
0