結果
問題 | No.1188 レベルX門松列 |
ユーザー |
|
提出日時 | 2021-03-28 12:23:53 |
言語 | Nim (2.2.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,788 bytes |
コンパイル時間 | 6,096 ms |
コンパイル使用メモリ | 86,912 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-11-29 08:59:18 |
合計ジャッジ時間 | 7,338 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 2 |
コンパイルメッセージ
/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]
ソースコード
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] # 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()