I went to the mountains and didn't come back by the time, so I entered the virtual race. It's the first time I haven't been to ABC since I started AtCoder? The result was ABCD complete (TLE1) 75:49. . If it comes out, it was a rating up, Gussun
Break through in 2 minutes. Just write.
S = input()
t = 0
result = 0
for c in S:
if c == 'R':
t += 1
else:
t = 0
result = max(result, t)
print(result)
It broke through in 7 minutes. First, I googled because I didn't know the condition of the length of the side where the triangle can be made. I missed "all different </ sub>". As a result, it took a long time to answer the question B.
from itertools import combinations
N, *L = map(int, open(0).read().split())
result = 0
for a, b, c in combinations(L, 3):
if a == b or b == c or c == a:
continue
if a + b > c and b + c > a and c + a > b:
result += 1
print(result)
It broke through in 10 minutes. I knew immediately because I had solved similar problems in the past that I would just approach and then go back and forth, but it took a lot of time to make bugs here and there.
X, K, D = map(int, input().split())
if X > D:
t = min(X // D, K)
K -= t
X -= t * D
else:
t = min(-X // D, K)
K -= t
X += t * D
K %= 2
if K == 0:
print(abs(X))
else:
if abs(X + D) < abs(X - D):
print(abs(X + D))
else:
print(abs(X - D))
Break through in 52 minutes. TLE × 1. At first, I missed the "less than or equal to" of "K times or less", wrote the code with doubling, and wondered why the output example 1 was not 7. I noticed "the following" and reconsidered, I thought that O ( N </ i> 2 </ sup>) would not pass, and if loop detection is performed and the total in that loop is positive, the number of possible loops × I wrote it thinking that I should add the total in the loop, but TLE. I can not help it, so I rewrote it in Go language and it passed quickly.
package main
import (
"bufio"
"fmt"
"math"
"os"
"strconv"
)
func max(x, y int) int {
if x > y {
return x
}
return y
}
func main() {
defer flush()
N := readInt()
K := readInt()
P := make([]int, N)
for i := 0; i < N; i++ {
P[i] = readInt()
}
C := make([]int, N)
for i := 0; i < N; i++ {
C[i] = readInt()
}
result := math.MinInt64
for i := 0; i < N; i++ {
p := P[i] - 1
c := C[p]
k := K - 1
t := c
for p != i && k != 0 {
p = P[p] - 1
c += C[p]
t = max(t, c)
k--
}
if k == 0 || c <= 0 {
result = max(result, t)
continue
}
l := K - k
c = c * (K/l - 1)
k = K - (K/l-1)*l
t = c
for k != 0 {
p = P[p] - 1
c += C[p]
t = max(t, c)
k--
}
result = max(result, t)
}
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
}
var stdoutWriter = bufio.NewWriter(os.Stdout)
func flush() {
stdoutWriter.Flush()
}
func println(args ...interface{}) (int, error) {
return fmt.Fprintln(stdoutWriter, args...)
}
Instead of rewriting it in Go, I just had to put it out in PyPy.
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))
result = -float('inf')
for i in range(N):
p = P[i] - 1
c = C[p]
k = K - 1
t = c
while p != i and k != 0:
p = P[p] - 1
c += C[p]
t = max(t, c)
k -= 1
if k == 0 or c <= 0:
result = max(result, t)
continue
l = K - k
c = c * (K // l - 1)
k = K - (K // l - 1) * l
t = c
while k != 0:
p = P[p] - 1
c += C[p]
t = max(t, c)
k -= 1
result = max(result, t)
print(result)
I couldn't break through. I thought it would be easy with DP without "However, you can only pick up up to 3 items in the same row of squares." There were quite a few people who skipped D and solved E. So, if you know something, isn't there a difference in difficulty?
Recommended Posts