結果
問題 | No.345 最小チワワ問題 |
ユーザー |
![]() |
提出日時 | 2018-07-28 16:35:44 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,019 bytes |
コンパイル時間 | 11,048 ms |
コンパイル使用メモリ | 226,444 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 05:06:39 |
合計ジャッジ時間 | 11,959 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
package mainimport ("bufio""fmt""math""os")type myScanner struct {*bufio.Scanner}func NewScanner(fp *os.File) *myScanner {return &myScanner{bufio.NewScanner(fp),}}func (sc *myScanner) nextLine() (bool, string) {flg := sc.Scan()return !flg, sc.Text()}func check(in string) bool {c, w := false, falsefor _, s := range in {if s == 'c' {c = truecontinue}if c && !w && s == 'w' {w = truecontinue}if c && w && s == 'w' {return true}}return false}func cww(in string) int {min := math.MaxInt64for i, s1 := range in {if s1 == 'c' {wc := 0for j, s2 := range in {if i >= j {continue}if s2 == 'w' {wc++}if wc == 2 {min = int(math.Min(float64(min), float64(j-i)+1))break}}}}return min}func main() {sc := NewScanner(os.Stdin)for {flg, in := sc.nextLine()if flg {break}if !check(in) {fmt.Println(-1)continue}fmt.Println(cww(in))}}