답안 #202895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202895 2020-02-18T15:53:37 Z MKopchev Difference (POI11_roz) C++14
100 / 100
396 ms 6340 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int n;
vector<int> seen[26];
int get_inp()
{
    char ret;
    scanf("%c",&ret);
    while('a'>ret||ret>'z')scanf("%c",&ret);
    return ret-'a';
}
int ask(int big,int small)
{
    if(seen[big].size()==0||seen[small].size()==0)return 0;
    int mx=0,current=0;

    int l=0,r=0,last_in=0;
    while(l<seen[big].size()||r<seen[small].size())
    {
        if(l==seen[big].size())
        {
            if(current==0)last_in=0;
            current=max(current-1,0);
            r++;
        }
        else if(r==seen[small].size())
        {
            current=current+1;
            l++;
            last_in++;
        }
        else if(seen[big][l]<seen[small][r])
        {
            current=current+1;
            l++;
            last_in++;
        }
        else
        {
            if(current==0)last_in=0;
            current=max(current-1,0);
            r++;
        }

        mx=max(mx,current-(current==last_in));
    }
    return mx;
}
int main()
{
    scanf("%i",&n);

    for(int i=1;i<=n;i++)
        seen[get_inp()].push_back(i);

    int output=0;
    for(int big=0;big<26;big++)
        for(int small=0;small<26;small++)
            if(big!=small)output=max(output,ask(big,small));
    printf("%i\n",output);
    return 0;
}

Compilation message

roz.cpp: In function 'int ask(int, int)':
roz.cpp:19:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(l<seen[big].size()||r<seen[small].size())
           ~^~~~~~~~~~~~~~~~~
roz.cpp:19:32: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(l<seen[big].size()||r<seen[small].size())
                               ~^~~~~~~~~~~~~~~~~~~
roz.cpp:21:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(l==seen[big].size())
            ~^~~~~~~~~~~~~~~~~~
roz.cpp:27:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         else if(r==seen[small].size())
                 ~^~~~~~~~~~~~~~~~~~~~
roz.cpp: In function 'int get_inp()':
roz.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%c",&ret);
     ~~~~~^~~~~~~~~~~
roz.cpp:10:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     while('a'>ret||ret>'z')scanf("%c",&ret);
                            ~~~~~^~~~~~~~~~~
roz.cpp: In function 'int main()':
roz.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i",&n);
     ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 7 ms 256 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 352 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 248 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 376 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 892 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 393 ms 6312 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 208 ms 4692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 6200 KB Output is correct
2 Correct 305 ms 5200 KB Output is correct
3 Correct 87 ms 4848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 6340 KB Output is correct
2 Correct 91 ms 5472 KB Output is correct
3 Correct 79 ms 5488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 389 ms 5724 KB Output is correct
2 Correct 96 ms 5248 KB Output is correct
3 Correct 94 ms 5572 KB Output is correct