結果
| 問題 |
No.436 ccw
|
| コンテスト | |
| ユーザー |
fjafjafja
|
| 提出日時 | 2017-09-10 23:47:08 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 1,236 bytes |
| コンパイル時間 | 3,227 ms |
| コンパイル使用メモリ | 76,020 KB |
| 実行使用メモリ | 43,176 KB |
| 最終ジャッジ日時 | 2024-11-07 12:54:19 |
| 合計ジャッジ時間 | 6,106 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
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;
}
}
}
fjafjafja