Submission #715608

# Submission time Handle Problem Language Result Execution time Memory
715608 2023-03-27T09:52:11 Z oblantis Election (BOI18_election) C++17
28 / 100
3000 ms 996 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 1e9;
const int mod = 1e9 + 7;
const int maxn = 5e5 + 12;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
void solve() {
	int n, q;
	string s;
	cin >> n >> s >> q;
	while(q--) {
		int l, r;
		cin >> l >> r;
		int t = 0, ans = 0;
		for(int i = l - 1; i < r; i++) {
			if(s[i] == 'T'){
				if(t == 0)s[i] = '!', ans++;
				else t--;
			}
			else t++;
		}
		t = 0;
		for(int i = r - 1; i >= l - 1; i--) {
			if(s[i] == 'T'){
				if(t == 0)ans++;
				else t--;
			}
			else if(s[i] == 'C')t++;
			else s[i] = 'T';
		}
		cout << ans << '\n';
	}
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int tcs = 1;
	//cin >> tcs;
	for(int i = 1; i <= tcs; i++) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 10 ms 336 KB Output is correct
3 Correct 10 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 4 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 10 ms 336 KB Output is correct
3 Correct 10 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 4 ms 336 KB Output is correct
6 Execution timed out 3066 ms 996 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 340 KB Output is correct
2 Correct 10 ms 336 KB Output is correct
3 Correct 10 ms 340 KB Output is correct
4 Correct 7 ms 340 KB Output is correct
5 Correct 4 ms 336 KB Output is correct
6 Execution timed out 3066 ms 996 KB Time limit exceeded
7 Halted 0 ms 0 KB -