結果

問題 No.1375 Divide and Update
ユーザー dot_haraaidot_haraai
提出日時 2021-06-06 12:52:35
言語 Nim
(2.0.2)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 2,753 bytes
コンパイル時間 4,665 ms
コンパイル使用メモリ 87,296 KB
実行使用メモリ 37,504 KB
最終ジャッジ日時 2024-11-22 19:18:31
合計ジャッジ時間 11,780 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 1 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 2 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 309 ms
32,640 KB
testcase_11 AC 290 ms
30,336 KB
testcase_12 AC 158 ms
17,664 KB
testcase_13 AC 134 ms
15,360 KB
testcase_14 AC 359 ms
36,608 KB
testcase_15 AC 367 ms
36,608 KB
testcase_16 AC 371 ms
36,608 KB
testcase_17 AC 364 ms
36,608 KB
testcase_18 AC 359 ms
37,504 KB
testcase_19 AC 356 ms
37,504 KB
testcase_20 AC 346 ms
34,944 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(1, 41) Warning: imported and not used: 'algorithm' [UnusedImport]
/home/judge/data/code/Main.nim(1, 52) Warning: imported and not used: 'tables' [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]
/home/judge/data/code/Main.nim(1, 73) Warning: imported and not used: 'intsets' [UnusedImport]
/home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'critbits' [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 solve()=
  var
    n = scan()
    x = scan()
    y = scan()
    a = newseqwith(n,scan())
    
    ax = newseqwith(n,0)
    cx = newseqwith(n,0)
    minIdxX = newseqwith(n+1,0)
    choicex = newseqwith(n,newseqwith(3,-int.high.div(4)))
    ay = newseqwith(n,0)
    cy = newseqwith(n,0)
    minIdxY = newseqwith(n+1,0)
    choicey = newseqwith(n,newseqwith(3,-int.high.div(4)))

  # i番目の要素をx,yに置き換えたときのうれしさ
  for i in 0..<n:
    ax[i] = x - a[i]
    ay[i] = y - a[i]


  # 両側からの累積和を用意
  cx[0] = ax[0]
  cy[^1] = ay[^1]

  for i in 1..<n:
    cx[i] = cx[i-1]+ax[i]
    cy[n-i-1] = cy[n-i]+ay[n-i-1]
  # 終端が必要だったので追加
  cx = @[0] & cx
  cy = cy & @[0]

  # 最小値のインデックス
  minIdxX[0]=0
  minIdxy[^1]=n
  for i in 1..n:
    if cx[minIdxX[i-1]] > cx[i]:
      minIdxX[i] = i
    else:
      minIdxX[i] = minIdxX[i-1]
  for i in countdown(n-1,0):
    if cy[minIdxY[i+1]] > cy[i]:
      minIdxY[i] = i
    else:
      minIdxY[i] = minIdxY[i+1]
  #echo a
  #echo "x"
  #echo cx
  #echo minIdxX

  #echo "y"
  #echo ay
  #echo cy
  #echo minIdxY
  #echo ""
  # choicex[i]
  # 0: [0..i-1]での最大値
  # 1: [?..i]での最大値:
  #  : 最小値のインデックスだけ保持しておけばよさそう
  # 2: [i..i]の値
  choicex[0][0] = cx[1]
  choicex[0][1] = cx[1]
  choicex[0][2] = cx[1]
  
  for m in 1..<n:
    choicex[m][1] = cx[m]-cx[minIdxX[m-1]]
    choicex[m][2] = cx[m]-cx[m-1]
    choicex[m][0] = max(choicex[m-1][0],max(choicex[m][1],choicex[m][2]))

  # choicey[i]
  # 0: [0..i-1]での最大値
  # 1: [?..i]での最大値:
  #  : 最小値のインデックスだけ保持しておけばよさそう
  # 2: [i..i]の値
  choicey[^1][0] = cy[^2]
  choicey[^1][1] = cy[^2]
  choicey[^1][2] = cy[^2]
  
  for m in countdown(n-2,0):
    choicey[m][1] = cy[m]-cy[minIdxY[m+1]]
    choicey[m][2] = cy[m]-cy[m+1]
    choicey[m][0] = max(choicey[m+1][0],max(choicey[m][1],choicey[m][2]))

  

  #echo ""
  #echo choicex.join("\n")
  #echo ""
  #echo choicey.join("\n")

  #echo "a.sum() = \n",a.sum
  var asum = a.sum
  for m in 1..<n-1:
    echo asum+choicex[m][0]+choicey[m+1][0]


    

  # 
solve()
0