結果

問題 No.52 よくある文字列の問題
ユーザー holegumaholeguma
提出日時 2015-08-12 00:16:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 96 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 78,184 KB
実行使用メモリ 55,364 KB
最終ジャッジ日時 2023-10-22 04:00:58
合計ジャッジ時間 3,160 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
53,636 KB
testcase_01 AC 49 ms
53,636 KB
testcase_02 AC 54 ms
53,668 KB
testcase_03 AC 50 ms
53,640 KB
testcase_04 AC 87 ms
55,364 KB
testcase_05 AC 72 ms
54,244 KB
testcase_06 AC 96 ms
55,248 KB
testcase_07 AC 62 ms
54,232 KB
testcase_08 AC 52 ms
53,652 KB
testcase_09 AC 52 ms
53,640 KB
testcase_10 AC 52 ms
53,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.ArrayList;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static int ans=0;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
StringBuilder sb1=new StringBuilder(line);
StringBuilder sb2=new StringBuilder("");
ArrayList<String> array=new ArrayList<String>();
dfs(sb1,sb2,array);
out.println(ans);
out.flush();
}
}

private static void dfs(StringBuilder sb1,StringBuilder sb2,ArrayList<String> array){
if(sb1.length()==0){
String str=sb2.toString();
if(array.indexOf(str)<0){
ans++;
array.add(str);
}
return;
}
String first=sb1.substring(0,1);
String last=sb1.substring(sb1.length()-1);
sb1.deleteCharAt(0);
sb2.append(first);
dfs(sb1,sb2,array);
sb1.insert(0,first);
sb2.deleteCharAt(sb2.length()-1);
sb1.deleteCharAt(sb1.length()-1);
sb2.append(last);
dfs(sb1,sb2,array);
sb1.append(last);
sb2.deleteCharAt(sb2.length()-1);
}
}
0