이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ar array< int , 2>
#define MASK(i) (1 << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
const int MAX = 1e6 + 1000;
int n, k, x, y;
char c;
map< char , int > d[MAX];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> c;
if (c == 'C')
{
d[i]['C'] = d[i - 1]['C'] + 1;
d[i]['T'] = d[i - 1]['T'];
}
else
{
d[i]['T'] = d[i - 1]['T'] + 1;
d[i]['C'] = d[i - 1]['C'];
}
}
cin >> k;
for (int i = 1; i <= k; i++)
{
cin >> x >> y;
//cout << d[y]['C'] - d[x - 1]['C'] << '\n' ;
int ans = 0;
for (int j = x; j <= y; j++)
{
ans = max(ans, d[j]['T'] - d[x - 1]['T'] - d[j]['C'] + d[x - 1]['T']);
}
for (int j = y; j >= x; j--)
{
ans = max(ans, d[y]['T'] - d[j - 1]['T'] - d[y]['C'] + d[j - 1]['C']);
}
cout << ans << '\n' ;
}
}
/*
11
CCCTTTTTTCC
3
1 11
4 9
1 6
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |