結果
| 問題 |
No.559 swapAB列
|
| コンテスト | |
| ユーザー |
zaichu
|
| 提出日時 | 2017-10-22 04:28:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 858 bytes |
| コンパイル時間 | 1,978 ms |
| コンパイル使用メモリ | 169,872 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 13:01:43 |
| 合計ジャッジ時間 | 2,254 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y)
{
if (y == 0)
return x;
return gcd(y, x % y);
}
long long lcm(long long x, long long y)
{
if (x == 0 || y == 0)
return 0;
return x / gcd(x, y) * y;
}
int main()
{
string s;
cin >> s;
int n = s.size();
string ss = s;
sort(ss.begin(), ss.end());
int cnt = 0;
while (ss != s)
{
for (int i = 0; i < n - 1; i++)
{
if (s[i] == 'B' and s[i + 1] == 'A')
{
cnt++;
swap(s[i], s[i + 1]);
}
}
for (int i = n - 1; i < 0; i--)
{
if (s[i] == 'A' and s[i - 1] == 'B')
{
cnt++;
swap(s[i], s[i - 1]);
}
}
}
cout << cnt << endl;
}
zaichu