結果

問題 No.2021 Not A but B
ユーザー yamakeyamake
提出日時 2022-07-29 21:47:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,499 bytes
コンパイル時間 1,631 ms
コンパイル使用メモリ 170,156 KB
実行使用メモリ 4,900 KB
最終ジャッジ日時 2023-09-26 20:26:06
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 8 ms
4,648 KB
testcase_09 AC 8 ms
4,900 KB
testcase_10 AC 8 ms
4,688 KB
testcase_11 AC 8 ms
4,708 KB
testcase_12 AC 8 ms
4,656 KB
testcase_13 AC 8 ms
4,636 KB
testcase_14 AC 8 ms
4,688 KB
testcase_15 AC 8 ms
4,688 KB
testcase_16 AC 8 ms
4,680 KB
testcase_17 AC 8 ms
4,748 KB
testcase_18 AC 8 ms
4,688 KB
testcase_19 AC 8 ms
4,756 KB
testcase_20 AC 8 ms
4,740 KB
testcase_21 AC 2 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 1 ms
4,380 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 8 ms
4,712 KB
testcase_28 AC 8 ms
4,688 KB
testcase_29 AC 6 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:47:15: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   47 |     for(auto& [c,m]:b){
      |               ^
main.cpp:52:15: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   52 |     for(auto& [c,m]:b){
      |               ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<"\n";
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1.1e18;const int inf=1.01e9;
constexpr int MOD=1000000007;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }

template<class T>
vector<pair<T,int>> RunLengthPress(vector<T> a){
  int cnt=1;T last=a[0];
  int n=a.size();
  vector<pair<T,int>> res;
  rep1(i,n-1){
    if(last==a[i])++cnt;
    else{
      res.push_back({last,cnt});
      last=a[i];cnt=1;
    }
  }
  res.push_back({last,cnt});
  return res;
}

signed main(){
    int n;cin>>n;
    string s;cin>>s;
    vector<char> a(n);
    rep(i,n)a[i]=s[i];
    auto b=RunLengthPress(a);
    int res=0;
    if(b.size()==1){
        if(b[0].first=='B'){
            cout<<1<<"\n";
            return 0;
        }
        cout<<b[0].second-1<<"\n";
        return 0;
    }
    for(auto& [c,m]:b){
        if(c=='B')continue;
        if(m==1)++res;
        else res+=m+1;
    }
    for(auto& [c,m]:b){
        if(c=='B'&&m>=2){
            ++res;
            break;
        }
    }
    if(s[0]=='A'&&s[1]=='A')--res;
    if(s[n-2]=='A'&&s[n-1]=='A')--res;
    cout<<res<<"\n";
    return 0;
}
0