結果
問題 | No.559 swapAB列 |
ユーザー |
![]() |
提出日時 | 2017-08-25 22:44:33 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 712 bytes |
コンパイル時間 | 586 ms |
コンパイル使用メモリ | 65,868 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-15 16:05:06 |
合計ジャッジ時間 | 1,042 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 |
ソースコード
#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;}