結果

問題 No.2021 Not A but B
ユーザー wanuiwanui
提出日時 2022-07-29 21:38:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 206,656 KB
実行使用メモリ 15,952 KB
最終ジャッジ日時 2023-09-26 20:02:00
合計ジャッジ時間 4,182 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 45 ms
11,120 KB
testcase_09 AC 46 ms
11,024 KB
testcase_10 AC 46 ms
11,184 KB
testcase_11 AC 44 ms
11,060 KB
testcase_12 AC 43 ms
11,020 KB
testcase_13 AC 44 ms
11,104 KB
testcase_14 AC 45 ms
11,232 KB
testcase_15 AC 45 ms
11,044 KB
testcase_16 AC 44 ms
10,872 KB
testcase_17 AC 44 ms
10,856 KB
testcase_18 AC 47 ms
11,132 KB
testcase_19 AC 46 ms
11,120 KB
testcase_20 AC 46 ms
11,072 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 65 ms
15,368 KB
testcase_28 AC 64 ms
15,356 KB
testcase_29 AC 66 ms
15,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

int main() {
    ioinit();
    ll N;
    cin >> N;
    string S;
    cin >> S;

    set<pll> changed;
    bool nochange = false;
    for (ll i = 0; i < N - 1; i++) {
        bool cur = (S[i] == 'A');
        bool nxt = (S[i + 1] == 'A');
        if (cur && nxt) {
            changed.insert({i, i + 1});
        }
        if (cur && !nxt) {
            changed.insert({i, i});
        }
        if (!cur && nxt) {
            changed.insert({i + 1, i + 1});
        }
        if (!cur && !nxt) {
            nochange = true;
        }
    }
    ll ans = changed.size();
    if (nochange) ans++;
    print(ans);
    return 0;
}
0