Contest Duration: - (local time) (100 minutes) Back to Home

Submission #7026113

Source Code Expand

Copy
```proc lowerBound*[T, K](a: openArray[T]; key: K; cmp: proc (x: T; k: K): int): int =
if cmp(a[0], key) >= 0: return 0
if cmp(a[^1], key) < 0: return a.len
result = a.low
var step = a.len
while step > 0:
step = step div 2
if cmp(a[min(result + step, a.high)], key) < 0:
result += step + 1

proc upperBound*[T, K](a: openArray[T]; key: K; cmp: proc (x: T; k: K): int): int =
a.lowerBound(key, proc (x:T; k: K): int = return if cmp(x, k) <= 0: -1 else: 1)

proc equalRange*[T, K](a: openArray[T]; key: K; cmp: proc (x: T; k: K): int): int =
a.upperBound(key, cmp) - a.lowerBound(key, cmp)

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
import sets
from sequtils import applyIt
from algorithm import fill

let

if (t.toSet - s.toSet).len > 0:
echo -1
quit()

var
T = newSeq[int](t.len)
positions: array['a'..'z', seq[int]]

positions.fill(newSeq[int]())
for i, c in s:

for i, c in t:
if i == 0:
T[i] = positions[c][0]
else:
var j = positions[c].upperBound(T[i - 1], system.cmp)
T[i] = positions[c][j mod positions[c].len]
T.applyIt(it + 1)

var
result = T[0]
prev = T[0]
for i in 1..<T.len:
result += T[i] - prev
if prev >= T[i]:
result += s.len
prev = T[i]

echo result
```

#### Submission Info

Submission Time 2019-08-19 18:23:01+0900 E - Strings of Impurity nimon Nim (0.13.0) 500 1383 Byte AC 23 ms 12540 KB

#### Compile Error

```Hint: system [Processing]
Hint: Main [Processing]
Hint: sets [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: times [Processing]
Hint: posix [Processing]
Hint: hashes [Processing]
Hint: etcpriv [Processing]
Hint: math [Processing]
Hint: sequtils [Processing]
Hint: algorithm [Processing]
Hint: operation successful (22090 lines compiled; 2.131 sec total; 20.209MB; Release Build) [SuccessX]
```

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
 AC × 3
 AC × 45
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 1 ms 256 KB
b09 AC 1 ms 256 KB
b10 AC 23 ms 12540 KB
b11 AC 14 ms 12412 KB
b12 AC 14 ms 12540 KB
b13 AC 13 ms 12540 KB
b14 AC 23 ms 12540 KB
b15 AC 22 ms 12540 KB
b16 AC 6 ms 8828 KB
b17 AC 22 ms 10748 KB
b18 AC 22 ms 10748 KB
b19 AC 5 ms 8828 KB
b20 AC 14 ms 10620 KB
b21 AC 14 ms 10748 KB
b22 AC 14 ms 10876 KB
b23 AC 14 ms 10748 KB
b24 AC 14 ms 10876 KB
b25 AC 20 ms 11260 KB
b26 AC 19 ms 11132 KB
b27 AC 19 ms 11260 KB
b28 AC 17 ms 11132 KB
b29 AC 16 ms 11004 KB
b30 AC 15 ms 10876 KB
b31 AC 6 ms 8828 KB
b32 AC 9 ms 5372 KB
b33 AC 3 ms 4604 KB
b34 AC 5 ms 6640 KB
b35 AC 3 ms 4604 KB
b36 AC 14 ms 12540 KB
b37 AC 14 ms 12540 KB
b38 AC 14 ms 12540 KB
b39 AC 14 ms 12540 KB
b40 AC 14 ms 12540 KB
b41 AC 14 ms 12540 KB
b42 AC 6 ms 8828 KB
b43 AC 6 ms 8828 KB
b44 AC 14 ms 12412 KB
b45 AC 14 ms 12540 KB