답안 #565643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
565643 2022-05-21T08:03:56 Z Rifal Election (BOI18_election) C++14
28 / 100
3000 ms 752 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 ss;
    cin >> n >> ss >> q;
    while(q--)
    {
        int l, r;
        cin >> l >> r;
        long long sum = 0;
        string s = ss;
        long long tt = 0, cc = 0;
        for(int i = l-1; i < r; i++)
        {
            if(s[i] == 'T')
            {
                if(cc > 0)
                {
                    cc--;
                }
                else
                {
                    s[i] = ' ';
                    sum++;
                }
            }
            else if(s[i] != ' ')
            {
                cc++;
            }
        }
        tt = 0, cc = 0;
        for(int i = r-1; i >= l-1; i--)
        {
            if(s[i] == 'T')
            {
                if(cc > 0)
                {
                    cc--;
                }
                else
                {
                    s[i] = ' ';
                    sum++;
                }
            }
            else if(s[i] != ' ')
            {
                cc++;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:23:19: warning: variable 'tt' set but not used [-Wunused-but-set-variable]
   23 |         long long tt = 0, cc = 0;
      |                   ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 212 KB Output is correct
2 Correct 10 ms 212 KB Output is correct
3 Correct 9 ms 212 KB Output is correct
4 Correct 9 ms 212 KB Output is correct
5 Correct 8 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 212 KB Output is correct
2 Correct 10 ms 212 KB Output is correct
3 Correct 9 ms 212 KB Output is correct
4 Correct 9 ms 212 KB Output is correct
5 Correct 8 ms 308 KB Output is correct
6 Execution timed out 3056 ms 752 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 212 KB Output is correct
2 Correct 10 ms 212 KB Output is correct
3 Correct 9 ms 212 KB Output is correct
4 Correct 9 ms 212 KB Output is correct
5 Correct 8 ms 308 KB Output is correct
6 Execution timed out 3056 ms 752 KB Time limit exceeded
7 Halted 0 ms 0 KB -