結果
問題 | No.559 swapAB列 |
ユーザー |
![]() |
提出日時 | 2020-09-21 12:15:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 425 bytes |
コンパイル時間 | 2,474 ms |
コンパイル使用メモリ | 193,072 KB |
最終ジャッジ日時 | 2025-01-14 19:14:31 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 7 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; int res = 0; for (int i = (int)S.size() - 1; i > -1; i--) { if (S[i] == 'A') { for (int j = i - 1; j > -1; j--) { if (S[j] == 'B') { swap(S[i], S[j]); res += i - j; break; } } } } cout << res << '\n'; return 0; }