This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// election.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
while (q--)
{
int l;
cin >> l;
int r;
cin >> r;
l -= 1;
r -= 1;
vector<int>v(n,1);
int hlas = 0;
for (int i = l; i <= r; i++)
{
if (s[i] == 'C')
{
hlas += 1;
}
else if (s[i] == 'T')
{
hlas -= 1;
}
if (hlas < 0)
{
v[i] = 0;
hlas += 1;
}
}
int hlas2 = 0;
for (int i = r; i >= l; i--)
{
if (s[i] == 'C')
{
hlas2 += 1;
}
else if (s[i] == 'T'&&v[i]==1)
{
hlas2 -= 1;
}
if (hlas2 < 0)
{
v[i] = 0;
hlas2 += 1;
}
}
int vys = 0;
for (int i = l; i <= r; i++)
{
if (v[i] == 0)
{
vys += 1;
}
}
cout << vys << endl;
}
return 0;
///std::cout << "Hello World!\n";
}
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
// Tips for Getting Started:
// 1. Use the Solution Explorer window to add/manage files
// 2. Use the Team Explorer window to connect to source control
// 3. Use the Output window to see build output and other messages
// 4. Use the Error List window to view errors
// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |