답안 #709706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
709706 2023-03-14T08:17:01 Z WonderfulWhale Election (BOI18_election) C++17
28 / 100
3000 ms 3596 KB
#include<bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

int f(vector<int> v) {
	int ans = 0;
	int s = 0;
	for(int i=0;i<sz(v);i++) {
		s += v[i];
		if(s < 0) {
			v[i] = s = 0;
			ans++;
		}
	}
	s = 0;
	for(int i=sz(v)-1;i>=0;i--) {
		s += v[i];
		if(s < 0) {
			v[i] = s = 0;
			ans++;
		}
	}
	return ans;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		char c;
		cin >> c;
		if(c=='C') v[i] = 1;
		else v[i] = -1;
	}
	int q;
	cin >> q;
	while(q--) {
		int l, r;
		cin >> l >> r;
		vector<int> Q;
		for(int i=l-1;i<r;i++) {
			Q.pb(v[i]);
		}
		cout << f(Q) << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 6 ms 436 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 6 ms 436 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
6 Execution timed out 3072 ms 3596 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 KB Output is correct
2 Correct 6 ms 340 KB Output is correct
3 Correct 6 ms 436 KB Output is correct
4 Correct 8 ms 340 KB Output is correct
5 Correct 7 ms 340 KB Output is correct
6 Execution timed out 3072 ms 3596 KB Time limit exceeded
7 Halted 0 ms 0 KB -