結果
問題 |
No.672 最長AB列
|
ユーザー |
|
提出日時 | 2020-08-27 13:28:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 852 bytes |
コンパイル時間 | 1,009 ms |
コンパイル使用メモリ | 93,504 KB |
実行使用メモリ | 6,912 KB |
最終ジャッジ日時 | 2024-11-07 15:59:40 |
合計ジャッジ時間 | 2,098 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:25:23: warning: iteration 400040 invokes undefined behavior [-Waggressive-loop-optimizations] 25 | co[i] = -1; | ~~~~~~^~~~ main.cpp:24:27: note: within this loop 24 | for (int i = 0; i <= 400040; i++) { | ~~^~~~~~~~~ main.cpp:25:23: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 1600164 bytes into a region of size 1600160 overflows the destination [-Wstringop-overflow=] 25 | co[i] = -1; | ~~~~~~^~~~ main.cpp:17:5: note: destination object 'co' of size 1600160 17 | int co[400040]; | ^~
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; int co[400040]; int a[200020], b[200020]; int main() { co[0] = 0; string s; cin >> s; int n = s.size(); for (int i = 0; i <= 400040; i++) { co[i] = -1; } for (int i = 1; i <= n; i++) { if (s[i - 1] == 'A') { a[i]++; } else { b[i]++; } a[i] += a[i - 1]; b[i] += b[i - 1]; } int ans = 0; for (int i = 0; i <= n; i++) { if (co[a[i] - b[i] + 200000] == -1) { co[a[i] - b[i] + 200000] = i; } else { if (ans < i - co[a[i] - b[i] + 200000]) { ans = i - co[a[i] - b[i] + 200000]; } } } cout << ans << endl; return 0; }