Approach
Sorting and greedy selection
For Codeforces 2200E — Divisive Battle, the implementation first exposes a useful order, then scans that order while making locally justified choices.
- Choose the key that reveals the greedy or grouping structure.
- Sort the relevant records by that key.
- Scan in order, maintaining the invariant that makes each local choice safe.
Code notes
- 50 lines of Go from the credited upstream file 2200E.go.
- The implementation visibly relies on sequence storage.
- No explicit loop blocks detected.
Complexity
Sorting is typically the dominant term unless the subsequent scan uses a more expensive nested operation.
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 . "fmt"5 "io"6 "slices"7)8 910func cf2200E(in io.Reader, out io.Writer) {11 const mx int = 1e6 + 112 lpf := [mx]int{1: 1}13 for i := 2; i < mx; i++ {14 if lpf[i] == 0 {15 for j := i; j < mx; j += i {16 if lpf[j] == 0 {17 lpf[j] = i18 }19 }20 }21 }22 23 var T, n int24 for Fscan(in, &T); T > 0; T-- {25 Fscan(in, &n)26 a := make([]int, n)27 b := make([]int, n)28 win := false29 for i := range a {30 Fscan(in, &a[i])31 v := a[i]32 p := lpf[v]33 for v /= p; v > 1 && v%p == 0; v /= p {34 }35 if v > 1 {36 win = true37 } else {38 b[i] = p39 }40 }41 if slices.IsSorted(a) || !win && slices.IsSorted(b) {42 Fprintln(out, "Bob")43 } else {44 Fprintln(out, "Alice")45 }46 }47}48 4950