Submission #1002298

# Submission time Handle Problem Language Result Execution time Memory
1002298 2024-06-19T12:09:39 Z votranngocvy Difference (POI11_roz) C++14
100 / 100
62 ms 5464 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define fod(i, a, b) for(int i = a; i >= b; i--)
#define name "DIFFER"
#define getbit(i,j) ((i>>j)&1)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define f first
#define s second
const int N = 1e6 + 5;
int n ;
int a[N] , d[N] , xh[N];
int ans = 0;

int main()
{
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    fo(i , 1 , n)
    {
      char x ; cin >> x;
      a[i] = x - 'a' + 1;
      xh[a[i] ] = 1;
    }
    fo(i , 1 ,26)
    {
        if(xh[i] == 1)
        {
            bool ok = 0;
            fo(j , 1 , 26) d[j] = 0;
            fo(j , 1 , n)
            {
                if(a[j] == i)
                {
                    ok = true;
                    fo(x , 1 , 26) d[x]--;
                }
                else if(d[a[j]] < 0)
                {
                    ok = false;
                    d[a[j]] = 0;
                }
                d[a[j]] ++;
                if(ok)
                {
                    ans = max(ans , d[a[j]]);
                }
                else ans = max(ans , d[a[j]] - 1);
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory 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
# 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 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 856 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 5464 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 43 ms 4416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 5208 KB Output is correct
2 Correct 43 ms 4188 KB Output is correct
3 Correct 32 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 5344 KB Output is correct
2 Correct 32 ms 5212 KB Output is correct
3 Correct 33 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 5340 KB Output is correct
2 Correct 29 ms 5208 KB Output is correct
3 Correct 37 ms 5208 KB Output is correct