Submission #565632

# Submission time Handle Problem Language Result Execution time Memory
565632 2022-05-21T07:51:44 Z Rifal Election (BOI18_election) C++14
0 / 100
15 ms 212 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 32768
#define INF 100000000000000
//#define ll long long
//#define cin fin
//#define cout fout
using namespace std;
//ofstream fout("convention.out");
//ifstream fin("convention.in");
int main()
{
    int n, q;
    string s;
    cin >> n >> s >> q;
    while(q--)
    {
        int l, r;
        cin >> l >> r;
        long long ans = INF;
        long long sum = 0;
        int tt = 0, cc = 0;
        for(int i = l-1; i < r; i++)
        {
            if(s[i] == 'T')
            {
                if(cc > 0)
                    cc--;
                else
                    sum++;
            }
            else
            {
                cc++;
            }
        }
        ans = min(sum,ans);
        tt = 0, cc = 0, sum = 0;
        for(int i = r-1; i >= l-1; i--)
        {
           if(s[i] == 'T')
            {
                if(cc > 0)
                    cc--;
                else
                    sum++;
            }
            else
            {
                cc++;
            }
        }

        cout << max(ans,sum) << endl;
    }
    return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:23:13: warning: variable 'tt' set but not used [-Wunused-but-set-variable]
   23 |         int tt = 0, cc = 0;
      |             ^~
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -