이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 100'010, K = 19;
int sp[N][K];
int getor(int l, int r)
{
// cerr << l << ' ' << r << endl;
int b = 31 - __builtin_clz(r - l);
// cerr << b << endl;
return (sp[l][b] | sp[r - (1 << b)][b]);
}
bool smaller(vector<int> a, vector<int> b)
{
return a[0] * b[1] < b[0] * a[1];
}
int main()
{
int n;
string s;
cin >> n >> s;
int mask[n];
for(int i = 0; i < n; i ++)
mask[i] = 1 << (s[i] - 'a');
for(int i = n - 1; i >= 0; i --)
{
sp[i][0] = mask[i];
for(int l = 1; i + (1 << l) <= n; l++)
sp[i][l] = (sp[i][l - 1] | sp[i + (1 << (l - 1))][l - 1]);
}
vector<int> ans;
// set sz s e
ans = {1, 1, 1, 1};
for(int i = 0; i < n; i ++)
{
// cerr << i << endl;
int cur = 0;
while(cur < getor(i, n))
{
int l = i, r = n;
while(r - l > 1)
{
int m = (l + r) / 2;
if(getor(i, m) <= cur)
l = m;
else
r = m;
}
if(smaller({__builtin_popcount(cur), l - i, i + 1, l}, ans))
ans = {__builtin_popcount(cur), l - i, i + 1, l};
cur = getor(i, r);
}
cur = getor(i, n);
// cerr << "out : " << __builtin_popcount(cur) << ' ' << i + 1 << ' ' << n << endl;
if(smaller({__builtin_popcount(cur), n - i, i + 1, n}, ans))
ans = {__builtin_popcount(cur), n - i, i + 1, n};
}
cout << ans[2] << ' ' << ans[3] << endl;
return 0;
}
# | 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... |