Submission #857280


Source Code Expand

Copy
package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  hotels := make([]int, n)
  for i := range hotels {
    hotels[i] = getI()
  }
  hop := getI()
  maxLeap := 30

  leapsRight := make([][]int, n)
  for i := range leapsRight {
    leapsRight[i] = make([]int, maxLeap + 1)
    for j := range leapsRight[i] {
      leapsRight[i][j] = -1
    }
  }
  left, right := 0, 1
  for right < n {
    for hotels[left] + hop < hotels[right] {
      leapsRight[left][0] = right - 1
      left++
    }
    right++
  }
  for left < n - 1 {
    leapsRight[left][0] = n - 1
    left++
  }
  for x := 0; x <= maxLeap; x++ {
    for a := 0; a < n; a++ {
      b := leapsRight[a][x]
      if b != -1 {
        c := leapsRight[b][x]
        if c != -1 {
          leapsRight[a][x + 1] = c
        }
      }
    }
  }

  leapsLeft := make([][]int, n)
  for i := range leapsLeft {
    leapsLeft[i] = make([]int, maxLeap + 1)
    for j := range leapsLeft[i] {
      leapsLeft[i][j] = -1
    }
  }
  left, right = n - 2, n - 1
  for left >= 0 {
    for hotels[right] - hop > hotels[left] {
      leapsLeft[right][0] = left + 1
      right--
    }
    left--
  }
  for right > 0 {
    leapsLeft[right][0] = 0
    right--
  }
  for x := 0; x <= maxLeap; x++ {
    for a := n - 1; a >= 0; a-- {
      b := leapsLeft[a][x]
      if b != -1 {
        c := leapsLeft[b][x]
        if c != -1 {
          leapsLeft[a][x + 1] = c
        }
      }
    }
  }

  numQueries := getI()
  for qi := 0; qi < numQueries; qi++ {
    a, b := getI() - 1, getI() - 1
    result := 0
    if a > b {
      a, b = b, a
    }
    if a < b {
      for x := maxLeap; x >= 0; x-- {
        for {
          p := leapsRight[a][x]
          if p == -1 || p > b {
            break
          }
          result += 1 << uint(x)
          a = p
          if a == b {
            break
          }
        }
      }
    } else {
      for x := maxLeap; x >= 0; x-- {
        p := leapsLeft[a][x]
        fmt.Printf("leapsLeft[%d][%d] = %d\n", a, x, p)
        if p != -1 && p >= b {
          result += 1 << uint(x)
          fmt.Printf("%d -> %d (%d)\n", a, p, 1 << uint(x))
          a = p
          if a == b {
            break
            fmt.Printf("done\n")
          }
        }
      }
    }
    writer.WriteString(fmt.Sprintf("%d\n", result))
  }
}

Submission Info

Submission Time
Task E - Tak and Hotels
User Eeyore
Language Go (1.6)
Score 0
Code Size 2785 Byte
Status WA
Exec Time 637 ms
Memory 62464 KB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 500
Status
AC × 1
AC × 4
WA × 10
AC × 5
WA × 22
Set Name Test Cases
Sample example_01.txt
Subtask1 example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt
All example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt
Case Name Status Exec Time Memory
example_01.txt AC 3 ms 640 KB
subtask1_01.txt WA 4 ms 640 KB
subtask1_02.txt AC 3 ms 640 KB
subtask1_03.txt WA 7 ms 1152 KB
subtask1_04.txt AC 7 ms 1280 KB
subtask1_05.txt WA 7 ms 1280 KB
subtask1_06.txt AC 5 ms 896 KB
subtask1_07.txt WA 5 ms 896 KB
subtask1_08.txt WA 7 ms 1280 KB
subtask1_09.txt WA 7 ms 1280 KB
subtask1_10.txt WA 7 ms 1280 KB
subtask1_11.txt WA 7 ms 1280 KB
subtask1_12.txt WA 7 ms 1280 KB
subtask1_13.txt WA 7 ms 1152 KB
subtask2_01.txt WA 593 ms 62208 KB
subtask2_02.txt AC 637 ms 62464 KB
subtask2_03.txt WA 575 ms 61952 KB
subtask2_04.txt WA 277 ms 40320 KB
subtask2_05.txt WA 331 ms 40960 KB
subtask2_06.txt WA 472 ms 61312 KB
subtask2_07.txt WA 591 ms 62336 KB
subtask2_08.txt WA 635 ms 62464 KB
subtask2_09.txt WA 631 ms 62336 KB
subtask2_10.txt WA 633 ms 62336 KB
subtask2_11.txt WA 588 ms 57728 KB
subtask2_12.txt WA 525 ms 61696 KB
subtask2_13.txt WA 471 ms 61312 KB