Submission #571550

# Submission time Handle Problem Language Result Execution time Memory
571550 2022-06-02T10:54:49 Z vbee Election (BOI18_election) C++14
0 / 100
3 ms 340 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>
#define fi first
#define se second
#define TASK ""
#define ll long long
#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define pb push_back
#define MASK(i) (1 << (i))
#define BIT(x, i) ((x >> (i)) & 1)
 
using namespace std;

const int oo = 1e9 + 7;
const ll loo = (ll)1e18 + 7; 
const int N = 2e3 + 7;
int n, q;
string s;
bool mark[N];
int solve(int l, int r){
	memset(mark, false, sizeof mark);
	int sum = 0, savesum = 0, ret = 0;
	for (int i = l; i <= r; i++){
		if (s[i] == 'C') sum++;
		else sum--;
		savesum = min(savesum, sum);
	}
	int savesum2 = 0;
	sum = 0;
	for (int i = r; i >= l; i--){
		if (s[i] == 'C') sum++;
		else sum--;
		savesum2 = min(savesum2, sum);
	}
	return max(-savesum2, -savesum);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	//freopen(TASK".inp", "r", stdin);
	//freopen(TASK".out", "w", stdout);
	cin >> n >> s;
	s = " " + s;
	cin >> q;
	while (q--){
		int l, r; cin >> l >> r;
		cout << max(0, solve(l, r)) << "\n";
	}
	return 0;
}

Compilation message

election.cpp: In function 'int solve(int, int)':
election.cpp:28:28: warning: unused variable 'ret' [-Wunused-variable]
   28 |  int sum = 0, savesum = 0, ret = 0;
      |                            ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -