結果
| 問題 | No.252 "良問"(良問とは言っていない (2) |
| コンテスト | |
| ユーザー |
fmhr
|
| 提出日時 | 2015-07-25 18:50:27 |
| 言語 | Go (1.23.4) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 983 bytes |
| コンパイル時間 | 12,851 ms |
| コンパイル使用メモリ | 233,516 KB |
| 実行使用メモリ | 21,780 KB |
| 最終ジャッジ日時 | 2024-10-10 19:24:45 |
| 合計ジャッジ時間 | 18,427 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 6 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
var a int
fmt.Scan(&a)
for i := 0; i < a; i++ {
solve()
}
}
func solve() {
var s string
fmt.Scan(&s)
s_len := len(s)
cost := 100
p_cost := 0
// "problem"のdiff()を計算しておく
diff_p := make([]int, s_len)
for j:=0; j<s_len-6; j++{
diff_p[j] = diff(s[j:j+7], "problem")
}
for j := 0; j < s_len; j++ {
if j >= 7 {
if s[j-7:j] == "problem" {
p_cost++
}
}
for k := j + 4; k < s_len-6; k++ {
cost = min(cost, diff(s[j:j+4], "good")+diff_p[k]+p_cost)
}
}
fmt.Println(cost)
}
func min(x, y int) int {
if x > y {
x = y
}
return x
}
func diff(s1, s2 string) int {
c := 0
for i := 0; i < len(s1); i++ {
if s1[i] != s2[i] {
c++
}
}
return c
}
var s = bufio.NewScanner(os.Stdin)
func next() string {
s.Split(bufio.ScanWords)
s.Scan()
return s.Text()
}
func nextInt() int {
i, e := strconv.Atoi(next())
if e != nil {
panic(e)
}
return i
}
fmhr