Submission #1103948

# Submission time Handle Problem Language Result Execution time Memory
1103948 2024-10-22T11:04:59 Z HiepVu217 Difference (POI11_roz) C++17
30 / 100
541 ms 14420 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 17;
int n, f[N], ans;
string s;
vector <int> v, p[217];
void build (char a, char b)
{
    int i = 0, j = 0;
    while (i < p[a].size() && j < p[b].size())
    {
        if (p[a][i] < p[b][j])
        {
            v.push_back(1);
            ++i;
        }
        else
        {
            v.push_back(-1);
            ++j;
        }
    }
    while (i < p[a].size())
    {
        v.push_back(1);
        ++i;
    }
    while (j < p[b].size())
    {
        v.push_back(-1);
        ++j;
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> s;
    for (int i = 0; i < s.size(); ++i)
    {
        p[s[i]].push_back(i);
    }
    for (char a = 'a'; a <= 'z'; ++a)
    {
        if (!p[a].size())
        {
            continue;
        }
        for (char b = 'a'; b <= 'z'; ++b)
        {
            if (a == b || !p[b].size())
            {
                continue;
            }
            build (a, b);
            for (int i = 1; i <= v.size(); ++i)
            {
                f[i] = f[i - 1] + v[i - 1];
            }
            int m = 0;
            bool ex = 0;
            for (int i = 1; i <= v.size(); ++i)
            {
                if (v[i - 1] == -1)
                {
                    ex = 1;
                }
                if (ex)
                {
                    m = min (m, f[i]);
                    ans = max (ans, f[i] - m);
                }
            }
            v.clear();
        }
    }
    cout << ans;
}

Compilation message

roz.cpp: In function 'void build(char, char)':
roz.cpp:10:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   10 |     while (i < p[a].size() && j < p[b].size())
      |                  ^
roz.cpp:10:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     while (i < p[a].size() && j < p[b].size())
      |            ~~^~~~~~~~~~~~~
roz.cpp:10:37: warning: array subscript has type 'char' [-Wchar-subscripts]
   10 |     while (i < p[a].size() && j < p[b].size())
      |                                     ^
roz.cpp:10:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     while (i < p[a].size() && j < p[b].size())
      |                               ~~^~~~~~~~~~~~~
roz.cpp:12:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   12 |         if (p[a][i] < p[b][j])
      |               ^
roz.cpp:12:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   12 |         if (p[a][i] < p[b][j])
      |                         ^
roz.cpp:23:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   23 |     while (i < p[a].size())
      |                  ^
roz.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while (i < p[a].size())
      |            ~~^~~~~~~~~~~~~
roz.cpp:28:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     while (j < p[b].size())
      |                  ^
roz.cpp:28:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     while (j < p[b].size())
      |            ~~^~~~~~~~~~~~~
roz.cpp: In function 'int main()':
roz.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for (int i = 0; i < s.size(); ++i)
      |                     ~~^~~~~~~~~~
roz.cpp:42:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |         p[s[i]].push_back(i);
      |               ^
roz.cpp:46:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   46 |         if (!p[a].size())
      |                ^
roz.cpp:52:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   52 |             if (a == b || !p[b].size())
      |                              ^
roz.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for (int i = 1; i <= v.size(); ++i)
      |                             ~~^~~~~~~~~~~
roz.cpp:63:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for (int i = 1; i <= v.size(); ++i)
      |                             ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Incorrect 1 ms 336 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 484 KB Output is correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 1104 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 501 ms 10988 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 541 ms 10988 KB Output is correct
2 Correct 412 ms 9876 KB Output is correct
3 Correct 123 ms 7912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 530 ms 10904 KB Output is correct
2 Correct 53 ms 14292 KB Output is correct
3 Incorrect 94 ms 9192 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 517 ms 10772 KB Output is correct
2 Correct 34 ms 14420 KB Output is correct
3 Correct 162 ms 9720 KB Output is correct