Submission #3420188
Source Code Expand
import strutils import sequtils import algorithm import math import queues import tables import sets import logging import future const INF* = int(1e18 + 373) proc readSeq*(): seq[string] = stdin.readLine().strip().split() proc readSeq*(n: Natural): seq[string] = result = newSeq[string](n) for i in 0..<n: result[i] = stdin.readLine().strip() proc readInt1*(): int = readSeq().map(parseInt)[0] proc readInt2*(): (int, int) = let a = readSeq().map(parseInt) return (a[0], a[1]) proc readInt3*(): (int, int, int) = let a = readSeq().map(parseInt) return (a[0], a[1], a[2]) proc readInt4*(): (int, int, int, int) = let a = readSeq().map(parseInt) return (a[0], a[1], a[2], a[3]) type seq2*[T] = seq[seq[T]] proc newSeq2*[T](n1, n2: Natural): seq2[T] = newSeqWith(n1, newSeq[T](n2)) #------------------------------------------------------------------------------# proc eval(s: string): int = var zeroInd = @[ -1 ] for i in 0..<s.len(): if s[i] == '0': zeroInd.add(i) zeroInd.add(s.len()) var ones = newSeq[int]() for i in 0..<zeroInd.len() - 1: ones.add(zeroInd[i + 1] - zeroInd[i] - 1) let k = ones.len() if k == 1: return 0 var dp = newSeq2[int](k + 1, 2) dp[k][0] = 0 dp[k][1] = 0 dp[k - 1][0] = 0 dp[k - 1][1] = 0 for i in countdown(k - 2, 0): let ll = ones[i] let rr = ones[i + 1] dp[i][0] = dp[i + 1][0] dp[i][0] = max(dp[i][0], ll + dp[i + 1][1]) dp[i][0] = max(dp[i][0], rr + dp[i + 2][0]) dp[i][1] = dp[i + 1][0] if ll >= 2: dp[i][1] = max(dp[i][1], (ll - 1) + dp[i + 1][1]) dp[i][1] = max(dp[i][1], rr + dp[i + 2][0]) return dp[0][0] proc main() = let n = readInt1() let s = stdin.readLine() var sec = newSeq[string](0) var i = 0 while i < n and s[i] == '0': i += 1 while i < n: var j = i while j < n: if s[j] == '0' and (j + 1 >= n or s[j + 1] == '0'): break j += 1 sec.add(s[i..<j]) i = j while i < n and s[i] == '0': i += 1 var ans = 0 for s in sec: ans += s.eval() echo ans main()
Submission Info
Submission Time | |
---|---|
Task | D - 101 to 010 |
User | somq14 |
Language | Nim (0.13.0) |
Score | 0 |
Code Size | 2188 Byte |
Status | WA |
Exec Time | 41 ms |
Memory | 4860 KB |
Compile Error
Hint: system [Processing] Hint: Main [Processing] Hint: strutils [Processing] Hint: parseutils [Processing] Hint: sequtils [Processing] Hint: algorithm [Processing] Hint: math [Processing] Hint: times [Processing] Hint: queues [Processing] Hint: tables [Processing] Hint: hashes [Processing] Hint: etcpriv [Processing] Hint: sets [Processing] Hint: os [Processing] Hint: posix [Processing] Hint: logging [Processing] lib/pure/logging.nim(128, 22) Hint: 'Exception' is declared but not used [XDeclaredButNotUsed] Hint: future [Processing] Hint: macros [Processing] Hint: [Link] Hint: operation successful (24885 lines compiled; 2.788 sec total; 25.256MB; Release Build) [SuccessX]
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 700 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 4 ms | 1148 KB |
001.txt | AC | 6 ms | 1148 KB |
002.txt | WA | 15 ms | 2684 KB |
003.txt | WA | 11 ms | 1532 KB |
004.txt | WA | 15 ms | 2172 KB |
005.txt | WA | 20 ms | 2044 KB |
006.txt | WA | 4 ms | 636 KB |
007.txt | WA | 7 ms | 892 KB |
008.txt | WA | 1 ms | 508 KB |
009.txt | WA | 5 ms | 2300 KB |
010.txt | AC | 2 ms | 1404 KB |
011.txt | AC | 15 ms | 3324 KB |
012.txt | WA | 26 ms | 4092 KB |
013.txt | WA | 35 ms | 4732 KB |
014.txt | WA | 40 ms | 4860 KB |
015.txt | WA | 41 ms | 3964 KB |
016.txt | WA | 37 ms | 3836 KB |
017.txt | WA | 31 ms | 2812 KB |
018.txt | WA | 21 ms | 2172 KB |
019.txt | WA | 11 ms | 2300 KB |
020.txt | AC | 3 ms | 2172 KB |
021.txt | AC | 3 ms | 2172 KB |
022.txt | AC | 3 ms | 2172 KB |
023.txt | WA | 3 ms | 2172 KB |
024.txt | WA | 3 ms | 2172 KB |
025.txt | WA | 3 ms | 2172 KB |
026.txt | WA | 3 ms | 2172 KB |
027.txt | WA | 3 ms | 2172 KB |
028.txt | WA | 3 ms | 2172 KB |
029.txt | WA | 3 ms | 2172 KB |
030.txt | WA | 3 ms | 2172 KB |
031.txt | WA | 3 ms | 2044 KB |
032.txt | WA | 3 ms | 2300 KB |
033.txt | WA | 3 ms | 2684 KB |
034.txt | WA | 4 ms | 3324 KB |
035.txt | WA | 5 ms | 2812 KB |
036.txt | WA | 8 ms | 2300 KB |
example0.txt | AC | 1 ms | 256 KB |
example1.txt | AC | 1 ms | 256 KB |