fork download
  1. package main
  2.  
  3. import "fmt"
  4.  
  5. func main() {
  6. var t int
  7. fmt.Scanf("%d", &t)
  8. for k := 0; k < t; k++ {
  9. var n int
  10. fmt.Scanf("%d", &n)
  11. a := make([]int, n)
  12. for i := 0; i < n; i++ {
  13. fmt.Scanf("%d", &a[i])
  14. }
  15. m := make(map[int]int)
  16. for i := 0; i < n; i++ {
  17. var j int
  18. for j = i; j < n; j++ {
  19. if a[j] == 0 {
  20.  
  21. break
  22. }
  23. }
  24. if a[i] != 0 {
  25. _, ok := m[j]
  26. if !ok {
  27. m[j] = i
  28. }
  29. }
  30. }
  31. if len(m) >= 2 {
  32. fmt.Println(2)
  33. } else {
  34. fmt.Println(len(m))
  35. }
  36. }
  37. }
  38.  
Success #stdin #stdout 0s 5280KB
stdin
10
4
0 1 2 3
6
0 0 0 0 0 0
5
1 0 1 0 1
5
3 1 4 1 5
4
3 2 1 0
7
9 100 0 89 12 2 3
4
0 3 9 0
7
0 7 0 2 0 7 0
1
0
2
0 1
stdout
1
0
2
1
1
2
1
2
0
1