結果
問題 |
No.967 引き算をして門松列(その2)
|
ユーザー |
|
提出日時 | 2021-06-20 01:51:58 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,963 bytes |
コンパイル時間 | 3,008 ms |
コンパイル使用メモリ | 88,672 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-22 22:23:05 |
合計ジャッジ時間 | 3,668 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 |
コンパイルメッセージ
/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, 8) Warning: imported and not used: 'critbits' [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(2, 18) Warning: imported and not used: 'future' [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') var memo = initTable[(int,int,int),bool]() proc dfs(a,b,c:int):bool= if memo.haskey((a,b,c)): return memo[(a,b,c)] if a==0 or b==0 or c==0: return false elif (a!=b and b!=c and c!=a) and ((a > b and b < c) or (a < b and b > c)): #echo fmt"{a} {b} {c}" return true else: memo[(a,b,c)]=dfs(a-1,b,c) or dfs(a,b-1,c) or dfs(a,b,c-1) return memo[(a,b,c)] #for a in 1..100: #fo#r b in 1..100: #for c in 1..100: #if dfs(a,b,c)==false: #echo fmt"{a} {b} {c}" #echo dfs(2,2,3) proc solve()= var t = scan() abcxyz = newseqwith(t,(scan(),scan(),scan(),scan(),scan(),scan())) for i in 0..<abcxyz.len: var (a,b,c,x,y,z)=abcxyz[i] if (a,b)==(1,1) or (a,b)==(1,2) or (b,c)==(1,1) or (b,c)==(2,1) or (a,c)==(1,1): echo -1 else: var res = int.high p1 = 0 p2 = 0 # 真ん中凸を作る if a>=b: p1+=(a-b+1)*x a = b-1 if c>=b: p1+=(c-b+1)*z c = b-1 if a==c: p1+=min(x,z) a-=1 if not (a<=0 or b<=0 or c<=0): res.min=p1 # 真ん中凹を作る (a,b,c,x,y,z)=abcxyz[i] if a==c: p2+=min(x,z) a-=1 if b>=min(a,c): p2+=(b-min(a,c)+1)*y b=min(a,c)-1 if not (a<=0 or b<=0 or c<=0): res.min=p2 if res==int.high: echo -1 else: echo res solve()