이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
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()||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]);
st=i;
}
if(arr[i]==1) 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);
for(int c1='a';c1<='z';c1++){
for(int c2='a';c2<='z';c2++){
if(c1==c2) continue;
construct(c1,c2);
ans=max(ans,calc());
}
}
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
roz.cpp: In function 'void construct(char, char)':
roz.cpp:10:16: warning: array subscript has type 'char' [-Wchar-subscripts]
10 | while(i!=v[a].size()||j!=v[b].size()){
| ^
roz.cpp:10:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | while(i!=v[a].size()||j!=v[b].size()){
| ~^~~~~~~~~~~~~
roz.cpp:10:32: warning: array subscript has type 'char' [-Wchar-subscripts]
10 | while(i!=v[a].size()||j!=v[b].size()){
| ^
roz.cpp:10:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | while(i!=v[a].size()||j!=v[b].size()){
| ~^~~~~~~~~~~~~
roz.cpp:11:17: warning: array subscript has type 'char' [-Wchar-subscripts]
11 | if(i==v[a].size()){
| ^
roz.cpp:11:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | if(i==v[a].size()){
| ~^~~~~~~~~~~~~
roz.cpp:15:22: warning: array subscript has type 'char' [-Wchar-subscripts]
15 | else if(j==v[b].size()||v[b][j]>v[a][i]){
| ^
roz.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | else if(j==v[b].size()||v[b][j]>v[a][i]){
| ~^~~~~~~~~~~~~
roz.cpp:15:35: warning: array subscript has type 'char' [-Wchar-subscripts]
15 | else if(j==v[b].size()||v[b][j]>v[a][i]){
| ^
roz.cpp:15:43: warning: array subscript has type 'char' [-Wchar-subscripts]
15 | else if(j==v[b].size()||v[b][j]>v[a][i]){
| ^
roz.cpp: In function 'int main()':
roz.cpp:49:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=0;i<s.size();i++) v[s[i]].push_back(i);
| ~^~~~~~~~~
roz.cpp:49:39: warning: array subscript has type 'char' [-Wchar-subscripts]
49 | for(int i=0;i<s.size();i++) v[s[i]].push_back(i);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |