結果

問題 No.672 最長AB列
ユーザー elphe
提出日時 2024-12-24 23:41:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 748 bytes
コンパイル時間 1,130 ms
コンパイル使用メモリ 77,184 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 23:45:42
合計ジャッジ時間 2,119 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:16:32: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 1600008 bytes into a region of size 1600004 overflows the destination [-Wstringop-overflow=]
   16 |                 first_index[i] = UINT32_MAX;
      |                                ^
main.cpp:14:25: note: destination object 'first_index' of size 1600004
   14 |         static uint32_t first_index[400001], ans = 0, count_A = 0, count_B = 0, i;
      |                         ^~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdint>

using namespace std;

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
	static char S[200001];
	cin >> S;

	static uint32_t first_index[400001], ans = 0, count_A = 0, count_B = 0, i;
	for (i = 0; i <= 400001; ++i)
		first_index[i] = UINT32_MAX;

	first_index[0] = 0;
	for (i = 0; ; ++i)
	{
		switch (S[i])
		{
		case 'A':
			++count_A;
			break;

		case 'B':
			++count_B;
			break;

		case '\0':
			cout << ans << '\n';
			return 0;
		}

		if (first_index[200000 + count_A - count_B] == UINT32_MAX)
			first_index[200000 + count_A - count_B] = i + 1;
		else if (ans < i + 1 - first_index[200000 + count_A - count_B])
			ans = i + 1 - first_index[200000 + count_A - count_B];
	}

	return -1;
}
0