This https://codeforces.me/contest/1956/submission/256474898 solution consumes at least (2 * n + 1) * sizeof(int) bytes, on the test #4 the memory usage must be at least 1_600_004 bytes instead of 56 KB.
| # | User | Rating |
|---|---|---|
| 1 | jiangly | 3810 |
| 2 | Benq | 3676 |
| 3 | Kevin114514 | 3655 |
| 4 | maroonrk | 3463 |
| 5 | strapple | 3447 |
| 6 | Um_nik | 3387 |
| 7 | heuristica | 3322 |
| 8 | turmax | 3317 |
| 9 | tourist | 3307 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 156 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | Um_nik | 141 |
| 5 | Errichto | 139 |
| 6 | adamant | 137 |
| 7 | AmShZ | 135 |
| 8 | BledDest | 132 |
| 9 | maroonrk | 131 |
| 10 | qwexd | 129 |
This https://codeforces.me/contest/1956/submission/256474898 solution consumes at least (2 * n + 1) * sizeof(int) bytes, on the test #4 the memory usage must be at least 1_600_004 bytes instead of 56 KB.
https://codeforces.me/contest/1846/submission/215981788
The code (Ruby) below is a solution for https://leetcode.com/problems/uncrossed-lines/
Note: In Ruby Array#shift is O(1)
The trick is on the lines 3-4:
def max_uncrossed_lines a, b
# These two lines
c = a.to_set & b.to_set
a, b = *[a, b].map! { | v | v.filter { c === _1 } }
s = 0
while !a.empty? && a.first == b.first
a.shift
b.shift
s += 1
end
while !a.empty? && a.last == b.last
a.pop
b.pop
s += 1
end
r0, r1 = *Array.new(2) { [0] * (b.size + 1) }
for x in a
for y, j in b.each_with_index
r1[j + 1] = (x == y) ?
1 + r0[j] :
[r0[j + 1], r1[j]].max
end
r0, r1 = r1, r0
end
s + r0.last
end
| Name |
|---|


