結果

問題 No.2021 Not A but B
ユーザー forest3
提出日時 2022-08-01 01:59:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 172,620 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-21 08:30:00
合計ジャッジ時間 3,332 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int test( int N, string S )
{
	set<string> st;
	for( int i = 0; i < N - 1; i++ ) {
		string s = S;
		s[i] = 'B';
		s[i + 1] = 'B';
		st.insert( s );
	}
	return st.size();
}

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

	int ans = 0, f = 0;
	for( int i = 0; i < N - 1; i++ ) {
		if( i == 0 ) {
			if( S.substr( 0, 2) == "BB" ) {
				ans = 1;
				f = 1;
			}
			else ans = 1;
		}
		else {
			if( S.substr( i, 2 ) == "BB" ) {
				if( f == 0 ) {
					ans++;
					f = 1;
				}
			}
			else ans++;
			if( S.substr( i - 1, 3 ) == "BAB" ) ans--;
		}
	}

	cout << ans << endl;
}
0