結果
問題 |
No.559 swapAB列
|
ユーザー |
![]() |
提出日時 | 2017-08-26 07:51:27 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 641 bytes |
コンパイル時間 | 1,224 ms |
コンパイル使用メモリ | 158,308 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-10-15 17:25:35 |
合計ジャッジ時間 | 4,612 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | TLE * 1 -- * 6 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> PI; int main() { cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; int a = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'A') a++; } int ans = 0; int pos = 0; while (true) { bool flag = false; for (int i = pos; i < s.size(); i++) { if (s[i] == 'B' && s[i+1] == 'A') { s[i] = 'A'; s[i+1] = 'B'; ans++; break; } } pos = s.find('B') - 1; //cout << s << pos << endl; if (pos + 1 == a) { break; } } cout << ans << endl; return 0; }