Submission #1098087

# Submission time Handle Problem Language Result Execution time Memory
1098087 2024-10-09T04:03:58 Z Alihan_8 Election (BOI18_election) C++17
28 / 100
3000 ms 1600 KB
#include <bits/stdc++.h>

using namespace std;

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n; cin >> n;
	
	vector <int> a(n + 1);
	
	for ( int i = 1; i <= n; i++ ){
		char x; cin >> x;
		
		a[i] = (x == 'C' ? 1 : -1);
	}
	
	int q; cin >> q;
	
	while ( q-- ){
		int l, r; cin >> l >> r;
		
		vector <int> er(n + 1);
		
		int cnt = 0;
		
		for ( int i = l; i <= r; i++ ){
			cnt += a[i];
			
			if ( cnt < 0 ){
				er[i] = 1, cnt = 0;
			}
		}
		
		cnt = 0;
		
		for ( int i = r; i >= l; i-- ){
			if ( er[i] ) continue;
			
			if ( a[i] == -1 ){
				if ( cnt == 0 ) er[i] = 1;
				else cnt -= 1;
			} else{
				cnt += 1;
			}
		}
		
		cout << accumulate(er.begin(), er.end(), 0) << '\n';
	}
	
	cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Execution timed out 3085 ms 1600 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 5 ms 348 KB Output is correct
6 Execution timed out 3085 ms 1600 KB Time limit exceeded
7 Halted 0 ms 0 KB -