이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |