結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー horiesiniti
提出日時 2018-03-14 09:18:51
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 602 bytes
コンパイル時間 345 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-11-26 03:00:41
合計ジャッジ時間 6,863 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(s)
	arr=[]
	old=""
	p1=0
	s.chars{|e|
		if old==e
			if e=="o"
				p1+=1
			else
				p1-=1
			end
		else
			arr<<p1
			if e=="o"
				p1=1
			else
				p1=-1
			end
		end
		old=e
	}
	arr<<p1
	arr.shift
	return arr
end
def g(s,n)
	ans=[n,s.max].max
	s.size.times{|i|
		if s[i]<0
			t=-s[i]
			if t>n
				if i>0
					ans=[ans,n+s[i-1]].max
				end
				if i<s.size-1
					ans=[ans,n+s[i+1]].max
				end
			else
				t2=t
				if i>0
					t2+=s[i-1]
				end
				if i<s.size-1
					t2+=s[i+1]
				end
				ans=[ans,t2].max
			end
		end
	}
	return ans
end

n=gets.to_i
s=gets.chomp+gets.chomp
puts g(f(s),n)
0