結果

問題 No.559 swapAB列
ユーザー pinebookspinebooks
提出日時 2017-08-25 22:44:33
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 66,096 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 15:38:59
合計ジャッジ時間 1,056 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int find_B(string S) {
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'B')
      return i;
  }
  return -1;
}

int main() {
  string S;
  cin >> S;
  vector<int> B_locations;
  int B_counts = 0;
  if (S.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == 'B') {
      B_locations.push_back(i);
      ++B_counts;
    }
  }
  sort(B_locations.begin(), B_locations.end(), greater<int>());
  int answer = 0;
  for (int i = 0; i < B_locations.size(); ++i) {
    answer += S.size() - i - B_locations[i] - 1;
  }
  cout << answer << endl;
  return 0;
}
0