結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー horiesiniti
提出日時 2018-03-14 16:21:45
言語 Ruby
(3.4.1)
結果
AC  
実行時間 84 ms / 1,000 ms
コード長 683 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2024-11-27 20:24:26
合計ジャッジ時間 5,368 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
	}
	if p1<0
		arr<<-14
	else
		arr<<p1
	end
	if arr[1]<0
		arr[1]=-14
	end
	arr.shift
	return arr
end
def g(s,n)
	ans=[n,s.max,s.last+n,s[0]+n].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