Submission #1103949

# Submission time Handle Problem Language Result Execution time Memory
1103949 2024-10-22T11:11:55 Z HiepVu217 Difference (POI11_roz) C++17
100 / 100
709 ms 14284 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 = 1e9, z = f[0];
            for (int i = 1; i <= v.size(); ++i)
            {
                if (v[i - 1] == -1)
                {
                     m = min (z, m);
                }
                z = min (z, 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:62:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |             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 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# 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
# Verdict Execution time Memory Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 1104 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 6 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 673 ms 10388 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 341 ms 9016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 696 ms 10120 KB Output is correct
2 Correct 511 ms 8940 KB Output is correct
3 Correct 117 ms 7912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 709 ms 9964 KB Output is correct
2 Correct 68 ms 14284 KB Output is correct
3 Correct 95 ms 8948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 684 ms 10012 KB Output is correct
2 Correct 40 ms 13660 KB Output is correct
3 Correct 141 ms 8680 KB Output is correct