Submission #770176

# Submission time Handle Problem Language Result Execution time Memory
770176 2023-06-30T22:40:51 Z allllekssssa Election (BOI18_election) C++14
28 / 100
3000 ms 1052 KB
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

const int maxN = 100000;
string s;
int n, q;
int d[maxN];

int main() {

	cin >> n;
	cin >> s;
	cin >> q;

	while(q--) {
		int l, r;
		scanf("%d%d", &l, &r);

		int cur = 0;
		int mm = 0;
		for (int i = l; i <= r; i++) {
			if (s[i - 1] == 'T') ++cur; else cur--;
			mm = max(mm, cur);
			d[i] = mm;
		}

		cur = 0;
		mm = 0;
		for (int i = r; i>=l; i--) {
			d[i]+=mm;
			if (s[i - 1] == 'T') ++cur; else cur--;
			mm = max(mm, cur);
		}

		int mx = 0;
		for (int i = l; i<=r; i++) {
			mx = max(mx, d[i]);
		}
		printf("%d\n", mx);
	}
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d%d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 5 ms 320 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 5 ms 320 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
6 Execution timed out 3070 ms 1052 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 5 ms 320 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 4 ms 212 KB Output is correct
6 Execution timed out 3070 ms 1052 KB Time limit exceeded
7 Halted 0 ms 0 KB -