結果
| 問題 |
No.672 最長AB列
|
| コンテスト | |
| ユーザー |
Esire
|
| 提出日時 | 2018-11-27 21:02:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 2,000 ms |
| コード長 | 1,048 bytes |
| コンパイル時間 | 1,041 ms |
| コンパイル使用メモリ | 106,672 KB |
| 実行使用メモリ | 12,916 KB |
| 最終ジャッジ日時 | 2024-06-24 07:55:37 |
| 合計ジャッジ時間 | 2,290 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 16 |
ソースコード
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
//g++ -std=c++14 -Wall -O2 -o main.exe main.cpp
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <tuple>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
using namespace std;
#define spc " "
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
typedef pair<int, int> p_ii;
typedef tuple<int, int, int, int> tup;
bool tupComp(tup &t1, tup &t2){
return get<2>(t1) > get<2>(t2);
}
//------------------------------------------------------------------------------
int main(){
string s;
cin >> s;
int c = 0, ans = 0;
map<int, int> m;
m[0] = 0;
for(int i = 0; i < s.size(); i++){
c += (s[i] == 'A' ? 1 : -1);
if(c != 0 && m[c] == 0) m[c] = i + 1;
else{
ans = max(ans, i + 1 - m[c]);
}
}
cout << ans << endl;
return 0;
}
Esire