Submission #574506

# Submission time Handle Problem Language Result Execution time Memory
574506 2022-06-08T16:00:54 Z FatihSolak Election (BOI18_election) C++17
28 / 100
3000 ms 1112 KB
#include <bits/stdc++.h>
#define N 500005
using namespace std;
bool ok[N];
void solve(){
	int n,q;
	string s;
	cin >> n >> s >> q;
	s = "." + s;
	for(int i = 1;i<=q;i++){
		int l,r;
		cin >> l >> r;
		for(int j = l;j<=r;j++){
			ok[j] = 0;
		}
		int mini = 0;
		int now = 0;
		for(int j = l;j<=r;j++){
			if(s[j] == 'C')now++;
			else now--;
			if(now < mini){
				ok[j] = 1;
				mini = now;
			}
		}
		mini = 0;
		now = 0;
		for(int j = r;j>=l;j--){
			if(ok[j])continue;
			if(s[j] == 'C')now++;
			else now--;
			if(now < mini){
				ok[j] = 1;
				mini = now;
			}
		}
		int ans = 0;
		for(int j = l;j<=r;j++){
			ans += ok[j];
		}
		cout << ans << "\n";
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	#ifdef Local
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	#ifdef Local
		cout << endl << fixed << setprecision(2) << 1000.0 * clock() / CLOCKS_PER_SEC << " milliseconds.";
	#endif
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 340 KB Output is correct
2 Correct 9 ms 356 KB Output is correct
3 Correct 10 ms 360 KB Output is correct
4 Correct 10 ms 352 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 340 KB Output is correct
2 Correct 9 ms 356 KB Output is correct
3 Correct 10 ms 360 KB Output is correct
4 Correct 10 ms 352 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Execution timed out 3030 ms 1112 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 340 KB Output is correct
2 Correct 9 ms 356 KB Output is correct
3 Correct 10 ms 360 KB Output is correct
4 Correct 10 ms 352 KB Output is correct
5 Correct 5 ms 340 KB Output is correct
6 Execution timed out 3030 ms 1112 KB Time limit exceeded
7 Halted 0 ms 0 KB -