結果

問題 No.150 "良問"(良問とは言っていない
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-22 09:25:55
言語 Go
(1.22.1)
結果
AC  
実行時間 13 ms / 5,000 ms
コード長 1,122 bytes
コンパイル時間 12,525 ms
コンパイル使用メモリ 232,264 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 09:49:30
合計ジャッジ時間 13,351 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 13 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 4 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 6 ms
5,376 KB
testcase_15 AC 6 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 7 ms
5,376 KB
testcase_19 AC 7 ms
5,376 KB
testcase_20 AC 8 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func main() {
	var n int
	_, _ = fmt.Scan(&n)

	good := "good"
	problem := "problem"

	for i := 0; i < n; i++ {
		s := ""
		_, _ = fmt.Scan(&s)

		// goodへの書き換えに必要な手数の一覧
		goodCost := make([]int, 0)
		for i := 0; i < len(s)-len(problem)-len(good)+1; i++ {
			d := 0
			for j := range good {
				if good[j] != s[i+j] {
					d++
				}
			}
			goodCost = append(goodCost, d)
			// fmt.Println(good, string(s[i:i+len(good)]), d)
		}

		// problemへの書き換えに必要な手数の一覧
		problemCost := make([]int, 0)
		for i := len(good); i < len(s)-len(problem)+1; i++ {
			d := 0
			for j := range problem {
				if problem[j] != s[i+j] {
					d++
				}
			}
			problemCost = append(problemCost, d)
			// fmt.Println(problem, string(s[i:i+len(problem)]), d)
		}

		// 可能な組み合わせのうち最小となるものを出力
		min := -1
		for j := 0; j < len(goodCost); j++ {
			for k := j; k < len(problemCost); k++ {
				if min > goodCost[j]+problemCost[k] || min == -1 {
					min = goodCost[j] + problemCost[k]
				}
			}
		}
		fmt.Println(min)
	}
}
0