結果

問題 No.1375 Divide and Update
ユーザー dot_haraaidot_haraai
提出日時 2021-06-06 12:25:33
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 2,708 bytes
コンパイル時間 5,728 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 53,116 KB
最終ジャッジ日時 2024-11-22 18:45:22
合計ジャッジ時間 37,773 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,496 KB
testcase_01 AC 2 ms
37,760 KB
testcase_02 AC 2 ms
10,496 KB
testcase_03 WA -
testcase_04 AC 2 ms
10,496 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/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,newseq[int](3))
    ay = newseqwith(n,0)
    cy = newseqwith(n,0)
    minIdxY = newseqwith(n+1,0)
    choicey = newseqwith(n,newseq[int](3))

  # 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]]
    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]]
    choicey[m][2] = cy[m]-cy[m+1]
    choicey[m][0] = max(choicey[m+1][0],max(choicey[m][1],choicey[m][2]))

  


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

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


    

  # 
solve()
0