結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー 👑 horiesinitihoriesiniti
提出日時 2018-03-14 16:21:45
言語 Ruby
(3.2.2)
結果
AC  
実行時間 81 ms / 1,000 ms
コード長 683 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 11,476 KB
実行使用メモリ 15,340 KB
最終ジャッジ日時 2023-08-18 14:29:48
合計ジャッジ時間 6,519 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,164 KB
testcase_01 AC 78 ms
15,092 KB
testcase_02 AC 78 ms
15,240 KB
testcase_03 AC 78 ms
15,092 KB
testcase_04 AC 76 ms
15,168 KB
testcase_05 AC 76 ms
15,092 KB
testcase_06 AC 77 ms
15,240 KB
testcase_07 AC 77 ms
15,280 KB
testcase_08 AC 77 ms
15,144 KB
testcase_09 AC 78 ms
15,040 KB
testcase_10 AC 78 ms
15,252 KB
testcase_11 AC 77 ms
15,244 KB
testcase_12 AC 77 ms
15,144 KB
testcase_13 AC 77 ms
15,272 KB
testcase_14 AC 77 ms
15,276 KB
testcase_15 AC 76 ms
15,244 KB
testcase_16 AC 78 ms
15,028 KB
testcase_17 AC 77 ms
15,340 KB
testcase_18 AC 77 ms
15,024 KB
testcase_19 AC 79 ms
15,028 KB
testcase_20 AC 78 ms
15,124 KB
testcase_21 AC 77 ms
15,076 KB
testcase_22 AC 77 ms
15,084 KB
testcase_23 AC 78 ms
15,028 KB
testcase_24 AC 76 ms
15,156 KB
testcase_25 AC 77 ms
15,328 KB
testcase_26 AC 77 ms
15,164 KB
testcase_27 AC 77 ms
15,028 KB
testcase_28 AC 76 ms
15,128 KB
testcase_29 AC 76 ms
15,244 KB
testcase_30 AC 76 ms
15,136 KB
testcase_31 AC 76 ms
15,112 KB
testcase_32 AC 76 ms
15,164 KB
testcase_33 AC 77 ms
15,240 KB
testcase_34 AC 76 ms
15,160 KB
testcase_35 AC 76 ms
15,036 KB
testcase_36 AC 76 ms
15,024 KB
testcase_37 AC 77 ms
15,280 KB
testcase_38 AC 77 ms
15,328 KB
testcase_39 AC 76 ms
15,108 KB
testcase_40 AC 78 ms
15,084 KB
testcase_41 AC 76 ms
15,032 KB
testcase_42 AC 77 ms
15,140 KB
testcase_43 AC 77 ms
15,300 KB
testcase_44 AC 81 ms
15,252 KB
testcase_45 AC 77 ms
15,092 KB
testcase_46 AC 76 ms
15,084 KB
testcase_47 AC 77 ms
15,316 KB
testcase_48 AC 77 ms
15,136 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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