AGC041A - Table Tennis Training
Break through in 28 and a half minutes. WA5. I thought it was easy and submitted it, but it wasn't easy.
The earliest of the following is the answer
N, A, B = map(int, input().split())
t = float('inf')
if abs(A - B) % 2 == 0:
t = min(abs(A - B) // 2, t)
t = min(B - 1, t)
t = min(N - A, t)
t = min((A - 1 + 1) + (B - A - 1) // 2, t)
t = min((N - B + 1) + (N - (A + (N - B + 1))) // 2, t)
print(t)
PS: If you think about it again, you don't need 2 and 3, and if it's an even number, you don't have to think about the pattern that goes to the edge.
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
print(min(A, N - B + 1) + (B - A - 1) // 2)
Break through in 113 minutes. WA5. Eat TLE with Python, eat TLE with PyPy, eat TLE even if rewritten with Go, erase one useless copy of slice, AC, only one heavy test case I went in and was messed up.
Nonetheless, the dance of delight was reincarnated from the state of tears that seemed to be rated full bocco in the 1900s to the splendid 900s.
Since M is the maximum number of votes that can receive one problem, if the current score + M is equal to or higher than the Pth score, it is basically a candidate. However, if there were too many votes, I had to vote for the Pth score, which was very difficult. To be honest, I wrote it properly, but I often went through it. Strictly speaking, there seems to be a hole somewhere ...
package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
)
func min(x, y int) int {
if x < y {
return x
}
return y
}
func main() {
N := readInt()
M := readInt()
V := readInt()
P := readInt()
A := make([]int, N)
for i := 0; i < N; i++ {
A[i] = readInt()
}
sort.Sort(sort.Reverse(sort.IntSlice(A)))
p := A[P-1]
V -= P - 1
b := A[P-1:]
for {
mv := M * V
for i := 0; i < len(b); i++ {
t := min(p-b[i], M)
mv -= t
}
if mv > 0 {
p += (mv + len(b) - 1) / len(b)
} else {
break
}
}
result := 0
for i := 0; i < N; i++ {
if A[i]+M >= p {
result++
}
}
fmt.Println(result)
}
const (
ioBufferSize = 1 * 1024 * 1024 // 1 MB
)
var stdinScanner = func() *bufio.Scanner {
result := bufio.NewScanner(os.Stdin)
result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
result.Split(bufio.ScanWords)
return result
}()
func readString() string {
stdinScanner.Scan()
return stdinScanner.Text()
}
func readInt() int {
result, err := strconv.Atoi(readString())
if err != nil {
panic(err)
}
return result
}
Recommended Posts