結果

問題 No.2021 Not A but B
ユーザー ldsybldsyb
提出日時 2022-07-29 22:19:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 5,158 ms
コンパイル使用メモリ 266,040 KB
実行使用メモリ 13,060 KB
最終ジャッジ日時 2023-09-26 21:34:24
合計ジャッジ時間 7,491 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 58 ms
9,464 KB
testcase_09 AC 58 ms
9,288 KB
testcase_10 AC 58 ms
9,160 KB
testcase_11 AC 56 ms
8,980 KB
testcase_12 AC 57 ms
9,048 KB
testcase_13 AC 57 ms
9,108 KB
testcase_14 AC 58 ms
9,228 KB
testcase_15 AC 56 ms
9,172 KB
testcase_16 AC 58 ms
9,168 KB
testcase_17 AC 56 ms
8,944 KB
testcase_18 AC 59 ms
9,260 KB
testcase_19 AC 59 ms
9,196 KB
testcase_20 AC 59 ms
9,272 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 86 ms
12,520 KB
testcase_28 AC 84 ms
12,276 KB
testcase_29 AC 89 ms
13,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0