답안 #581370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581370 2022-06-22T14:32:18 Z willi19 Election (BOI18_election) C++17
28 / 100
3000 ms 1108 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

//1 => l-1~r 
ll n,q;
string s;


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	cin>>s;
	cin>>q;
	
	while(q--)
	{
		ll l,r;
		cin>>l>>r;
		vector<char> lf;
		ll cnt = 0,ans = 0;
		for(ll i=l-1;i<r;i++)
		{
			if(s[i]=='T'&&cnt==0)
				ans++;
			else
			{
				if(s[i]=='T')
					cnt--;
				else
					cnt++;
				lf.push_back(s[i]);
			}
		}
		reverse(lf.begin(),lf.end());
		cnt = 0;
		for(char c:lf)
		{
			if(c=='T'&&cnt==0)
				ans++;
			else
			{
				if(c=='T')
					cnt--;
				else
					cnt++;
			}
		}
		cout<<ans<<"\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 212 KB Output is correct
2 Correct 11 ms 328 KB Output is correct
3 Correct 10 ms 352 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 212 KB Output is correct
2 Correct 11 ms 328 KB Output is correct
3 Correct 10 ms 352 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Execution timed out 3074 ms 1108 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 212 KB Output is correct
2 Correct 11 ms 328 KB Output is correct
3 Correct 10 ms 352 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 6 ms 340 KB Output is correct
6 Execution timed out 3074 ms 1108 KB Time limit exceeded
7 Halted 0 ms 0 KB -