/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
int fre[500];
vector <int> v[500],arr;
int pre[2000000];
void construct(char a,char b){
int i=0,j=0;
arr.clear();
while(i!=v[a].size()||j!=v[b].size()){
if(i==v[a].size()){
arr.push_back(-1);
j++;
}
else if(j==v[b].size()){
arr.push_back(1);
i++;
}
else if(v[b][j]>v[a][i]){
arr.push_back(1);
i++;
}
else{
arr.push_back(-1);
j++;
}
}
return;
}
int calc(){
int n=arr.size(),st=0,mn=1e9,ans=0;
pre[0]=arr[0];
for(int i=1;i<n;i++) pre[i]=pre[i-1]+arr[i];
for(int i=0;i<n;i++){
if(arr[i]==-1){
for(int j=st;j<i;j++) mn=min(mn,pre[j]);
mn=min(mn,0ll);
st=i;
}
ans=max(ans,pre[i]-mn);
}
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,ans=0;
cin>>n;
string s;
cin>>s;
for(int i=0;i<s.size();i++){
v[s[i]].push_back(i);
fre[s[i]]++;
}
for(int c1='a';c1<='z';c1++){
for(int c2='a';c2<='z';c2++){
if(c1==c2||fre[c1]==0||fre[c2]==0) continue;
construct(c1,c2);
ans=max(ans,calc());
}
}
cout<<ans<<endl;
return 0;
}
Compilation message
roz.cpp: In function 'void construct(char, char)':
roz.cpp:19:16: warning: array subscript has type 'char' [-Wchar-subscripts]
19 | while(i!=v[a].size()||j!=v[b].size()){
| ^
roz.cpp:19:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | while(i!=v[a].size()||j!=v[b].size()){
| ~^~~~~~~~~~~~~
roz.cpp:19:32: warning: array subscript has type 'char' [-Wchar-subscripts]
19 | while(i!=v[a].size()||j!=v[b].size()){
| ^
roz.cpp:19:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | while(i!=v[a].size()||j!=v[b].size()){
| ~^~~~~~~~~~~~~
roz.cpp:20:17: warning: array subscript has type 'char' [-Wchar-subscripts]
20 | if(i==v[a].size()){
| ^
roz.cpp:20:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if(i==v[a].size()){
| ~^~~~~~~~~~~~~
roz.cpp:24:22: warning: array subscript has type 'char' [-Wchar-subscripts]
24 | else if(j==v[b].size()){
| ^
roz.cpp:24:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | else if(j==v[b].size()){
| ~^~~~~~~~~~~~~
roz.cpp:28:19: warning: array subscript has type 'char' [-Wchar-subscripts]
28 | else if(v[b][j]>v[a][i]){
| ^
roz.cpp:28:27: warning: array subscript has type 'char' [-Wchar-subscripts]
28 | else if(v[b][j]>v[a][i]){
| ^
roz.cpp: In function 'int main()':
roz.cpp:63:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
roz.cpp:64:15: warning: array subscript has type 'char' [-Wchar-subscripts]
64 | v[s[i]].push_back(i);
| ^
roz.cpp:65:17: warning: array subscript has type 'char' [-Wchar-subscripts]
65 | fre[s[i]]++;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
1628 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
6 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
496 ms |
14224 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
262 ms |
11584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
515 ms |
14268 KB |
Output is correct |
2 |
Correct |
384 ms |
13048 KB |
Output is correct |
3 |
Correct |
79 ms |
10276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
489 ms |
13816 KB |
Output is correct |
2 |
Correct |
53 ms |
19932 KB |
Output is correct |
3 |
Correct |
81 ms |
12692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
461 ms |
14364 KB |
Output is correct |
2 |
Correct |
36 ms |
25684 KB |
Output is correct |
3 |
Correct |
121 ms |
12448 KB |
Output is correct |