結果
問題 | No.436 ccw |
ユーザー | fjafjafja |
提出日時 | 2017-09-10 23:47:08 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 1,236 bytes |
コンパイル時間 | 5,164 ms |
コンパイル使用メモリ | 73,564 KB |
実行使用メモリ | 54,860 KB |
最終ジャッジ日時 | 2023-08-07 09:10:25 |
合計ジャッジ時間 | 5,845 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
49,116 KB |
testcase_01 | AC | 41 ms
49,096 KB |
testcase_02 | AC | 41 ms
49,404 KB |
testcase_03 | AC | 41 ms
49,148 KB |
testcase_04 | AC | 41 ms
49,244 KB |
testcase_05 | AC | 40 ms
49,136 KB |
testcase_06 | AC | 41 ms
49,428 KB |
testcase_07 | AC | 40 ms
49,208 KB |
testcase_08 | AC | 40 ms
49,176 KB |
testcase_09 | AC | 41 ms
49,256 KB |
testcase_10 | AC | 41 ms
49,100 KB |
testcase_11 | AC | 41 ms
49,208 KB |
testcase_12 | AC | 41 ms
49,144 KB |
testcase_13 | AC | 41 ms
49,164 KB |
testcase_14 | AC | 41 ms
49,104 KB |
testcase_15 | AC | 40 ms
49,060 KB |
testcase_16 | AC | 48 ms
49,168 KB |
testcase_17 | AC | 46 ms
49,300 KB |
testcase_18 | AC | 49 ms
49,144 KB |
testcase_19 | AC | 48 ms
49,672 KB |
testcase_20 | AC | 48 ms
49,352 KB |
testcase_21 | AC | 93 ms
54,008 KB |
testcase_22 | AC | 93 ms
54,860 KB |
testcase_23 | AC | 96 ms
54,664 KB |
testcase_24 | AC | 98 ms
54,564 KB |
testcase_25 | AC | 85 ms
54,624 KB |
ソースコード
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; } } }