結果

問題 No.436 ccw
ユーザー fjafjafjafjafjafja
提出日時 2017-09-10 23:47:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 3,800 ms
コンパイル使用メモリ 76,184 KB
実行使用メモリ 43,112 KB
最終ジャッジ日時 2024-04-25 03:14:33
合計ジャッジ時間 6,594 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
37,052 KB
testcase_01 AC 54 ms
36,664 KB
testcase_02 AC 51 ms
37,036 KB
testcase_03 AC 53 ms
36,956 KB
testcase_04 AC 55 ms
37,040 KB
testcase_05 AC 52 ms
36,900 KB
testcase_06 AC 57 ms
36,896 KB
testcase_07 AC 55 ms
36,668 KB
testcase_08 AC 54 ms
36,872 KB
testcase_09 AC 56 ms
36,900 KB
testcase_10 AC 54 ms
36,896 KB
testcase_11 AC 54 ms
36,972 KB
testcase_12 AC 54 ms
36,784 KB
testcase_13 AC 54 ms
36,652 KB
testcase_14 AC 52 ms
36,956 KB
testcase_15 AC 57 ms
36,920 KB
testcase_16 AC 58 ms
37,144 KB
testcase_17 AC 55 ms
36,788 KB
testcase_18 AC 59 ms
37,336 KB
testcase_19 AC 59 ms
37,128 KB
testcase_20 AC 61 ms
37,176 KB
testcase_21 AC 110 ms
43,068 KB
testcase_22 AC 111 ms
42,712 KB
testcase_23 AC 119 ms
42,668 KB
testcase_24 AC 118 ms
43,112 KB
testcase_25 AC 116 ms
42,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class N436
{
	static int ans=0;
	static int cnt=0;
	public static void main(String[] args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		int c=0,w=0;
		int[] h=new int[str.length()];
		for(int i=0;i<str.length();i++)
		{
			h[i]=0;
		}
		for(int i=0;i<str.length();i++)
		{
			String now=str.substring(i, i+1);
			if(now.equals("c"))
			{
				c++;
			}
			else if(now.equals("w")&&c>=2)
			{
				h[i-2]++;h[i-1]++;h[i]++;
				c=0;
				cnt++;
			}
			else
			{
				c=0;
			}
		}

		search(h,0,str.length()-1);

		System.out.println(ans);

	}

	static void search(int[] h,int st,int las)
	{
		int sbuf=0;
		int lbuf=0;

		if(cnt>0)
		{
			while(h[st]!=1)
			{
				st++;
				sbuf++;
			}sbuf++;//このbufが初めの1を消すまでの工程数


			while(h[las]!=1)
			{
				las--;
				lbuf++;
			}lbuf++;

			cnt--;

			if(sbuf<=lbuf)
			{
				h[st]=0;h[st+1]=0;h[st+2]=0;
				ans+=sbuf;
				search(h,st+1,las);
			}
			else
			{
				h[las]=0;h[las-1]=0;h[las-2]=0;
				ans+=lbuf;
				search(h,st,las-1);
			}


		}
		else
		{
			return;
		}


	}




}
0