結果

問題 No.2021 Not A but B
ユーザー yamakeyamake
提出日時 2022-07-29 21:43:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,292 bytes
コンパイル時間 1,667 ms
コンパイル使用メモリ 171,392 KB
実行使用メモリ 4,928 KB
最終ジャッジ日時 2023-09-26 20:15:43
合計ジャッジ時間 3,024 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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