結果
問題 | No.193 筒の数式 |
ユーザー |
|
提出日時 | 2019-01-23 13:22:34 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 666 bytes |
コンパイル時間 | 2,936 ms |
コンパイル使用メモリ | 63,096 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-01 10:34:05 |
合計ジャッジ時間 | 3,546 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 8) Warning: imported and not used: 'sequtils' [UnusedImport] /home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'algorithm' [UnusedImport] /home/judge/data/code/Main.nim(1, 27) Warning: imported and not used: 'math' [UnusedImport] /home/judge/data/code/Main.nim(1, 32) Warning: imported and not used: 'tables' [UnusedImport]
ソースコード
import sequtils,algorithm,math,tables proc evalPlusMinusExpression(S:string): tuple[ok:bool,val:int] = # 012+223-123+... if S[0] == '+' or S[0] == '-' : return (false,0) if S[^1] == '+' or S[^1] == '-' : return (false,0) var minus = false var val = 0 var ans = 0 for i,s in S: if '0' <= s and s <= '9' : val = 10 * val + s.ord - '0'.ord if i != S.len - 1 : continue if minus : ans -= val else: ans += val val = 0 minus = s == '-' return (true,ans) let S = stdin.readLine() var ans = newSeq[int]() for i in 0..<S.len: let (ok,val) = evalPlusMinusExpression( S[i..^1] & S[0..<i]) if ok : ans &= val echo ans.max()