Submission #571493

# Submission time Handle Problem Language Result Execution time Memory
571493 2022-06-02T10:10:57 Z Doanxem99 Election (BOI18_election) C++14
0 / 100
53 ms 47444 KB
#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
1 Incorrect 53 ms 47444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 47444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 47444 KB Output isn't correct
2 Halted 0 ms 0 KB -