結果

問題 No.345 最小チワワ問題
ユーザー fmhr
提出日時 2016-06-24 01:55:19
言語 Go
(1.23.4)
結果
WA  
実行時間 -
コード長 408 bytes
コンパイル時間 14,074 ms
コンパイル使用メモリ 220,216 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 19:50:40
合計ジャッジ時間 14,681 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 21 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	var c int
	l := len(s)
	w1 := l
	w2 := l
	ans := l
	for j := l - 1; j >= 0; j-- {
		if s[j] == 'w' {
			w1, w2 = j, w1
		}
		if s[j] == 'c' {
			c = j
			if w2 < l {
				ans = minInt(ans, w2-c+1)
			}
		}
	}
	if ans == l+1 {
		ans = -1
	}
	fmt.Println(ans)
}

func minInt(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
0