結果

問題 No.52 よくある文字列の問題
ユーザー alpha_virginisalpha_virginis
提出日時 2015-06-21 12:15:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 880 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 168,440 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 04:00:01
合計ジャッジ時間 2,008 ms
ジャッジサーバーID
(参考情報)
judge10 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

std::set<std::string> ans;

void solve(std::string str1, std::string str2) {
  if( str1.size() == 0 ) {
    ans.insert(str2);
    return;
  }

  char temp1[16];
  char temp2[16];
  
  for(int i = 0; i < str1.size()-1; ++i) {
    temp1[i] = str1[i];
  }
  temp1[str1.size()-1] = '\0';
  for(int i = 0; i < str2.size(); ++i) {
    temp2[i] = str2[i];
  }
  temp2[str2.size()] = str1[str1.size()-1];
  temp2[str2.size()+1] = '\0';
  solve(temp1, temp2);

  for(int i = 1; i < str1.size(); ++i) {
    temp1[i-1] = str1[i];
  }
  temp1[str1.size()-1] = '\0';
  for(int i = 0; i < str2.size(); ++i) {
    temp2[i] = str2[i];
  }
  temp2[str2.size()] = str1[0];
  temp2[str2.size()+1] = '\0';
  solve(temp1, temp2);

  return;
}

int main() {

  std::string str;
  
  std::cin >> str;
  solve(str, "");

  std::cout << ans.size() << std::endl;
  
  return 0;
}
0