Submission #3420262
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 main() = let n = readInt1() let s = stdin.readLine() var dp = newSeq[int](n + 1) dp[n] = 0 dp[n - 1] = 0 dp[n - 2] = 0 var i = n - 3 while i >= 0: if not (s[i] == '1' and s[i + 1] == '0' and s[i + 2] == '1'): dp[i] = dp[i + 1] i -= 1 continue var ll = i while ll >= 0 and s[ll] == '1': ll -= 1 var rr = i + 2 while rr < n and s[rr] == '1': rr += 1 let a = i - ll let b = rr - (i + 2) dp[i] = dp[i + 1] for j in 0..<b: dp[i] = max(dp[i], (j + 1) + dp[(i + 2) + j + 1]) for j in 0..<a: dp[i - j] = max(dp[i], (j + 1) + dp[i + 3]) i -= a echo dp[0] main()
Submission Info
Submission Time | |
---|---|
Task | D - 101 to 010 |
User | somq14 |
Language | Nim (0.13.0) |
Score | 700 |
Code Size | 1632 Byte |
Status | AC |
Exec Time | 7 ms |
Memory | 5372 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 (24860 lines compiled; 2.485 sec total; 24.250MB; Release Build) [SuccessX]
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 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 | 2 ms | 2812 KB |
001.txt | AC | 2 ms | 1532 KB |
002.txt | AC | 3 ms | 2684 KB |
003.txt | AC | 2 ms | 1660 KB |
004.txt | AC | 3 ms | 2300 KB |
005.txt | AC | 4 ms | 2684 KB |
006.txt | AC | 1 ms | 764 KB |
007.txt | AC | 2 ms | 1532 KB |
008.txt | AC | 1 ms | 380 KB |
009.txt | AC | 4 ms | 4348 KB |
010.txt | AC | 3 ms | 5372 KB |
011.txt | AC | 4 ms | 5372 KB |
012.txt | AC | 5 ms | 5372 KB |
013.txt | AC | 5 ms | 5372 KB |
014.txt | AC | 6 ms | 5372 KB |
015.txt | AC | 6 ms | 5372 KB |
016.txt | AC | 7 ms | 5372 KB |
017.txt | AC | 7 ms | 5372 KB |
018.txt | AC | 6 ms | 5372 KB |
019.txt | AC | 5 ms | 5372 KB |
020.txt | AC | 3 ms | 5372 KB |
021.txt | AC | 4 ms | 5372 KB |
022.txt | AC | 4 ms | 5372 KB |
023.txt | AC | 4 ms | 5372 KB |
024.txt | AC | 4 ms | 5372 KB |
025.txt | AC | 4 ms | 5372 KB |
026.txt | AC | 4 ms | 5372 KB |
027.txt | AC | 4 ms | 5372 KB |
028.txt | AC | 4 ms | 5372 KB |
029.txt | AC | 4 ms | 5372 KB |
030.txt | AC | 4 ms | 5372 KB |
031.txt | AC | 4 ms | 5372 KB |
032.txt | AC | 4 ms | 5372 KB |
033.txt | AC | 4 ms | 5372 KB |
034.txt | AC | 4 ms | 5372 KB |
035.txt | AC | 5 ms | 5372 KB |
036.txt | AC | 6 ms | 5372 KB |
example0.txt | AC | 1 ms | 256 KB |
example1.txt | AC | 1 ms | 256 KB |