28852023-02-01 18:36:37bencewokVideójátékgolangWrong answer 0/100129ms56128 KiB
package main

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

func binarySearch(needle int, haystack []int) bool {

	low := 0
	high := len(haystack) - 1

	for low <= high {
		median := (low + high) / 2
		if haystack[median] < needle {
			low = median + 1
		} else {
			high = median - 1
		}
	}
	if low == len(haystack) || haystack[low] != needle {
		return false
	}
	return true
}

func input() []int {
	var input string
	var output []int

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	input = scanner.Text()

	inputSplit := strings.Split(input, " ")

	for i := 0; i < len(inputSplit); i++ {
		charInt, _ := strconv.Atoi(inputSplit[i])
		output = append(output, charInt)
	}

	return output
}

func main() {
	var aBreaks, yBreaks []int
	var boretimeNow, output int

	boretime := input()[0]

	aLenght := input()[0]
	for i := 0; i < aLenght; i++ {
		ln := input()
		aBreaks = append(aBreaks, ln[0])
		aBreaks = append(aBreaks, ln[1])
	}

	yLenght := input()[0]
	for i := 0; i < yLenght; i++ {
		ln := input()
		yBreaks = append(yBreaks, ln[0])
		yBreaks = append(yBreaks, ln[1])
	}

	var max int
	for i := 1; i < len(yBreaks); i++ {
		if max < yBreaks[i] {
			max = yBreaks[i]
		}
	}

	for i := 1; i < len(aBreaks); i++ {
		if max < aBreaks[i] {
			max = aBreaks[i]
		}
	}

	var u, q int
	var aBreaksList []int
	for true {

		if u == len(aBreaks) {
			break
		}

		if aBreaks[u]+q != aBreaks[u+1]+1 {

			aBreaksList = append(aBreaksList, aBreaks[u]+q)
			q++

		} else {
			q = 0
			u += 2
		}
	}

	q, u = 0, 0
	var yBreaksList []int
	for true {

		if u == len(yBreaks) {
			break
		}

		if yBreaks[u]+q != yBreaks[u+1]+1 {

			yBreaksList = append(yBreaksList, yBreaks[u]+q)
			q++

		} else {
			q = 0
			u += 2
		}
	}

	var p int
	for i := 0; i < len(aBreaksList); i++ {
		if binarySearch(aBreaksList[i], yBreaksList) == true {
			//fmt.Println(aBreaksList[i], "aa")
			output++
		} else {
			boretimeNow++
			if boretimeNow == boretime {
				p += 2
				i = p
			}
		}
	}

	//fmt.Println(aBreaksList, yBreaksList)

	fmt.Println(output)
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Wrong answer27ms30044 KiB
2Wrong answer26ms30876 KiB
subtask20/10
3Accepted26ms30496 KiB
4Accepted24ms30964 KiB
5Accepted25ms31688 KiB
6Accepted24ms31908 KiB
7Wrong answer26ms32060 KiB
8Wrong answer26ms32240 KiB
9Accepted25ms32272 KiB
10Wrong answer25ms32016 KiB
11Wrong answer25ms32420 KiB
subtask30/20
12Wrong answer24ms32256 KiB
13Wrong answer25ms32220 KiB
14Wrong answer25ms32384 KiB
15Wrong answer25ms32212 KiB
16Wrong answer25ms32556 KiB
17Runtime error127ms54216 KiB
18Runtime error125ms55136 KiB
19Runtime error128ms55520 KiB
20Runtime error128ms55756 KiB
21Runtime error128ms55656 KiB
22Runtime error126ms56012 KiB
subtask40/30
23Runtime error128ms55920 KiB
24Runtime error128ms55608 KiB
25Runtime error125ms55560 KiB
26Runtime error128ms55088 KiB
27Runtime error128ms55864 KiB
28Runtime error125ms55988 KiB
29Runtime error128ms56120 KiB
30Runtime error125ms55804 KiB
31Runtime error128ms56028 KiB
subtask50/40
32Runtime error129ms56076 KiB
33Runtime error125ms56020 KiB
34Runtime error128ms55864 KiB
35Runtime error125ms55820 KiB
36Runtime error123ms56000 KiB
37Runtime error122ms55664 KiB
38Runtime error122ms56124 KiB
39Runtime error128ms55788 KiB
40Runtime error125ms56128 KiB
41Runtime error123ms56016 KiB