48682023-04-03 22:52:32bencewokA lehető legkevesebb átszállás (50 pont)golangWrong answer 14/50280ms64616 KiB
package main

import "fmt"

type line struct {
	start int
	end   int
	index int
}

var (
	stationsc  int
	linesc     int
	start      int
	end        int
	maxstatind int

	maxstat      line
	maxstatcache line

	lines []line

	returnlines []int
)

func input() {
	fmt.Scanln(&linesc, &stationsc)
	for i := 0; i < linesc; i++ {
		fmt.Scanln(&start, &end)
		lines = append(lines, newLine(start, end, i))
	}
}

func newLine(start, end, index int) line {
	return line{
		start: start,
		end:   end,
		index: index,
	}
}

func sort(line []line, i int) {
	for ; i < len(line)-1; i++ {
		if lines[i].start == line[i+1].start {
			if lines[i].end < lines[i+1].end {
				lines[i], lines[i+1] = lines[i+1], lines[i]
			}
		} else {
			break
		}
	}
}

func trains() {
	var i, u int
	i, u = maxstatind, maxstatind

	for ; true; u++ {
		if lines[i].end < lines[u].start {
			break
		}
		if lines[i].start == lines[u].start {
		} else {
			if lines[u].end > maxstat.end {
				maxstat = lines[u]
				maxstatind = u
			}
		}
	}
}

func main() {
	input()
	sort(lines, maxstatind)
	returnlines = append(returnlines, lines[0].index)

	for {
		trains()
		returnlines = append(returnlines, maxstat.index)
		if maxstat.end == stationsc {
			fmt.Println(len(returnlines) - 1)
			fmt.Println(returnlines)
			break
		} else if maxstat == maxstatcache {
			fmt.Println(-1)
			break
		}
		maxstatcache = maxstat
	}
}
SubtaskSumTestVerdictTimeMemory
base14/50
1Wrong answer0/024ms29964 KiB
2Time limit exceeded0/0207ms34272 KiB
3Runtime error0/1134ms62596 KiB
4Accepted1/127ms42492 KiB
5Runtime error0/2125ms64616 KiB
6Runtime error0/2127ms64464 KiB
7Partially correct1/241ms43240 KiB
8Partially correct1/248ms43364 KiB
9Partially correct1/256ms43916 KiB
10Wrong answer0/271ms44300 KiB
11Wrong answer0/290ms45012 KiB
12Partially correct1/2105ms45160 KiB
13Wrong answer0/241ms43948 KiB
14Partially correct1/257ms44224 KiB
15Partially correct1/275ms44896 KiB
16Partially correct1/2108ms46144 KiB
17Partially correct1/2145ms47188 KiB
18Wrong answer0/2160ms46932 KiB
19Partially correct1/2172ms47960 KiB
20Partially correct1/2175ms47856 KiB
21Wrong answer0/2192ms48392 KiB
22Partially correct1/2193ms48616 KiB
23Time limit exceeded0/2275ms32724 KiB
24Time limit exceeded0/2270ms29592 KiB
25Partially correct1/2187ms48544 KiB
26Time limit exceeded0/2250ms28248 KiB
27Time limit exceeded0/2280ms31892 KiB
28Partially correct1/2187ms48244 KiB