Submission #856628


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()
  leaps := make([][]int, n)
  maxLeap := 30
  for i := range leaps { 
    leaps[i] = make([]int, maxLeap + 1)
    for j := range leaps[i] { 
      leaps[i][j] = -1
    }
  }
  left, right := 0, 1
  for right < n {
    for hotels[left] + hop < hotels[right] {
      leaps[left][0] = right - 1 
      left++
    }
    right++
  }
  for left < n - 1 {
    leaps[left][0] = n - 1 
    left++
  }
  for x := 0; x <= maxLeap; x++ {
    for a := 0; a < n; a++ {
      b := leaps[a][x]
      if b != -1 {
        c := leaps[b][x]
        if c != -1 {
          leaps[a][x + 1] = c
        }
      }
    }
  }
  
  numQueries := getI()
  for qi := 0; qi < numQueries; qi++ {
    a, b := getI() - 1, getI() - 1
    if a > b {
      a, b = b, a
    }
    result := 0
    for x := maxLeap; x >= 0; x-- {
      p := leaps[a][x]
      if p != -1 && p <= b {
        result += 1 << uint(x)
        a = p
        if a == b {
          break
        }
      }
    }
    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 1586 Byte
Status WA
Exec Time 486 ms
Memory 33792 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 4 ms 640 KB
subtask1_01.txt WA 4 ms 640 KB
subtask1_02.txt AC 4 ms 640 KB
subtask1_03.txt WA 6 ms 1024 KB
subtask1_04.txt AC 7 ms 896 KB
subtask1_05.txt WA 6 ms 896 KB
subtask1_06.txt AC 5 ms 768 KB
subtask1_07.txt WA 5 ms 768 KB
subtask1_08.txt WA 6 ms 896 KB
subtask1_09.txt WA 6 ms 896 KB
subtask1_10.txt WA 6 ms 896 KB
subtask1_11.txt WA 6 ms 896 KB
subtask1_12.txt WA 6 ms 896 KB
subtask1_13.txt WA 6 ms 896 KB
subtask2_01.txt WA 426 ms 33536 KB
subtask2_02.txt AC 486 ms 33792 KB
subtask2_03.txt WA 413 ms 33280 KB
subtask2_04.txt WA 204 ms 21632 KB
subtask2_05.txt WA 244 ms 22144 KB
subtask2_06.txt WA 345 ms 32640 KB
subtask2_07.txt WA 423 ms 33664 KB
subtask2_08.txt WA 451 ms 33792 KB
subtask2_09.txt WA 449 ms 33792 KB
subtask2_10.txt WA 450 ms 33664 KB
subtask2_11.txt WA 448 ms 31360 KB
subtask2_12.txt WA 357 ms 33024 KB
subtask2_13.txt WA 340 ms 32640 KB