結果
| 問題 |
No.2021 Not A but B
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2022-07-31 02:20:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 666 bytes |
| コンパイル時間 | 368 ms |
| コンパイル使用メモリ | 41,412 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-20 22:33:43 |
| 合計ジャッジ時間 | 1,392 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
/* -*- coding: utf-8 -*-
*
* 2021.cc: No.2021 Not A but B - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int MAX_N = 200000;
/* typedef */
/* global variables */
char s[MAX_N + 4];
/* subroutines */
/* main */
int main() {
int n;
scanf("%d%s", &n, s);
int c = 0, d = 0;
for (int i = 0; i < n;) {
int j = i;
while (i < n && s[i] == 'B') i++;
if (i - j >= 2) d = 1;
if (i >= n) break;
j = i;
while (i < n && s[i] == 'A') i++;
int l = i - j;
if (l == 1) c++;
else c += (l + 1) - (j == 0 ? 1 : 0) - (i == n ? 1 : 0);
}
printf("%d\n", c + d);
return 0;
}
tnakao0123