hxrxchang / atcoder

https://atcoder.jp/users/hxrxchang
0 stars 0 forks source link

E - Make it Palindrome #69

Open hxrxchang opened 1 month ago

hxrxchang commented 1 month ago

https://atcoder.jp/contests/abc290/tasks/abc290_e

問題概要

数列Aの連続部分に対して、それを回分にするために変更する要素数の総和を求めよ。

解き方

愚直に解くとこう↓。もちろんTLE

func solve() {
    n := getInt()
    a := getInts()

    ans := 0
    for i := 1; i <= n; i++ {
        for j := 0; j <= n-i; j++ {
            ans += calc(a[j:j+i])
        }
    }

    fmt.Println(ans)
}

func calc(a []int) int {
    cnt := 0
    for i := 0; i < len(a) / 2; i++ {
        if a[i] != a[len(a)-1-i] {
            cnt++
        }
    }
    return cnt
}

https://atcoder.jp/contests/abc290/submissions/54462731