結果
| 問題 | No.252 "良問"(良問とは言っていない (2) |
| コンテスト | |
| ユーザー |
fmhr
|
| 提出日時 | 2015-07-25 18:42:06 |
| 言語 | Go1.4 (1.4.2) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 982 bytes |
| コンパイル時間 | 383 ms |
| コンパイル使用メモリ | 32,384 KB |
| 最終ジャッジ日時 | 2025-12-03 10:27:16 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | TLE * 1 -- * 6 |
ソースコード
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
var a int
a = nextInt()
for i := 0; i < a; i++ {
solve()
}
}
func solve() {
var s string
s = next()
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