結果
| 問題 |
No.1536 仕切り直し
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-06 18:24:12 |
| 言語 | Nim (2.2.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,858 bytes |
| コンパイル時間 | 4,211 ms |
| コンパイル使用メモリ | 87,824 KB |
| 実行使用メモリ | 31,932 KB |
| 最終ジャッジ日時 | 2024-11-25 06:31:47 |
| 合計ジャッジ時間 | 6,450 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | WA * 2 RE * 8 |
コンパイルメッセージ
/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 solve()=
var
n = scan()
m = scan()
a = newseqwith(n,scan())
dp = newseqwith(m+1,newseqwith(n+1,0))
frm = newseqwith(m+1,newseqwith(n+1,false))
for i in 1..n:
dp[0][i] = dp[0][i-1]+a[i-1]
for j in 1..m:
for i in 1..n:
# jが偶数:iより前に偶数枚の仕切りが入っているので、a[i]は加算する
# jが奇数:iより前に偶数枚の仕切りが入っているので、a[i]は減算する
if j.mod(2)==0:
if dp[j-1][i-1] >= dp[j][i-1]+a[i-1]:
frm[j][i]=true # 直前に仕切りがあったほうがいいフラグ
dp[j][i] = max(dp[j-1][i-1]+a[i-1],dp[j][i-1]+a[i-1])
else:
if dp[j-1][i-1] >= dp[j][i-1]-a[i-1]:
frm[j][i]=true # 直前に仕切りがあったほうがいいフラグ
dp[j][i] = max(dp[j-1][i-1]-a[i-1],dp[j][i-1]-a[i-1])
var
maxIdx = -1
maxV = -int.high.div(4)
#echo dp.join("\n")
#echo frm.join("\n")
for i in 0..m:
if dp[i][^1]>maxV:
maxV = dp[i][^1]
maxIdx = i
var
y = maxIdx
x = n
ans = newseq[int]()
while (y,x) != (0,0):
if frm[y][x]:
ans.add(x-1)
y = y-1
x = x-1
else:
x = x-1
if ans.len>0:
echo ans.sorted.join("\n")
else:
for i in 0..<m:
echo n
solve()