Submission #1012492

# Submission time Handle Problem Language Result Execution time Memory
1012492 2024-07-02T08:44:51 Z HishamAlshehri Difference (POI11_roz) C++17
90 / 100
519 ms 17620 KB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int long long
#define mod 1000000007
#define base 7001
#define base2 757
// #define pi acos(-1)
#define double long double
// #define ordered_set tree<pair<int, int>, null_type, less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
// #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

#pragma GCC optimize("O3,Ofast,unroll-loops")
#pragma GCC target("avx2,sse3,sse4,avx")

constexpr int maxn = 1000001;
const int N = 1 << (int)(ceil(log2(maxn)));

struct max_sub_sum
{
    int mx, flag;
};

int n;
string s;
vector<int>v, idx[200];

void build(char a, char b)
{
    if (!idx[a].size() || !idx[b].size())
        return;
    int i = 0, j = 0;
    while (i < idx[a].size() && j < idx[b].size())
    {
        if (idx[a][i] < idx[b][j])
        {
            v.push_back(1);
            i++;
        }
        else
        {
            v.push_back(-1);
            j++;
        }
    }
    while (i < idx[a].size())
    {
        v.push_back(1);
        i++;
    }
    while (j < idx[b].size())
    {
        v.push_back(-1);
            j++;
    }
    return;
}

signed main()
{
    cin.tie(0) -> sync_with_stdio(0);
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++)
    {
        idx[s[i]].push_back(i);
    }
    int mx = 0;
    for (char a = 'a'; a <= 'z'; a++)
    {
        for (char b = 'a' ; b <= 'z'; b++)
        {
            if(a == b) continue;
            build(a, b);
            max_sub_sum ans;
            ans.mx = 0;
            ans.flag = 0;
            int sum = 0;
            for (int i = 0; i < v.size(); i++)
            {
                if (v[i] + sum > -1)
                {
                    sum += v[i];
                    if (v[i] < 0)
                        ans.flag = 1;
                    if (ans.flag)
                        ans.mx = max(ans.mx, sum);
                }
                else
                    ans.flag = 0;
                //cout << ans.mx << " ";
            }
            mx = max(ans.mx, mx);
            v.clear();
        }
    }
    cout << mx;
}

Compilation message

roz.cpp: In function 'void build(char, char)':
roz.cpp:34:14: warning: array subscript has type 'char' [-Wchar-subscripts]
   34 |     if (!idx[a].size() || !idx[b].size())
      |              ^
roz.cpp:34:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   34 |     if (!idx[a].size() || !idx[b].size())
      |                                ^
roz.cpp:37:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |     while (i < idx[a].size() && j < idx[b].size())
      |                    ^
roz.cpp:37:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (i < idx[a].size() && j < idx[b].size())
      |            ~~^~~~~~~~~~~~~~~
roz.cpp:37:41: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |     while (i < idx[a].size() && j < idx[b].size())
      |                                         ^
roz.cpp:37:35: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while (i < idx[a].size() && j < idx[b].size())
      |                                 ~~^~~~~~~~~~~~~~~
roz.cpp:39:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |         if (idx[a][i] < idx[b][j])
      |                 ^
roz.cpp:39:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |         if (idx[a][i] < idx[b][j])
      |                             ^
roz.cpp:50:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   50 |     while (i < idx[a].size())
      |                    ^
roz.cpp:50:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     while (i < idx[a].size())
      |            ~~^~~~~~~~~~~~~~~
roz.cpp:55:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   55 |     while (j < idx[b].size())
      |                    ^
roz.cpp:55:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     while (j < idx[b].size())
      |            ~~^~~~~~~~~~~~~~~
roz.cpp: In function 'int main()':
roz.cpp:67:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
roz.cpp:69:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   69 |         idx[s[i]].push_back(i);
      |                 ^
roz.cpp:82:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             for (int i = 0; i < v.size(); i++)
      |                             ~~^~~~~~~~~~
# Verdict Execution time Memory 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
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 52 ms 1368 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 14072 KB Output is correct
2 Incorrect 1 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 490 ms 14068 KB Output is correct
2 Correct 379 ms 12612 KB Output is correct
3 Correct 56 ms 10276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 13560 KB Output is correct
2 Correct 56 ms 17620 KB Output is correct
3 Correct 39 ms 11412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 484 ms 14068 KB Output is correct
2 Correct 34 ms 17508 KB Output is correct
3 Correct 59 ms 11432 KB Output is correct