답안 #82374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
82374 2018-10-30T10:21:13 Z faceless Election (BOI18_election) C++14
28 / 100
3000 ms 1872 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;

bool mark[maxn];

int main () {
	int n, q;
	string s;
	cin >> n >> s >> q;
	for (int i = 0; i < q; i++) {
		memset (mark, 0, sizeof mark);
		int l, r;
		cin >> l >> r;
		l --, r --;
		
		int cnt = 0, ans = 0;
		for (int j = l; j <= r; j++) {
			if (s[j] == 'T' and cnt == 0) {
				mark[j] = 1;
				ans ++;
			}
			else if (s[j] == 'T')
				cnt --;
			else
				cnt ++;
		}
		cnt = 0;
		for (int j = r; j >= l; j--) {
			if (mark[j])
				continue;
			if (s[j] == 'T' and cnt == 0) {
				mark[j] = 1;
				ans ++;
			}
			else if (s[j] == 'T')
				cnt --;
			else
				cnt ++;
		}
		cout << ans << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 376 KB Output is correct
2 Correct 26 ms 500 KB Output is correct
3 Correct 24 ms 648 KB Output is correct
4 Correct 26 ms 796 KB Output is correct
5 Correct 22 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 376 KB Output is correct
2 Correct 26 ms 500 KB Output is correct
3 Correct 24 ms 648 KB Output is correct
4 Correct 26 ms 796 KB Output is correct
5 Correct 22 ms 816 KB Output is correct
6 Execution timed out 3042 ms 1872 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 376 KB Output is correct
2 Correct 26 ms 500 KB Output is correct
3 Correct 24 ms 648 KB Output is correct
4 Correct 26 ms 796 KB Output is correct
5 Correct 22 ms 816 KB Output is correct
6 Execution timed out 3042 ms 1872 KB Time limit exceeded
7 Halted 0 ms 0 KB -