結果

問題 No.1188 レベルX門松列
ユーザー dot_haraaidot_haraai
提出日時 2021-03-28 12:39:06
言語 Nim
(2.0.2)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 2,794 bytes
コンパイル時間 6,058 ms
コンパイル使用メモリ 75,632 KB
実行使用メモリ 15,804 KB
最終ジャッジ日時 2023-08-19 15:30:47
合計ジャッジ時間 5,140 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
14,068 KB
testcase_01 AC 68 ms
12,592 KB
testcase_02 AC 58 ms
12,312 KB
testcase_03 AC 78 ms
14,124 KB
testcase_04 AC 70 ms
14,064 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 42 ms
13,880 KB
testcase_07 AC 71 ms
13,944 KB
testcase_08 AC 71 ms
13,912 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 7 ms
4,376 KB
testcase_12 AC 7 ms
4,384 KB
testcase_13 AC 8 ms
4,376 KB
testcase_14 AC 48 ms
10,220 KB
testcase_15 AC 82 ms
15,804 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 68 ms
12,720 KB
testcase_18 AC 1 ms
4,388 KB
testcase_19 AC 60 ms
12,300 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,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, 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]

ソースコード

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 getLIS(arr:seq[int]):seq[int]=
  var n = arr.len
  result = newseqwith(n+2,int.high.div(2))
  result[0]=arr[0]
  proc binSearch(v:int,res:var seq[int]):int=
    var
      left = 0
      right = n+1
    if res[left]>v:
      return left
    else:
      while left+1<right:
        var mid = (left+right).div(2)
        if res[mid]<=v:
          left = mid
        else:
          right=mid
      return right
  
    
  


#echo getLIS(@[1,3,5,2,4,6])






proc solve():int=
  var
    inf = int.high.div(2)
    n = scan()

    a = newseqwith(n,scan()) # 左から単調増加
    lisA = newseqwith(n+1,inf)
    resA = newseqwith(n,0)
    inva = a.reversed() # 右から単調増加
    lisInvA = newseqwith(n+1,inf)
    resInvA = newseqwith(n,0)
    b = a.mapIt(-it) # 左から単調減少
    lisB = newseqwith(n+1,inf)
    resB = newseqwith(n,0)
    invb = b.reversed() # 右から単調減少
    lisInvB = newseqwith(n+1,inf)
    resInvB = newseqwith(n,0)
    
    
  
  proc binSearch(v:int,res:var seq[int]):int=
    var
      left = 0
      right = n+1
    if res[left]>=v:
      return left
    else:
      while left+1<right:
        var mid = (left+right).div(2)
        if res[mid]<v:
          left = mid
        else:
          right=mid
      return right

  proc getMinVal(arr:var seq[int]):int=
    var
      left = 0
      right = n+1
    if arr[left]==inf:
      return left
    else:
      while left+1<right:
        var mid = (left+right).div(2)
        if arr[mid]==inf:
          right=mid
        else:
          left = mid
      return left
  
  for i in 0..<n:
    # LISの更新 
    lisA[binSearch(a[i],lisA)]=a[i]
    lisInvA[binSearch(inva[i],lisInvA)]=inva[i]
    lisB[binSearch(b[i],lisB)]=b[i]
    lisInvB[binSearch(invb[i],lisInvB)]=invb[i]
    #echo lisA
    resA[i]=getMinVal(lisA)+1
    resB[i]=getMinVal(lisB)+1
    resInvA[n-i-1]=getMinVal(lisInvA)+1
    resInvB[n-1-i]=getMinVal(lisInvB)+1

  #echo resA , "単調増加列(iまで)"
  #echo resB, "単調減少列(iまで)"
  #echo resInvA, "単調減少列(iから)"
  #echo resInvB, "単調増加列(iから)"
  for i in 0..<n:
    result.max=min(resA[i],resInvA[i])-1
    result.max=min(resB[i],resInvB[i])-1

  

    
  return

  
  
  
  


  
echo solve()
0