답안 #1012608

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012608 2024-07-02T11:41:58 Z HishamAlshehri Difference (POI11_roz) C++17
100 / 100
536 ms 25944 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, pre[maxn];
string s;
vector<int>v, idx[200];
 
void build(char a, char b)
{
    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++)
    {
        if (!idx[a].size())
            continue;
        for (char b = 'a' ; b <= 'z'; b++)
        {
            if (a == b || !idx[b].size())
                continue;
            build(a, b);
            for (int i = 1; i <= v.size(); i++)
                pre[i] = pre[i - 1] + v[i - 1];

            int mn = INT_MAX;
            int temp = pre[0];
            for (int i = 1; i <= v.size(); i++)
            {
                if (v[i - 1] == -1)
                    mn = min(temp, mn);
                temp = min(temp, pre[i]);
                mx = max(mx, pre[i] - mn);
                // cout << pre[i] << " ";
            }
            // cout << "\n";
            v.clear();
        }
    }
    cout << mx;
}

Compilation message

roz.cpp: In function 'void build(char, char)':
roz.cpp:35:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   35 |     while (i < idx[a].size() && j < idx[b].size())
      |                    ^
roz.cpp:35: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]
   35 |     while (i < idx[a].size() && j < idx[b].size())
      |            ~~^~~~~~~~~~~~~~~
roz.cpp:35:41: warning: array subscript has type 'char' [-Wchar-subscripts]
   35 |     while (i < idx[a].size() && j < idx[b].size())
      |                                         ^
roz.cpp:35: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]
   35 |     while (i < idx[a].size() && j < idx[b].size())
      |                                 ~~^~~~~~~~~~~~~~~
roz.cpp:37:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |         if (idx[a][i] < idx[b][j])
      |                 ^
roz.cpp:37:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |         if (idx[a][i] < idx[b][j])
      |                             ^
roz.cpp:48:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   48 |     while (i < idx[a].size())
      |                    ^
roz.cpp:48: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]
   48 |     while (i < idx[a].size())
      |            ~~^~~~~~~~~~~~~~~
roz.cpp:53:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   53 |     while (j < idx[b].size())
      |                    ^
roz.cpp:53: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]
   53 |     while (j < idx[b].size())
      |            ~~^~~~~~~~~~~~~~~
roz.cpp: In function 'int main()':
roz.cpp:65: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]
   65 |     for (int i = 0; i < s.size(); i++)
      |                     ~~^~~~~~~~~~
roz.cpp:67:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   67 |         idx[s[i]].push_back(i);
      |                 ^
roz.cpp:72:18: warning: array subscript has type 'char' [-Wchar-subscripts]
   72 |         if (!idx[a].size())
      |                  ^
roz.cpp:76:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   76 |             if (a == b || !idx[b].size())
      |                                ^
roz.cpp:79: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]
   79 |             for (int i = 1; i <= v.size(); i++)
      |                             ~~^~~~~~~~~~~
roz.cpp:84: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]
   84 |             for (int i = 1; i <= v.size(); i++)
      |                             ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 1628 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 536 ms 17004 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 271 ms 13040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 528 ms 17000 KB Output is correct
2 Correct 389 ms 15608 KB Output is correct
3 Correct 64 ms 12320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 508 ms 16372 KB Output is correct
2 Correct 61 ms 20684 KB Output is correct
3 Correct 54 ms 14228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 520 ms 16884 KB Output is correct
2 Correct 41 ms 25944 KB Output is correct
3 Correct 78 ms 13864 KB Output is correct