답안 #1018770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018770 2024-07-10T09:38:09 Z vjudge1 Izbori (COCI22_izbori) C++17
25 / 110
8 ms 1372 KB
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define inf ((int)1e9)
using namespace std;

void solve1(int n) {
	vector <int> arr(n);
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	auto compress = [&](vector <int> &a) {
		vector <pair<int, int> > v(a.size());
		for(int i = 0; i < n; i++) {
			v[i] = {a[i], i};
		}
		sort(v.begin(), v.end());
		for(int i = 0, ind = 0; i < n; i++) {
			if(i and v[i].first != v[i - 1].first) ind++;
			a[v[i].second] = ind;
		}
	};
	compress(arr);
	int ans = 0;
	for(int l = 0; l < n; l++) {
		vector <int> cnt(n);
		int mx = 0;
		for(int r = l; r < n; r++) {
			cnt[arr[r]]++;
			mx = max(mx, cnt[arr[r]]);
			if(mx > (r - l + 1) / 2) ans++;
		}
	}
	cout << ans << "\n";
}

void solve2(int n) {
	vector <int> arr(n+1), pre(n+1);
	for(int i = 1; i <= n; i++) {
		cin >> arr[i];
		if(arr[i] == 2) arr[i] = -1;
		pre[i] = arr[i] + pre[i-1];
	}
	int sub = 0;
	map <int, int> mp;
	for(int i = n; i > 0; i--) {
		mp[pre[i]]++;
		sub += mp[pre[i - 1]];
	}
	cout << n * (n + 1) / 2 - sub << "\n";
}

int32_t main(){
	fast
	int n;
	cin >> n;
	if(n <= 2000) solve1(n);
	else solve2(n);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4 ms 476 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 1372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 4 ms 476 KB Output is correct
10 Correct 4 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 4 ms 348 KB Output is correct
17 Correct 3 ms 348 KB Output is correct
18 Incorrect 8 ms 1372 KB Output isn't correct
19 Halted 0 ms 0 KB -