답안 #1012440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012440 2024-07-02T07:28:02 Z m5588ohammed Difference (POI11_roz) C++14
30 / 100
522 ms 13384 KB
/******************************************************************************

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"
int fre[500];
vector <int> v[500],arr;
int pre[1000000];
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=1;
    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;
}

Compilation message

roz.cpp: In function 'void construct(char, char)':
roz.cpp:18:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |     while(i!=v[a].size()||j!=v[b].size()){
      |                ^
roz.cpp:18:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(i!=v[a].size()||j!=v[b].size()){
      |           ~^~~~~~~~~~~~~
roz.cpp:18:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |     while(i!=v[a].size()||j!=v[b].size()){
      |                                ^
roz.cpp:18:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     while(i!=v[a].size()||j!=v[b].size()){
      |                           ~^~~~~~~~~~~~~
roz.cpp:19:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   19 |         if(i==v[a].size()){
      |                 ^
roz.cpp:19:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         if(i==v[a].size()){
      |            ~^~~~~~~~~~~~~
roz.cpp:23:22: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |         else if(j==v[b].size()||v[b][j]>v[a][i]){
      |                      ^
roz.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         else if(j==v[b].size()||v[b][j]>v[a][i]){
      |                 ~^~~~~~~~~~~~~
roz.cpp:23:35: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |         else if(j==v[b].size()||v[b][j]>v[a][i]){
      |                                   ^
roz.cpp:23:43: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |         else if(j==v[b].size()||v[b][j]>v[a][i]){
      |                                           ^
roz.cpp: In function 'int main()':
roz.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=0;i<s.size();i++) v[s[i]].push_back(i);
      |                 ~^~~~~~~~~
roz.cpp:58:39: warning: array subscript has type 'char' [-Wchar-subscripts]
   58 |     for(int i=0;i<s.size();i++) v[s[i]].push_back(i);
      |                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 Runtime error 1 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Runtime error 1 ms 600 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 348 KB Output is correct
2 Runtime error 1 ms 480 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 1116 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 479 ms 10232 KB Output is correct
2 Runtime error 1 ms 600 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 460 ms 9976 KB Output is correct
2 Correct 363 ms 9720 KB Output is correct
3 Correct 138 ms 8824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 9976 KB Output is correct
2 Correct 165 ms 13384 KB Output is correct
3 Runtime error 10 ms 12532 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 522 ms 9976 KB Output is correct
2 Runtime error 13 ms 13032 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -