結果
| 問題 |
No.2021 Not A but B
|
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2022-07-29 22:19:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 90 ms / 2,000 ms |
| コード長 | 992 bytes |
| コンパイル時間 | 4,457 ms |
| コンパイル使用メモリ | 256,000 KB |
| 最終ジャッジ日時 | 2025-01-30 15:25:58 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
int main() {
int n;
string s;
cin >> n >> s;
set<pair<int, int>> st;
int ans = 0;
for (int i = 0; i + 1 < n; i++) {
if (s[i] == 'A' && s[i + 1] == 'A') {
if (st.find({i, i + 1}) == st.end()) {
ans++;
st.emplace(i, i + 1);
}
} else if (s[i] == 'A') {
if (st.find({i, -1}) == st.end()) {
ans++;
st.emplace(i, -1);
}
} else if (s[i + 1] == 'A') {
if (st.find({i + 1, -1}) == st.end()) {
ans++;
st.emplace(i + 1, -1);
}
} else {
if (st.find({-1, -1}) == st.end()) {
ans++;
st.emplace(-1, -1);
}
}
}
cout << ans << endl;
return 0;
}
ldsyb