- Translate each rule into one explicit state update.
- Maintain the invariant after every processed item.
- Return the accumulated state once all relevant input has been handled.
Code notes
- 83 lines of Go from the credited upstream file 1359F.go.
- The implementation visibly relies on sequence storage.
- No explicit loop blocks detected.
Complexity
Count the number and nesting of passes over the input, then include the maintained containers in the memory estimate.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
1package main2 3import (4 "bufio"5 . "fmt"6 "io"7 "math"8)9 10type vec1359 struct{ x, y int }11 12func (a vec1359) sub(b vec1359) vec1359 { return vec1359{a.x - b.x, a.y - b.y} }13func (a vec1359) dot(b vec1359) int { return a.x*b.x + a.y*b.y }14func (a vec1359) det(b vec1359) int { return a.x*b.y - a.y*b.x }15func (a vec1359) len() float64 { return math.Hypot(float64(a.x), float64(a.y)) }16 1718func CF1359F(_r io.Reader, out io.Writer) {19 20 min := func(a, b float64) float64 {21 if a < b {22 return a23 }24 return b25 }26 max := func(a, b float64) float64 {27 if a > b {28 return a29 }30 return b31 }32 type car struct {33 p, d vec135934 s, norm float6435 }36 37 in := bufio.NewReader(_r)38 var n int39 Fscan(in, &n)40 cs := make([]car, n)41 for i := range cs {42 Fscan(in, &cs[i].p.x, &cs[i].p.y, &cs[i].d.x, &cs[i].d.y, &cs[i].s)43 cs[i].norm = cs[i].d.len()44 }45 46 ans := 1e9947 for i, p := range cs {48 for j := i + 1; j < n; j++ {49 q := cs[j]50 u := p.p.sub(q.p)51 if d := p.d.det(q.d); d != 0 {52 d1, d2 := q.d.det(u), p.d.det(u)53 if d > 0 && d1 >= 0 && d2 >= 0 || d < 0 && d1 <= 0 && d2 <= 0 {54 ans = min(ans, max(p.norm*float64(d1)/(p.s*float64(d)), q.norm*float64(d2)/(q.s*float64(d))))55 }56 continue57 }58 if u.det(p.d) != 0 {59 continue60 }61 62 if l := u.len(); p.d.dot(q.d) > 0 {63 if u.dot(q.d) >= 0 {64 ans = min(ans, l/q.s)65 } else {66 ans = min(ans, l/p.s)67 }68 } else {69 if u.dot(q.d) > 0 {70 ans = min(ans, l/(p.s+q.s))71 }72 }73 }74 }75 if ans == 1e99 {76 Fprint(out, "No show :(")77 } else {78 Fprintf(out, "%.8f", ans)79 }80}81 8283