Submission #515594

# Submission time Handle Problem Language Result Execution time Memory
515594 2022-01-19T10:15:07 Z myvaluska Election (BOI18_election) C++14
28 / 100
3000 ms 1376 KB
// 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
1 Correct 11 ms 208 KB Output is correct
2 Correct 12 ms 336 KB Output is correct
3 Correct 11 ms 308 KB Output is correct
4 Correct 12 ms 336 KB Output is correct
5 Correct 8 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 12 ms 336 KB Output is correct
3 Correct 11 ms 308 KB Output is correct
4 Correct 12 ms 336 KB Output is correct
5 Correct 8 ms 336 KB Output is correct
6 Execution timed out 3048 ms 1376 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 208 KB Output is correct
2 Correct 12 ms 336 KB Output is correct
3 Correct 11 ms 308 KB Output is correct
4 Correct 12 ms 336 KB Output is correct
5 Correct 8 ms 336 KB Output is correct
6 Execution timed out 3048 ms 1376 KB Time limit exceeded
7 Halted 0 ms 0 KB -